UNPKG

1.91 kBJavaScriptView Raw
1/***************************************************************************************
2 * (c) 2017 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 ****************************************************************************************/
12
13'use strict';
14
15var archiver = require('archiver');
16var chalk = require('chalk');
17var extensionDescriptor = require('./helpers/extensionDescriptor');
18var fs = require('fs');
19var getPaths = require('./helpers/getPackagePaths.js');
20var path = require('path');
21
22var fileExists = function(filepath) {
23 // We need to check if a file exists in a case sensitive way that is not OS dependent.
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
31module.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};