1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | 'use strict';
|
14 |
|
15 | var archiver = require('archiver');
|
16 | var chalk = require('chalk');
|
17 | var extensionDescriptor = require('./helpers/extensionDescriptor');
|
18 | var fs = require('fs');
|
19 | var getPaths = require('./helpers/getPackagePaths.js');
|
20 | var path = require('path');
|
21 |
|
22 | var fileExists = function(filepath) {
|
23 |
|
24 | var fileDirectory = path.dirname(filepath);
|
25 | var folderFiles = fs.readdirSync(fileDirectory);
|
26 | var fileBaseName = path.basename(filepath);
|
27 |
|
28 | return folderFiles.indexOf(fileBaseName) !== -1;
|
29 | };
|
30 |
|
31 | module.exports = function() {
|
32 | var output = fs.createWriteStream(
|
33 | 'package-' + extensionDescriptor.name + '-' + extensionDescriptor.version + '.zip'
|
34 | );
|
35 | var zipArchive = archiver('zip');
|
36 |
|
37 | zipArchive.pipe(output);
|
38 |
|
39 | var filepaths = getPaths(extensionDescriptor);
|
40 |
|
41 | filepaths.forEach(function(filepath) {
|
42 | if (!fileExists(filepath)) {
|
43 | var error = 'Cannot find file: ' + filepath;
|
44 | console.error(chalk.red(error));
|
45 | process.exit(1);
|
46 | }
|
47 | zipArchive.file(filepath);
|
48 | });
|
49 |
|
50 | zipArchive.finalize();
|
51 | };
|