forked from snovakovic/js-flock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish.js
41 lines (34 loc) · 1.06 KB
/
publish.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
/* eslint-disable no-console */
const { exec } = require('child_process');
const Fs = require('fs');
const Path = require('path');
const execute = function(command) {
return new Promise((resolve, reject) => {
exec(command, (err, stdout) => {
if (err) {
return reject(err);
}
console.info(`${stdout}`);
return resolve();
});
});
};
execute('npm run build')
.then(() => {
const packagePath = Path.resolve(__dirname, 'dist/package.json');
const file = Fs.readFileSync(packagePath);
const json = JSON.parse(file);
delete json.private; // Used to prevent accidental publish with npm publish
delete json['//'];
console.info(`\n\nSTART PUBLISHING version: ${json.version}\n\n`);
Fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8');
process.chdir(Path.resolve(__dirname, 'dist'));
return execute('npm publish');
})
.then(() => {
process.chdir(Path.resolve(__dirname));
return execute('npm run test:integration');
})
.then(() => {
console.info('--- PUBLISH COMPLETED ----');
});