forked from bbyars/mountebank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist.js
50 lines (42 loc) · 1.76 KB
/
dist.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
49
50
'use strict';
const run = require('./run').run,
fs = require('fs-extra');
async function distPackage (source, destination, packageTransformer) {
fs.ensureDirSync(`dist/${destination}`);
const pkg = JSON.parse(fs.readFileSync(`${source}/package.json`));
pkg.files.forEach(file => {
fs.copySync(`${source}/${file}`, `dist/${destination}/${file}`);
});
packageTransformer(pkg);
fs.writeFileSync(`dist/${destination}/package.json`, JSON.stringify(pkg, null, 2));
await run('npm', ['install', '--production'], { cwd: `dist/${destination}` });
await run('npm', ['pack'], { cwd: `dist/${destination}` });
}
async function packageMountebank () {
await distPackage('.', 'mountebank', pkg => {
delete pkg.devDependencies;
Object.keys(pkg.scripts).forEach(script => {
// We don't package most tasks and don't want users running them anyhow
if (['start', 'restart', 'stop'].indexOf(script) < 0) {
delete pkg.scripts[script];
}
});
fs.copySync('./Dockerfile', 'dist/mountebank/Dockerfile');
});
}
async function packageMbTest () {
await distPackage('mbTest', 'test', pkg => {
pkg.dependencies.mountebank = 'file:../mountebank';
const lockfile = JSON.parse(fs.readFileSync('dist/test/package-lock.json'));
lockfile.dependencies.mountebank.version = 'file:../mountebank';
fs.writeFileSync('dist/test/package-lock.json', JSON.stringify(lockfile, null, 2));
});
}
fs.removeSync('dist');
packageMountebank()
.then(() => packageMbTest())
.then(() => console.log('packages available in dist directory'))
.catch(error => {
console.error(error);
process.exit(1); // eslint-disable-line no-process-exit
});