build-strap 4.0.0-dev.46 → 4.0.0-dev.54
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/README.md +3 -34
- package/package.json +23 -19
- package/src/ant.d.ts +19 -0
- package/src/ant.js +12 -36
- package/src/cert.d.ts +12 -0
- package/src/cert.js +87 -148
- package/src/clean.d.ts +4 -0
- package/src/clean.js +5 -13
- package/src/copy.d.ts +7 -0
- package/src/copy.js +48 -74
- package/src/cp.d.ts +17 -0
- package/src/cp.js +81 -165
- package/src/docker.container.d.ts +73 -0
- package/src/docker.container.js +208 -350
- package/src/docker.d.ts +68 -0
- package/src/docker.js +163 -339
- package/src/docker.network.d.ts +42 -0
- package/src/docker.network.js +67 -141
- package/src/docker.volume.d.ts +26 -0
- package/src/docker.volume.js +50 -124
- package/src/dockerCleanup.d.ts +38 -0
- package/src/dockerCleanup.js +62 -136
- package/src/dockerCompose.d.ts +154 -0
- package/src/dockerCompose.js +390 -716
- package/src/fs.d.ts +5 -0
- package/src/fs.js +33 -91
- package/src/git.d.ts +9 -0
- package/src/git.js +19 -29
- package/src/index.d.ts +20 -0
- package/src/index.js +20 -26
- package/src/maps.d.ts +33 -0
- package/src/maps.js +12 -82
- package/src/npm.d.ts +48 -0
- package/src/npm.js +128 -131
- package/src/pkg.d.ts +38 -0
- package/src/pkg.js +27 -74
- package/src/publish.d.ts +27 -0
- package/src/publish.js +51 -138
- package/src/run.d.ts +13 -0
- package/src/run.js +39 -84
- package/src/tgz.d.ts +13 -0
- package/src/tgz.js +54 -88
- package/src/version.d.ts +34 -0
- package/src/version.js +85 -126
- package/src/yarn.d.ts +44 -0
- package/src/yarn.js +147 -115
- package/ant.js +0 -43
- 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 +0 -153
- package/cert.js.flow +0 -152
- package/clean.js +0 -20
- package/clean.js.flow +0 -19
- package/copy.js +0 -80
- package/copy.js.flow +0 -79
- package/cp.js +0 -173
- package/cp.js.flow +0 -172
- package/docker.container.js +0 -390
- package/docker.container.js.flow +0 -389
- package/docker.js +0 -365
- package/docker.js.flow +0 -364
- package/docker.network.js +0 -160
- package/docker.network.js.flow +0 -159
- package/docker.volume.js +0 -136
- package/docker.volume.js.flow +0 -136
- package/dockerCleanup.js +0 -152
- package/dockerCleanup.js.flow +0 -151
- package/dockerCompose.js +0 -766
- package/dockerCompose.js.flow +0 -765
- package/flow.js +0 -21
- package/flow.js.flow +0 -20
- package/fs.js +0 -95
- package/fs.js.flow +0 -96
- package/git.js +0 -35
- package/git.js.flow +0 -34
- package/hg.js +0 -35
- package/hg.js.flow +0 -34
- package/index.js +0 -27
- package/index.js.flow +0 -26
- package/inline-resources.js +0 -158
- package/inline-resources.js.flow +0 -157
- package/maps.js +0 -112
- package/maps.js.flow +0 -111
- package/npm.js +0 -145
- package/npm.js.flow +0 -144
- package/pkg.js +0 -81
- package/pkg.js.flow +0 -80
- package/publish.js +0 -145
- package/publish.js.flow +0 -144
- package/run.js +0 -90
- package/run.js.flow +0 -89
- package/src/artifactory.js +0 -616
- package/src/cert.conf +0 -20
- package/src/flow.js +0 -20
- package/src/hg.js +0 -34
- package/src/inline-resources.js +0 -157
- package/src/test.js +0 -55
- package/test.js +0 -56
- package/test.js.flow +0 -55
- package/tgz.js +0 -102
- package/tgz.js.flow +0 -101
- package/version.js +0 -143
- package/version.js.flow +0 -142
- package/yarn.js +0 -124
- package/yarn.js.flow +0 -123
package/src/cp.js
CHANGED
|
@@ -1,172 +1,88 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import cp from 'child_process';
|
|
3
2
|
import crossSpawn from 'cross-spawn';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export
|
|
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
|
-
|
|
79
|
-
stderr += str;
|
|
80
|
-
output += str;
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
buildLog(`Warning: cannot capture stderr for \`${toStr()}\``);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let exitHandled = false;
|
|
88
|
-
const handleExit = (code, signal) => {
|
|
89
|
-
if (!exitHandled) {
|
|
90
|
-
if (rejectOnErrorCode && code) {
|
|
91
|
-
reject(new Error(`${toStr()} => ${code} (error)`));
|
|
92
|
-
} else {
|
|
93
|
-
resolve({
|
|
94
|
-
output,
|
|
95
|
-
stdout,
|
|
96
|
-
stderr,
|
|
97
|
-
code,
|
|
98
|
-
signal,
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { buildLog } from './run.js';
|
|
5
|
+
export async function spawn(command, args, opts) {
|
|
6
|
+
const { captureOutput = false, pipeOutput = false, rejectOnErrorCode = true, ...options } = opts || {};
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
try {
|
|
9
|
+
const toStr = () => `${command}${args ? ` ${args.join(' ')}` : ''}`;
|
|
10
|
+
const p = crossSpawn(command, args, {
|
|
11
|
+
...(pipeOutput && !captureOutput ? { stdio: 'inherit' } : {}),
|
|
12
|
+
...options,
|
|
13
|
+
});
|
|
14
|
+
let output = '';
|
|
15
|
+
let stdout = '';
|
|
16
|
+
let stderr = '';
|
|
17
|
+
if (captureOutput) {
|
|
18
|
+
if (p.stdout) {
|
|
19
|
+
if (pipeOutput) {
|
|
20
|
+
p.stdout.pipe(process.stdout);
|
|
21
|
+
}
|
|
22
|
+
p.stdout.on('data', (d) => {
|
|
23
|
+
const str = d.toString();
|
|
24
|
+
stdout += str;
|
|
25
|
+
output += str;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
buildLog(`Warning: cannot capture stdout for \`${toStr()}\``);
|
|
30
|
+
}
|
|
31
|
+
if (p.stderr) {
|
|
32
|
+
if (pipeOutput) {
|
|
33
|
+
p.stderr.pipe(process.stderr);
|
|
34
|
+
}
|
|
35
|
+
p.stderr.on('data', (d) => {
|
|
36
|
+
const str = d.toString();
|
|
37
|
+
stderr += str;
|
|
38
|
+
output += str;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
buildLog(`Warning: cannot capture stderr for \`${toStr()}\``);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
let exitHandled = false;
|
|
46
|
+
const handleExit = (code, signal) => {
|
|
47
|
+
if (!exitHandled) {
|
|
48
|
+
if (rejectOnErrorCode && code) {
|
|
49
|
+
reject(new Error(`${toStr()} => ${code} (error)`));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
resolve({
|
|
53
|
+
code,
|
|
54
|
+
output,
|
|
55
|
+
signal,
|
|
56
|
+
stderr,
|
|
57
|
+
stdout,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exitHandled = true;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
p.on('close', handleExit);
|
|
64
|
+
p.on('exit', handleExit);
|
|
65
|
+
// only fires if we failed to spawn
|
|
66
|
+
p.on('error', (err) => {
|
|
67
|
+
// Here we have a workaround that reverses a "feature" of cross-spawn on Windows. See:
|
|
68
|
+
// https://github.com/moxystudio/node-cross-spawn/blob/master/lib/enoent.js#L23
|
|
69
|
+
// https://github.com/moxystudio/node-cross-spawn/issues/104
|
|
70
|
+
if (process.platform === 'win32' &&
|
|
71
|
+
err.code === 'ENOENT' &&
|
|
72
|
+
err.errno === 'ENOENT') {
|
|
73
|
+
handleExit(1, 'ENOENT');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
reject(err);
|
|
77
|
+
}
|
|
99
78
|
});
|
|
100
|
-
}
|
|
101
|
-
exitHandled = true;
|
|
102
79
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
p.on('close', handleExit);
|
|
106
|
-
|
|
107
|
-
p.on('exit', handleExit);
|
|
108
|
-
|
|
109
|
-
// only fires if we failed to spawn
|
|
110
|
-
p.on('error', (err) => {
|
|
111
|
-
// Here we have a workaround that reverses a "feature" of cross-spawn on Windows. See:
|
|
112
|
-
// https://jira.mmodal.com/browse/BTN-8
|
|
113
|
-
// https://github.com/moxystudio/node-cross-spawn/blob/master/lib/enoent.js#L23
|
|
114
|
-
// https://github.com/moxystudio/node-cross-spawn/issues/104
|
|
115
|
-
if (
|
|
116
|
-
process.platform === 'win32' &&
|
|
117
|
-
err.code === 'ENOENT' &&
|
|
118
|
-
err.errno === 'ENOENT'
|
|
119
|
-
) {
|
|
120
|
-
handleExit(1, 'ENOENT');
|
|
121
|
-
} else {
|
|
122
|
-
reject(err);
|
|
80
|
+
catch (err) {
|
|
81
|
+
reject(err);
|
|
123
82
|
}
|
|
124
|
-
});
|
|
125
|
-
} catch (err) {
|
|
126
|
-
reject(err);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// older, simpler interface that just returns a string
|
|
132
|
-
export async function spawn(
|
|
133
|
-
command: string,
|
|
134
|
-
args?: string[],
|
|
135
|
-
opts?: ?SpawnOptions,
|
|
136
|
-
): Promise<string> {
|
|
137
|
-
return spawnAdv(command, args, { rejectOnErrorCode: true, ...opts }).then(
|
|
138
|
-
(r) => r.output,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export type ExecOptions = {|
|
|
143
|
-
cwd?: string,
|
|
144
|
-
env?: Object,
|
|
145
|
-
encoding?: string,
|
|
146
|
-
shell?: string,
|
|
147
|
-
timeout?: number,
|
|
148
|
-
maxBuffer?: number,
|
|
149
|
-
killSignal?: string | number,
|
|
150
|
-
uid?: number,
|
|
151
|
-
gid?: number,
|
|
152
|
-
windowsHide?: boolean,
|
|
153
|
-
|};
|
|
154
|
-
|
|
155
|
-
export const exec = async (
|
|
156
|
-
command: string,
|
|
157
|
-
options?: ExecOptions,
|
|
158
|
-
): Promise<{ stdout: string | Buffer, stderr: string | Buffer }> =>
|
|
159
|
-
new Promise((resolve, reject) => {
|
|
160
|
-
cp.exec(command, options, (err, stdout, stderr) => {
|
|
161
|
-
if (err) {
|
|
162
|
-
reject(err);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
resolve({ stdout, stderr });
|
|
167
83
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
export const onKillSignal = (cbFn
|
|
171
|
-
|
|
84
|
+
}
|
|
85
|
+
export const exec = promisify(cp.exec);
|
|
86
|
+
export const onKillSignal = (cbFn) => {
|
|
87
|
+
['SIGINT', 'SIGTERM'].forEach((sig) => process.on(sig, cbFn));
|
|
172
88
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SpawnOptions } from './cp.js';
|
|
2
|
+
interface DockerContainerInspectOutput {
|
|
3
|
+
State: {
|
|
4
|
+
Running: boolean;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
interface Port {
|
|
8
|
+
dest: number;
|
|
9
|
+
iface: string;
|
|
10
|
+
src: number;
|
|
11
|
+
}
|
|
12
|
+
export interface DockerContainer {
|
|
13
|
+
command: string;
|
|
14
|
+
created: Date;
|
|
15
|
+
exists: () => Promise<boolean>;
|
|
16
|
+
exited: boolean;
|
|
17
|
+
id: string;
|
|
18
|
+
image: string;
|
|
19
|
+
inspect: () => Promise<DockerContainerInspectOutput | undefined>;
|
|
20
|
+
isRunning: () => Promise<boolean>;
|
|
21
|
+
kill: (ignoreError?: boolean) => Promise<void>;
|
|
22
|
+
labels: string[];
|
|
23
|
+
mounts: string[];
|
|
24
|
+
name: string;
|
|
25
|
+
names: string[];
|
|
26
|
+
networks: string[];
|
|
27
|
+
ports: Port[];
|
|
28
|
+
restart: () => Promise<void>;
|
|
29
|
+
rm: (ignoreError?: boolean) => Promise<void>;
|
|
30
|
+
runningFor: string;
|
|
31
|
+
size: number;
|
|
32
|
+
start: () => Promise<void>;
|
|
33
|
+
status: string;
|
|
34
|
+
stop: (ignoreError?: boolean) => Promise<void>;
|
|
35
|
+
teardown: (verbose?: boolean) => Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
interface DockerContainerLsOptions {
|
|
38
|
+
all?: boolean;
|
|
39
|
+
filter?: (container: DockerContainer) => boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare function unthrottledDockerContainerLs({ all, filter, }?: DockerContainerLsOptions): Promise<DockerContainer[]>;
|
|
42
|
+
export declare const dockerContainerLs: (options: DockerContainerLsOptions | undefined) => Promise<DockerContainer[]> | undefined;
|
|
43
|
+
export declare function dockerContainerFind(search: string, options?: DockerContainerLsOptions): Promise<DockerContainer | null>;
|
|
44
|
+
export declare function dockerContainerStop(id: string | string[], ignoreErrors?: boolean): Promise<void>;
|
|
45
|
+
export declare function dockerContainerKill(id: string | string[], ignoreErrors?: boolean): Promise<void>;
|
|
46
|
+
export declare function dockerTryStopContainer(id: string | null, name?: string): Promise<void>;
|
|
47
|
+
export declare function dockerContainerRm(id: string | string[], ignoreErrors?: boolean): Promise<void>;
|
|
48
|
+
export declare function dockerContainerRestart(id: string | string[]): Promise<void>;
|
|
49
|
+
export declare function dockerContainerStart(id: string | string[]): Promise<void>;
|
|
50
|
+
export declare function unthrottledDockerContainerInspect(id: string | string[]): Promise<DockerContainerInspectOutput[]>;
|
|
51
|
+
export declare const dockerContainerInspect: (id: string | string[]) => Promise<DockerContainerInspectOutput[]> | undefined;
|
|
52
|
+
interface DockerContainerRunDaemonArgs {
|
|
53
|
+
cmd?: string[];
|
|
54
|
+
image: string;
|
|
55
|
+
runArgs?: string[];
|
|
56
|
+
waitAttempts?: number;
|
|
57
|
+
waitDuration?: number;
|
|
58
|
+
}
|
|
59
|
+
interface DockerContainerRunArgs extends DockerContainerRunDaemonArgs {
|
|
60
|
+
spawnOptions?: SpawnOptions | null;
|
|
61
|
+
}
|
|
62
|
+
export declare function dockerContainerRun({ image, runArgs, cmd, spawnOptions, }: DockerContainerRunArgs): Promise<string>;
|
|
63
|
+
export declare function dockerContainerRunDaemon({ image, runArgs, cmd, waitAttempts, waitDuration, }: DockerContainerRunDaemonArgs): Promise<DockerContainer>;
|
|
64
|
+
/**
|
|
65
|
+
* Waits for the given container to be fully started. Checks that the container is
|
|
66
|
+
* running, and test with the provided testFn every second until it returns true.
|
|
67
|
+
* @param {DockerContainer} container The container to test
|
|
68
|
+
* @param {Function} testFn A function that validates that the container is ready (e.g. by calling an API on the container)
|
|
69
|
+
* @param {number} timeoutMs The amount of time to wait between attempts.
|
|
70
|
+
* @param {number} maxAttempts The maximum number of attempts before giving up (rejects promise)
|
|
71
|
+
*/
|
|
72
|
+
export declare const dockerContainerWaitForStart: (container: DockerContainer, testFn: (container: DockerContainer) => Promise<boolean>, timeoutMs?: number, maxAttempts?: number) => Promise<void>;
|
|
73
|
+
export {};
|