-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-package.js
More file actions
78 lines (59 loc) · 2.18 KB
/
create-package.js
File metadata and controls
78 lines (59 loc) · 2.18 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const seven = require('node-7z');
const process = require('process');
const minimist = require('minimist');
const fs = require('fs');
const fse = require('fs-extra');
const rimraf = require("rimraf");
const exec = require('child_process').exec;
const args = minimist(process.argv.slice(2));
const FILES = ['check.js', 'LICENCE', 'package.json', 'README.md'];
const FOLDERS = ['babel', 'lib'];
const PACKAGE_NAME = args['name'] || 'package.tar';
const PACKAGE_DIR = args['dir-name'] || './package/';
const createTarball = (PACKAGE_DIR) => {
const myStream = seven.add(PACKAGE_NAME, PACKAGE_DIR);
myStream.on('error', (error) => {
console.error('The following errors have occurred archiving files: ', error);
});
myStream.on('end', () => {
install();
});
};
const install = () => {
exec(`npm install -g ${PACKAGE_NAME}`, {}, (error, stdout, stderr) => {
if (error) return console.error(`The following errors have occurred installing ${PACKAGE_NAME}`, error);
if (stderr) console.log(`The following errors have occurred installing ${PACKAGE_NAME}`, stderr);
console.log(stdout);
console.log('Installed!');
removeDistFolder(PACKAGE_DIR);
});
};
const removeDistFolder = (PACKAGE_DIR) => {
if (fs.existsSync(PACKAGE_DIR)) {
rimraf.sync(PACKAGE_DIR);
}
}
const setup = () => {
console.log('Begin setup.');
removeDistFolder(PACKAGE_DIR);
fs.mkdirSync(PACKAGE_DIR);
FILES.forEach(fileName => {
fs.copyFileSync(fileName, `${PACKAGE_DIR}${fileName}`);
});
const promises = [];
FOLDERS.forEach(folderName => {
promises.push(fse.copy(folderName, `${PACKAGE_DIR}${folderName}`));
});
console.log('Finished setup.');
Promise.all(promises).then(() => {
createTarball(PACKAGE_DIR);
});
};
module.exports = (() => {
exec('npm run prepublish', {}, (error, stdout, stderr) => {
if (error) return console.error('The following errors have occurred building coherent-preact: ', error);
if (stderr) console.log('The following errors have occurred building coherent-preact: ', stderr);
console.log(stdout);
setup();
});
})();