-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
48 lines (42 loc) · 1.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
const archiver = require('archiver-promise');
const packlist = require('npm-packlist');
const path = require('path');
const sanitize = require('sanitize-filename');
const packagejson = require(path.join(process.cwd(), "/package.json"));
function zipFiles(files, filename, source, destination, info, verbose) {
const target = path.join(destination, filename);
if (info) console.log(`Archive: ${target}`);
let archive = archiver(target);
files.forEach(file => {
const filePath = path.join(source, file);
if (verbose) console.log(file);
archive.file(filePath, { name: file });
});
return archive.finalize();
}
function pack({ source, destination, info, verbose, name, includes, name_only }) {
source = source || './build';
if (name && name_only) {
name = `${name}.zip`;
} else {
name = name ? '.' + name : '';
name = `${sanitize(packagejson.name)}_${sanitize(packagejson.version)}${name}.zip`;
}
return packlist({
path: source,
bundled: includes.split(',')
}).then(files => {
return zipFiles(
files,
name,
source,
destination,
info,
verbose
);
});
}
module.exports = {
pack
};