/
prepare.js
40 lines (34 loc) · 1.07 KB
/
prepare.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
const path = require('path');
const {move} = require('fs-extra');
const execa = require('execa');
module.exports = async ({tarballDir, pkgRoot}, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => {
const basePath = pkgRoot ? path.resolve(cwd, pkgRoot) : cwd;
logger.log('Write version %s to package.json in %s', version, basePath);
const versionResult = execa('npm', ['version', version, '--no-git-tag-version', '--allow-same-version'], {
cwd: basePath,
env,
});
versionResult.stdout.pipe(
stdout,
{end: false}
);
versionResult.stderr.pipe(
stderr,
{end: false}
);
await versionResult;
if (tarballDir) {
logger.log('Creating npm package version %s', version);
const packResult = execa('npm', ['pack', basePath], {cwd, env});
packResult.stdout.pipe(
stdout,
{end: false}
);
packResult.stderr.pipe(
stderr,
{end: false}
);
const tarball = (await packResult).stdout.split('\n').pop();
await move(path.resolve(cwd, tarball), path.resolve(cwd, tarballDir.trim(), tarball));
}
};