build-strap 3.0.0-dev.45 → 4.0.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -34
- package/ant.d.ts +19 -0
- package/ant.js +12 -37
- package/cert.d.ts +12 -0
- package/cert.js +89 -151
- package/clean.d.ts +4 -0
- package/clean.js +7 -16
- package/copy.d.ts +7 -0
- package/copy.js +49 -76
- package/cp.d.ts +17 -0
- package/cp.js +85 -170
- package/docker.container.d.ts +73 -0
- package/docker.container.js +219 -362
- package/docker.d.ts +68 -0
- package/docker.js +167 -347
- package/docker.network.d.ts +42 -0
- package/docker.network.js +69 -144
- package/docker.volume.d.ts +26 -0
- package/docker.volume.js +52 -126
- package/dockerCleanup.d.ts +38 -0
- package/dockerCleanup.js +66 -141
- package/dockerCompose.d.ts +154 -0
- package/dockerCompose.js +400 -727
- package/fs.d.ts +5 -0
- package/fs.js +38 -95
- package/git.d.ts +9 -0
- package/git.js +19 -30
- package/index.d.ts +20 -0
- package/index.js +20 -27
- package/maps.d.ts +33 -0
- package/maps.js +16 -87
- package/npm.d.ts +42 -0
- package/npm.js +104 -135
- package/package.json +23 -19
- package/pkg.d.ts +39 -0
- package/pkg.js +26 -74
- package/publish.d.ts +27 -0
- package/publish.js +52 -140
- package/run.d.ts +13 -0
- package/run.js +39 -85
- package/tgz.d.ts +13 -0
- package/tgz.js +61 -96
- package/version.d.ts +34 -0
- package/version.js +86 -127
- package/yarn.d.ts +44 -0
- package/yarn.js +156 -119
- package/ant.js.flow +0 -42
- package/artifactory.js +0 -617
- package/artifactory.js.flow +0 -616
- package/cert.conf +0 -20
- package/cert.js.flow +0 -152
- package/clean.js.flow +0 -19
- package/copy.js.flow +0 -79
- package/cp.js.flow +0 -172
- package/docker.container.js.flow +0 -389
- package/docker.js.flow +0 -367
- package/docker.network.js.flow +0 -159
- package/docker.volume.js.flow +0 -136
- package/dockerCleanup.js.flow +0 -151
- package/dockerCompose.js.flow +0 -765
- package/flow.js +0 -21
- package/flow.js.flow +0 -20
- package/fs.js.flow +0 -96
- package/git.js.flow +0 -34
- package/hg.js +0 -35
- package/hg.js.flow +0 -34
- package/index.js.flow +0 -26
- package/inline-resources.js +0 -158
- package/inline-resources.js.flow +0 -157
- package/maps.js.flow +0 -111
- package/npm.js.flow +0 -144
- package/pkg.js.flow +0 -80
- package/publish.js.flow +0 -144
- package/run.js.flow +0 -89
- package/src/ant.js +0 -42
- package/src/artifactory.js +0 -616
- package/src/cert.conf +0 -20
- package/src/cert.js +0 -152
- package/src/clean.js +0 -19
- package/src/copy.js +0 -79
- package/src/cp.js +0 -172
- package/src/docker.container.js +0 -389
- package/src/docker.js +0 -367
- package/src/docker.network.js +0 -159
- package/src/docker.volume.js +0 -136
- package/src/dockerCleanup.js +0 -151
- package/src/dockerCompose.js +0 -765
- package/src/flow.js +0 -20
- package/src/fs.js +0 -96
- package/src/git.js +0 -34
- package/src/hg.js +0 -34
- package/src/index.js +0 -26
- package/src/inline-resources.js +0 -157
- package/src/maps.js +0 -111
- package/src/npm.js +0 -144
- package/src/pkg.js +0 -80
- package/src/publish.js +0 -144
- package/src/run.js +0 -89
- package/src/test.js +0 -55
- package/src/tgz.js +0 -101
- package/src/version.js +0 -141
- package/src/yarn.js +0 -123
- package/test.js +0 -56
- package/test.js.flow +0 -55
- package/tgz.js.flow +0 -101
- package/version.js.flow +0 -141
- package/yarn.js.flow +0 -123
package/test.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.karmaTest = karmaTest;
|
|
2
|
-
var _run = require("./run");
|
|
3
|
-
var _cp = require("./cp");
|
|
4
|
-
|
|
5
|
-
async function karmaTest(
|
|
6
|
-
karma,
|
|
7
|
-
karmaConfig,
|
|
8
|
-
preTestFn,
|
|
9
|
-
watch = process.argv.includes('--watch'))
|
|
10
|
-
{
|
|
11
|
-
// Lazy require karma
|
|
12
|
-
const { Server, runner, stopper, config } = karma;
|
|
13
|
-
|
|
14
|
-
const testConfig = config.parseConfig(karmaConfig, {
|
|
15
|
-
autoWatch: false,
|
|
16
|
-
singleRun: !watch });
|
|
17
|
-
|
|
18
|
-
const server = new Server(testConfig, (exitCode) => {
|
|
19
|
-
(0, _run.buildLog)(`Karma has exited with code ${exitCode}`);
|
|
20
|
-
});
|
|
21
|
-
(0, _cp.onKillSignal)(() => stopper.stop(testConfig));
|
|
22
|
-
|
|
23
|
-
let started = false;
|
|
24
|
-
async function doTest() {
|
|
25
|
-
if (!started) {
|
|
26
|
-
await Promise.all([
|
|
27
|
-
new Promise((resolve) => {
|
|
28
|
-
server.on('browsers_ready', resolve);
|
|
29
|
-
}),
|
|
30
|
-
server.start()]);
|
|
31
|
-
|
|
32
|
-
started = true;
|
|
33
|
-
}
|
|
34
|
-
if (watch) {
|
|
35
|
-
// await server.refreshFiles();
|
|
36
|
-
await new Promise((resolve, reject) => {
|
|
37
|
-
runner.run(testConfig, (exitCode) => {
|
|
38
|
-
(0, _run.buildLog)(`Karma run completed with exit code ${exitCode}`);
|
|
39
|
-
if (exitCode === 0 || watch) {
|
|
40
|
-
resolve(exitCode);
|
|
41
|
-
} else {
|
|
42
|
-
reject(exitCode);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (typeof preTestFn === 'function') {
|
|
50
|
-
// preTestFn is expected to callback and run doTest
|
|
51
|
-
await (0, _run.run)(preTestFn, doTest);
|
|
52
|
-
} else {
|
|
53
|
-
await doTest();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy90ZXN0LmpzIl0sIm5hbWVzIjpbImthcm1hVGVzdCIsImthcm1hIiwia2FybWFDb25maWciLCJwcmVUZXN0Rm4iLCJ3YX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AgIH1cbiAgICBpZiAod2F0Y2gpIHtcbiAgICAgIC8vIGF3YWl0IHNlcnZlci5yZWZyZXNoRmlsZXMoKTtcbiAgICAgIGF3YWl0IG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgICAgcnVubmVyLnJ1bih0ZXN0Q29uZmlnLCAoZXhpdENvZGUpID0+IHtcbiAgICAgICAgICBidWlsZExvZyhgS2FybWEgcnVuIGNvbXBsZXRlZCB3aXRoIGV4aXQgY29kZSAke2V4aXRDb2RlfWApO1xuICAgICAgICAgIGlmIChleGl0Q29kZSA9PT0gMCB8fCB3YXRjaCkge1xuICAgICAgICAgICAgcmVzb2x2ZShleGl0Q29kZSk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJlamVjdChleGl0Q29kZSk7XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgIH0pO1xuICAgIH1cbiAgfVxuXG4gIGlmICh0eXBlb2YgcHJlVGVzdEZuID09PSAnZnVuY3Rpb24nKSB7XG4gICAgLy8gcHJlVGVzdEZuIGlzIGV4cGVjdGVkIHRvIGNhbGxiYWNrIGFuZCBydW4gZG9UZXN0XG4gICAgYXdhaXQgcnVuKHByZVRlc3RGbiwgZG9UZXN0KTtcbiAgfSBlbHNlIHtcbiAgICBhd2FpdCBkb1Rlc3QoKTtcbiAgfVxufVxuIl19
|
package/test.js.flow
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { run, buildLog } from './run';
|
|
3
|
-
import { onKillSignal } from './cp';
|
|
4
|
-
|
|
5
|
-
export async function karmaTest(
|
|
6
|
-
karma: Object,
|
|
7
|
-
karmaConfig: any,
|
|
8
|
-
preTestFn?: () => any,
|
|
9
|
-
watch: boolean = process.argv.includes('--watch'),
|
|
10
|
-
) {
|
|
11
|
-
// Lazy require karma
|
|
12
|
-
const { Server, runner, stopper, config } = karma;
|
|
13
|
-
|
|
14
|
-
const testConfig = config.parseConfig(karmaConfig, {
|
|
15
|
-
autoWatch: false,
|
|
16
|
-
singleRun: !watch,
|
|
17
|
-
});
|
|
18
|
-
const server = new Server(testConfig, (exitCode) => {
|
|
19
|
-
buildLog(`Karma has exited with code ${exitCode}`);
|
|
20
|
-
});
|
|
21
|
-
onKillSignal(() => stopper.stop(testConfig));
|
|
22
|
-
|
|
23
|
-
let started = false;
|
|
24
|
-
async function doTest() {
|
|
25
|
-
if (!started) {
|
|
26
|
-
await Promise.all([
|
|
27
|
-
new Promise((resolve) => {
|
|
28
|
-
server.on('browsers_ready', resolve);
|
|
29
|
-
}),
|
|
30
|
-
server.start(),
|
|
31
|
-
]);
|
|
32
|
-
started = true;
|
|
33
|
-
}
|
|
34
|
-
if (watch) {
|
|
35
|
-
// await server.refreshFiles();
|
|
36
|
-
await new Promise((resolve, reject) => {
|
|
37
|
-
runner.run(testConfig, (exitCode) => {
|
|
38
|
-
buildLog(`Karma run completed with exit code ${exitCode}`);
|
|
39
|
-
if (exitCode === 0 || watch) {
|
|
40
|
-
resolve(exitCode);
|
|
41
|
-
} else {
|
|
42
|
-
reject(exitCode);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (typeof preTestFn === 'function') {
|
|
50
|
-
// preTestFn is expected to callback and run doTest
|
|
51
|
-
await run(preTestFn, doTest);
|
|
52
|
-
} else {
|
|
53
|
-
await doTest();
|
|
54
|
-
}
|
|
55
|
-
}
|
package/tgz.js.flow
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import tar from 'tar';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import crypto from 'crypto';
|
|
6
|
-
import StreamCounter from 'stream-counter';
|
|
7
|
-
import { makeDir } from './fs';
|
|
8
|
-
import { buildLog } from './run';
|
|
9
|
-
|
|
10
|
-
export type ArtifactInfo = {
|
|
11
|
-
md5: string,
|
|
12
|
-
sha1: string,
|
|
13
|
-
sha512: string,
|
|
14
|
-
size: number,
|
|
15
|
-
contentType?: string,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const generateHash = async (
|
|
19
|
-
stream: stream$Readable,
|
|
20
|
-
type: 'md5' | 'sha1' | 'sha512',
|
|
21
|
-
): Promise<string> =>
|
|
22
|
-
new Promise((resolve, reject) => {
|
|
23
|
-
stream
|
|
24
|
-
.pipe(crypto.createHash(type).setEncoding('hex'))
|
|
25
|
-
.on('finish', function () {
|
|
26
|
-
resolve(this.read());
|
|
27
|
-
})
|
|
28
|
-
.on('end', function () {
|
|
29
|
-
resolve(this.read());
|
|
30
|
-
})
|
|
31
|
-
.on('error', (err) => reject(err));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const countBytes = async (stream: stream$Readable): Promise<number> =>
|
|
35
|
-
new Promise((resolve, reject) => {
|
|
36
|
-
const counter = new StreamCounter();
|
|
37
|
-
stream
|
|
38
|
-
.pipe(counter)
|
|
39
|
-
.on('finish', () => resolve(counter.bytes))
|
|
40
|
-
.on('end', () => resolve(counter.bytes))
|
|
41
|
-
.on('error', (err) => reject(err));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const writeStreamToFile = async (stream: stream$Readable, filePath: string) =>
|
|
45
|
-
new Promise((resolve, reject) => {
|
|
46
|
-
stream
|
|
47
|
-
.pipe(fs.createWriteStream(filePath))
|
|
48
|
-
.on('finish', () => {
|
|
49
|
-
buildLog(`Successfully wrote file: ${filePath}`);
|
|
50
|
-
resolve();
|
|
51
|
-
})
|
|
52
|
-
.on('error', (err) => reject(err));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Take the given file (path or stream) and compute the info that artifactory needs.
|
|
56
|
-
// md5 + sha1 hash, and size in bytes
|
|
57
|
-
export async function getArtifactInfo(
|
|
58
|
-
artifact: string | stream$Readable,
|
|
59
|
-
): Promise<ArtifactInfo> {
|
|
60
|
-
// make it into a stream
|
|
61
|
-
const stream: stream$Readable =
|
|
62
|
-
typeof artifact === 'string' ? fs.createReadStream(artifact) : artifact;
|
|
63
|
-
|
|
64
|
-
const [md5, sha1, sha512, size] = await Promise.all([
|
|
65
|
-
generateHash(stream, 'md5'),
|
|
66
|
-
generateHash(stream, 'sha1'),
|
|
67
|
-
generateHash(stream, 'sha512'),
|
|
68
|
-
countBytes(stream),
|
|
69
|
-
]);
|
|
70
|
-
return { md5, sha1, sha512, size };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Creates a gzipped tarball of a directory, returns sha1 + md5 hash and size of resulting file
|
|
74
|
-
export async function tgzDir(
|
|
75
|
-
srcDir: string,
|
|
76
|
-
outPath: string,
|
|
77
|
-
options?: ?{ [string]: any },
|
|
78
|
-
): Promise<ArtifactInfo> {
|
|
79
|
-
await makeDir(path.dirname(outPath));
|
|
80
|
-
const tgzStream = tar.c(
|
|
81
|
-
// $FlowFixMe
|
|
82
|
-
{
|
|
83
|
-
gzip: true,
|
|
84
|
-
cwd: srcDir,
|
|
85
|
-
portable: true,
|
|
86
|
-
// $FlowFixMe
|
|
87
|
-
...options,
|
|
88
|
-
},
|
|
89
|
-
['.'],
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// write the file to disk (outPath)
|
|
93
|
-
const [info] = await Promise.all([
|
|
94
|
-
getArtifactInfo(tgzStream),
|
|
95
|
-
writeStreamToFile(tgzStream, `${outPath}`),
|
|
96
|
-
]);
|
|
97
|
-
return {
|
|
98
|
-
...info,
|
|
99
|
-
contentType: 'application/gzip',
|
|
100
|
-
};
|
|
101
|
-
}
|
package/version.js.flow
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { gitInfo } from './git';
|
|
4
|
-
import { hgInfo } from './hg';
|
|
5
|
-
import { getCfg, getPkg } from './pkg';
|
|
6
|
-
import { buildLog } from './run';
|
|
7
|
-
|
|
8
|
-
export function getBuild(): string {
|
|
9
|
-
let arg = process.argv.find((el) => /^--buildNum=\d+$/.test(el));
|
|
10
|
-
arg = arg && arg.substr(11);
|
|
11
|
-
return arg || process.env.BUILD_NUMBER || '0';
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getReleaseBranch(): string {
|
|
15
|
-
const { releaseBranch } = getCfg();
|
|
16
|
-
return releaseBranch || 'master';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type RepoType = 'git' | 'hg' | 'unknown';
|
|
20
|
-
export function getRepoType(): RepoType {
|
|
21
|
-
const { repoType } = getCfg();
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
repoType ||
|
|
25
|
-
(fs.existsSync('./.hg')
|
|
26
|
-
? 'hg'
|
|
27
|
-
: fs.existsSync('./.git')
|
|
28
|
-
? 'git'
|
|
29
|
-
: 'unknown')
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type RepoInfo = {
|
|
34
|
-
branch: string,
|
|
35
|
-
revision: string,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export async function getRepoInfo(): Promise<RepoInfo> {
|
|
39
|
-
const repoType = getRepoType();
|
|
40
|
-
const { branch, revision } =
|
|
41
|
-
repoType === 'git'
|
|
42
|
-
? await gitInfo()
|
|
43
|
-
: repoType === 'hg'
|
|
44
|
-
? await hgInfo()
|
|
45
|
-
: {};
|
|
46
|
-
if (!branch || !revision) {
|
|
47
|
-
throw new Error('Failed to parse branch and revision from source repo.');
|
|
48
|
-
}
|
|
49
|
-
return { branch, revision };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function getDevBranch(): string {
|
|
53
|
-
const { devBranch } = getCfg();
|
|
54
|
-
return devBranch || getRepoType() === 'hg' ? 'default' : 'dev';
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function getIsRelease(
|
|
58
|
-
passedBranch?: ?string = null,
|
|
59
|
-
releaseOverride?: ?boolean = null,
|
|
60
|
-
): Promise<boolean> {
|
|
61
|
-
const branch = passedBranch || (await getRepoInfo()).branch;
|
|
62
|
-
return releaseOverride != null
|
|
63
|
-
? releaseOverride
|
|
64
|
-
: process.argv.includes('--force-release-version')
|
|
65
|
-
? true
|
|
66
|
-
: branch === getReleaseBranch();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let cacheVersion = true;
|
|
70
|
-
export function useVersionCache(useCache: boolean = true): void {
|
|
71
|
-
cacheVersion = useCache;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export type Version = {|
|
|
75
|
-
branch: string,
|
|
76
|
-
build: string,
|
|
77
|
-
info: string,
|
|
78
|
-
isRelease: boolean,
|
|
79
|
-
major: string,
|
|
80
|
-
minor: string,
|
|
81
|
-
name: string,
|
|
82
|
-
npm: string,
|
|
83
|
-
patch: string,
|
|
84
|
-
revision: string,
|
|
85
|
-
short: string,
|
|
86
|
-
|};
|
|
87
|
-
|
|
88
|
-
let version = null;
|
|
89
|
-
export async function getVersion(
|
|
90
|
-
logIt: boolean = true,
|
|
91
|
-
release: ?boolean = null,
|
|
92
|
-
): Promise<Version> {
|
|
93
|
-
if (!cacheVersion || version == null) {
|
|
94
|
-
const { version: pkgVers, name } = getPkg();
|
|
95
|
-
const { branch, revision } = await getRepoInfo();
|
|
96
|
-
const [, major, minor, patch] =
|
|
97
|
-
pkgVers.match(/^(\d+)\.(\d+)\.(\d+)$/) || [];
|
|
98
|
-
if (!major || !minor || !patch) {
|
|
99
|
-
throw new Error('Invalid version format in package.json');
|
|
100
|
-
}
|
|
101
|
-
const build = getBuild();
|
|
102
|
-
const isRelease = await getIsRelease(branch, release);
|
|
103
|
-
const short = `${major}.${minor}.${patch}`;
|
|
104
|
-
const npm = `${short}${isRelease ? '' : `-${branch}.${build}`}`;
|
|
105
|
-
const info = `${short}${
|
|
106
|
-
isRelease ? `+${build}.` : `-${branch}.${build}+`
|
|
107
|
-
}${revision}`;
|
|
108
|
-
version = {
|
|
109
|
-
name,
|
|
110
|
-
branch,
|
|
111
|
-
revision,
|
|
112
|
-
major,
|
|
113
|
-
minor,
|
|
114
|
-
patch,
|
|
115
|
-
build,
|
|
116
|
-
short,
|
|
117
|
-
isRelease,
|
|
118
|
-
npm,
|
|
119
|
-
info,
|
|
120
|
-
};
|
|
121
|
-
if (logIt) buildLog(`Building version ${info}`);
|
|
122
|
-
}
|
|
123
|
-
return version;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function getBanner(): Promise<string> {
|
|
127
|
-
const { copyright = '' } = getCfg();
|
|
128
|
-
const { info, name } = await getVersion();
|
|
129
|
-
const today = new Date();
|
|
130
|
-
return `${name} v${info} | (c) ${today.getFullYear()} ${copyright} | built on ${today.toISOString()}`;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function getVersionCode(): Promise<string> {
|
|
134
|
-
return `// This file is auto-generated
|
|
135
|
-
export const version = ${JSON.stringify(await getVersion(), null, 2)}`;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export async function getUniqueBuildTag(): Promise<string> {
|
|
139
|
-
const { branch, revision, build } = await getVersion();
|
|
140
|
-
return `${branch}-${revision}-${build}`;
|
|
141
|
-
}
|
package/yarn.js.flow
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import md5File from 'md5-file';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { spawnAdv } from './cp';
|
|
6
|
-
import type { SpawnOptions, SpawnResult } from './cp';
|
|
7
|
-
import { buildLog } from './run';
|
|
8
|
-
import { readDir } from './fs';
|
|
9
|
-
import { getPkg } from './pkg';
|
|
10
|
-
|
|
11
|
-
export type YarnOptions = {|
|
|
12
|
-
args?: string[],
|
|
13
|
-
spawnOptions?: ?SpawnOptions,
|
|
14
|
-
|};
|
|
15
|
-
|
|
16
|
-
export async function yarnAdv(opts?: YarnOptions): Promise<SpawnResult> {
|
|
17
|
-
const { args = [], spawnOptions } = opts || {};
|
|
18
|
-
const localYarn = path.join(
|
|
19
|
-
path.dirname(process.execPath),
|
|
20
|
-
'/node_modules/yarn/bin/yarn.js',
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const spawnOpts = {
|
|
24
|
-
stdio: 'inherit',
|
|
25
|
-
shell: true,
|
|
26
|
-
env: process.env,
|
|
27
|
-
...spawnOptions,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
return (await fs.exists(localYarn))
|
|
31
|
-
? // prefer to use local copy of yarn
|
|
32
|
-
spawnAdv(process.execPath, [localYarn, ...args], spawnOpts)
|
|
33
|
-
: // fall back to globally installed yarn
|
|
34
|
-
spawnAdv('yarn', args, spawnOpts);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export async function yarn(opts?: YarnOptions): Promise<string> {
|
|
38
|
-
const { args = [], spawnOptions } = opts || {};
|
|
39
|
-
return yarnAdv({
|
|
40
|
-
args,
|
|
41
|
-
spawnOptions: { rejectOnErrorCode: true, ...spawnOptions },
|
|
42
|
-
}).then((r) => r.output);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export const yarnFiles = ['./package.json', './yarn.lock'];
|
|
46
|
-
|
|
47
|
-
export type YarnInstallOptions = {|
|
|
48
|
-
nodeModulesPath?: string,
|
|
49
|
-
hashFilePath?: string,
|
|
50
|
-
force?: boolean,
|
|
51
|
-
|};
|
|
52
|
-
|
|
53
|
-
// Smart yarn invocation, only if package changed
|
|
54
|
-
export async function yarnInstall(opts?: YarnInstallOptions) {
|
|
55
|
-
const {
|
|
56
|
-
nodeModulesPath = './node_modules',
|
|
57
|
-
hashFilePath = './download/buildHash_yarn.md5',
|
|
58
|
-
force = false,
|
|
59
|
-
} = opts || {};
|
|
60
|
-
await fs.ensureDir(nodeModulesPath);
|
|
61
|
-
const currentHash = (
|
|
62
|
-
await Promise.all(yarnFiles.map(async (f) => md5File(f)))
|
|
63
|
-
).join('|');
|
|
64
|
-
await fs.ensureFile(hashFilePath);
|
|
65
|
-
const prevHash = await fs.readFile(hashFilePath, 'utf8');
|
|
66
|
-
if (currentHash !== prevHash) {
|
|
67
|
-
buildLog(
|
|
68
|
-
'node package definition changed since last build, invoking yarn.',
|
|
69
|
-
);
|
|
70
|
-
} else if (!(await readDir(`${nodeModulesPath}/**/*.js`)).length) {
|
|
71
|
-
buildLog('node packages missing, invoking yarn.');
|
|
72
|
-
} else if (force) {
|
|
73
|
-
buildLog('node packages unchanged, but yarn forced on command line...');
|
|
74
|
-
} else {
|
|
75
|
-
buildLog('node packages unchanged since last build, skipping yarn.');
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
await yarn();
|
|
79
|
-
await fs.writeFile(hashFilePath, currentHash);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type YarnUpgradeOptions = {|
|
|
83
|
-
/**
|
|
84
|
-
* Use `yarn outdated` to find packages that should be upgraded
|
|
85
|
-
* May include breaking changes (major version changes)
|
|
86
|
-
*/
|
|
87
|
-
outdated?: boolean,
|
|
88
|
-
/**
|
|
89
|
-
* `false` by default
|
|
90
|
-
* we assume any package with an explicit version shouldn't be touched
|
|
91
|
-
*/
|
|
92
|
-
all?: boolean,
|
|
93
|
-
|};
|
|
94
|
-
|
|
95
|
-
export async function yarnUpgrade(opts?: YarnUpgradeOptions) {
|
|
96
|
-
const { outdated = false, all = false } = opts || {};
|
|
97
|
-
if (outdated) {
|
|
98
|
-
const { code, stdout } = await yarnAdv({
|
|
99
|
-
args: ['outdated'],
|
|
100
|
-
spawnOptions: { stdio: 'pipe', captureOutput: true },
|
|
101
|
-
});
|
|
102
|
-
if (code === 0) {
|
|
103
|
-
buildLog('No outdated packages.');
|
|
104
|
-
} else {
|
|
105
|
-
const { dependencies = {}, devDependencies = {} } = getPkg();
|
|
106
|
-
const packages = stdout
|
|
107
|
-
.split('\n')
|
|
108
|
-
.slice(5, -1)
|
|
109
|
-
.map((l) => l.split(/\s+/)[0])
|
|
110
|
-
.filter(
|
|
111
|
-
(p) =>
|
|
112
|
-
all || !/^\d/.test(dependencies[p] || devDependencies[p] || ''),
|
|
113
|
-
);
|
|
114
|
-
if (packages.length) {
|
|
115
|
-
await yarn({ args: ['add', ...packages] });
|
|
116
|
-
buildLog(`Upgraded: ${packages.join(', ')}`);
|
|
117
|
-
} else {
|
|
118
|
-
buildLog('No eligible outdated packages');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
await yarn({ args: ['upgrade'] });
|
|
123
|
-
}
|