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.
Files changed (108) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -34
  3. package/ant.d.ts +19 -0
  4. package/ant.js +12 -37
  5. package/cert.d.ts +12 -0
  6. package/cert.js +89 -151
  7. package/clean.d.ts +4 -0
  8. package/clean.js +7 -16
  9. package/copy.d.ts +7 -0
  10. package/copy.js +49 -76
  11. package/cp.d.ts +17 -0
  12. package/cp.js +85 -170
  13. package/docker.container.d.ts +73 -0
  14. package/docker.container.js +219 -362
  15. package/docker.d.ts +68 -0
  16. package/docker.js +167 -347
  17. package/docker.network.d.ts +42 -0
  18. package/docker.network.js +69 -144
  19. package/docker.volume.d.ts +26 -0
  20. package/docker.volume.js +52 -126
  21. package/dockerCleanup.d.ts +38 -0
  22. package/dockerCleanup.js +66 -141
  23. package/dockerCompose.d.ts +154 -0
  24. package/dockerCompose.js +400 -727
  25. package/fs.d.ts +5 -0
  26. package/fs.js +38 -95
  27. package/git.d.ts +9 -0
  28. package/git.js +19 -30
  29. package/index.d.ts +20 -0
  30. package/index.js +20 -27
  31. package/maps.d.ts +33 -0
  32. package/maps.js +16 -87
  33. package/npm.d.ts +42 -0
  34. package/npm.js +104 -135
  35. package/package.json +23 -19
  36. package/pkg.d.ts +39 -0
  37. package/pkg.js +26 -74
  38. package/publish.d.ts +27 -0
  39. package/publish.js +52 -140
  40. package/run.d.ts +13 -0
  41. package/run.js +39 -85
  42. package/tgz.d.ts +13 -0
  43. package/tgz.js +61 -96
  44. package/version.d.ts +34 -0
  45. package/version.js +86 -127
  46. package/yarn.d.ts +44 -0
  47. package/yarn.js +156 -119
  48. package/ant.js.flow +0 -42
  49. package/artifactory.js +0 -617
  50. package/artifactory.js.flow +0 -616
  51. package/cert.conf +0 -20
  52. package/cert.js.flow +0 -152
  53. package/clean.js.flow +0 -19
  54. package/copy.js.flow +0 -79
  55. package/cp.js.flow +0 -172
  56. package/docker.container.js.flow +0 -389
  57. package/docker.js.flow +0 -367
  58. package/docker.network.js.flow +0 -159
  59. package/docker.volume.js.flow +0 -136
  60. package/dockerCleanup.js.flow +0 -151
  61. package/dockerCompose.js.flow +0 -765
  62. package/flow.js +0 -21
  63. package/flow.js.flow +0 -20
  64. package/fs.js.flow +0 -96
  65. package/git.js.flow +0 -34
  66. package/hg.js +0 -35
  67. package/hg.js.flow +0 -34
  68. package/index.js.flow +0 -26
  69. package/inline-resources.js +0 -158
  70. package/inline-resources.js.flow +0 -157
  71. package/maps.js.flow +0 -111
  72. package/npm.js.flow +0 -144
  73. package/pkg.js.flow +0 -80
  74. package/publish.js.flow +0 -144
  75. package/run.js.flow +0 -89
  76. package/src/ant.js +0 -42
  77. package/src/artifactory.js +0 -616
  78. package/src/cert.conf +0 -20
  79. package/src/cert.js +0 -152
  80. package/src/clean.js +0 -19
  81. package/src/copy.js +0 -79
  82. package/src/cp.js +0 -172
  83. package/src/docker.container.js +0 -389
  84. package/src/docker.js +0 -367
  85. package/src/docker.network.js +0 -159
  86. package/src/docker.volume.js +0 -136
  87. package/src/dockerCleanup.js +0 -151
  88. package/src/dockerCompose.js +0 -765
  89. package/src/flow.js +0 -20
  90. package/src/fs.js +0 -96
  91. package/src/git.js +0 -34
  92. package/src/hg.js +0 -34
  93. package/src/index.js +0 -26
  94. package/src/inline-resources.js +0 -157
  95. package/src/maps.js +0 -111
  96. package/src/npm.js +0 -144
  97. package/src/pkg.js +0 -80
  98. package/src/publish.js +0 -144
  99. package/src/run.js +0 -89
  100. package/src/test.js +0 -55
  101. package/src/tgz.js +0 -101
  102. package/src/version.js +0 -141
  103. package/src/yarn.js +0 -123
  104. package/test.js +0 -56
  105. package/test.js.flow +0 -55
  106. package/tgz.js.flow +0 -101
  107. package/version.js.flow +0 -141
  108. package/yarn.js.flow +0 -123
package/cert.js.flow DELETED
@@ -1,152 +0,0 @@
1
- // @flow
2
- import os from 'os';
3
- import rp from 'request-promise-native';
4
- import path from 'path';
5
- import fs from 'fs-extra';
6
- import { buildLog } from './run';
7
- import { readDir } from './fs';
8
- import { spawn } from './cp';
9
- import { getCfg } from './pkg';
10
-
11
- export type CertConfig = {
12
- countryName?: string,
13
- stateOrProvinceName?: string,
14
- localityName?: string,
15
- organizationName?: string,
16
- organizationalUnitName?: string,
17
- commonName?: string,
18
- emailAddress?: string,
19
- };
20
-
21
- export function getCertConfig(): CertConfig {
22
- return getCfg().cert || {};
23
- }
24
-
25
- export function getIpAddresses(): string[] {
26
- const iFaces = os.networkInterfaces();
27
- return Object.keys(iFaces).reduce(
28
- (prev, ifName) => [
29
- ...prev,
30
- ...iFaces[ifName].map((iFace) => iFace.address),
31
- ],
32
- [],
33
- );
34
- }
35
-
36
- // Generate a self-signed certificate (if it doesn't exist)
37
- export async function generateCert(
38
- targetDir: string,
39
- force: boolean = process.argv.includes('--force-generateCert'),
40
- ) {
41
- if (process.argv.includes('--no-generateCert')) {
42
- buildLog('Skipping due to --no-generateCert');
43
- return;
44
- }
45
- buildLog(`scanning ${targetDir} for certificates...`);
46
- if (
47
- !force &&
48
- (await readDir(`${targetDir}/server.@(crt|key)`)).length === 2
49
- ) {
50
- buildLog('Skipping certificate generation: certificate already exists');
51
- return;
52
- }
53
- buildLog('Generating self-signed certificate...');
54
- const {
55
- countryName = 'US',
56
- stateOrProvinceName = 'Pennsylvania',
57
- localityName = 'SomeCity',
58
- organizationName = 'Company',
59
- organizationalUnitName = 'Product',
60
- commonName = 'app.company.com',
61
- emailAddress = 'contact@company.com',
62
- } = getCertConfig();
63
- const hostname = os.hostname();
64
- buildLog(`hostname: ${hostname}`);
65
- const ipAddresses = getIpAddresses();
66
- buildLog(`ip addresses: ${JSON.stringify(ipAddresses)}`);
67
- const ifconfig = await rp.get('https://ifconfig.co', { json: true });
68
- const externalIp4 = ifconfig.ip;
69
- buildLog(`external ipv4: ${externalIp4}`);
70
- const dnsName = ifconfig.hostname;
71
- buildLog(`dnsName: ${dnsName}`);
72
-
73
- await fs.ensureDir(targetDir);
74
- const keyFile = path.resolve(targetDir, 'server.key');
75
- const csrFile = path.resolve(targetDir, 'server.csr');
76
- const crtFile = path.resolve(targetDir, 'server.crt');
77
- const confTemplateFile = path.resolve(__dirname, 'cert.conf');
78
- const confFile = path.resolve(targetDir, 'cert.conf.generated');
79
- const confTemplate = await fs.readFile(confTemplateFile, 'utf8');
80
- await fs.writeFile(
81
- confFile,
82
- confTemplate
83
- .replace('{{countryName}}', countryName)
84
- .replace('{{stateOrProvinceName}}', stateOrProvinceName)
85
- .replace('{{localityName}}', localityName)
86
- .replace('{{organizationName}}', organizationName)
87
- .replace('{{organizationalUnitName}}', organizationalUnitName)
88
- .replace('{{commonName}}', commonName)
89
- .replace('{{emailAddress}}', emailAddress)
90
- .replace(
91
- '{{SAN_IP}}',
92
- ipAddresses.reduce((acc, next) => `${acc},IP:${next}`, ''),
93
- )
94
- .replace('{{SAN_DNS}}', `,DNS:${hostname},DNS:${dnsName}`),
95
- 'utf8',
96
- );
97
-
98
- buildLog('generating key file...');
99
- await spawn(
100
- 'openssl',
101
- [
102
- 'genpkey',
103
- '-algorithm',
104
- 'RSA',
105
- '-pkeyopt',
106
- 'rsa_keygen_bits:2048',
107
- '-out',
108
- keyFile,
109
- ],
110
- { pipeOutput: true },
111
- );
112
- buildLog('generating csr file...');
113
- await spawn(
114
- 'openssl',
115
- [
116
- 'req',
117
- '-new',
118
- '-key',
119
- keyFile,
120
- '-out',
121
- csrFile,
122
- '-subj',
123
- `/C=${countryName}/ST=${stateOrProvinceName}/L=${localityName}/O=${organizationName}/OU=${organizationalUnitName}/CN=${commonName}/CN=${externalIp4}/CN=${hostname}/CN=${dnsName}${ipAddresses.reduce(
124
- (acc, next) => `${acc}/CN=${next}`,
125
- )}/CN=localhost`,
126
- '-config',
127
- confFile,
128
- ],
129
- { pipeOutput: true },
130
- );
131
- buildLog('generating cert...');
132
- await spawn(
133
- 'openssl',
134
- [
135
- 'x509',
136
- '-req',
137
- '-days',
138
- '365',
139
- '-in',
140
- csrFile,
141
- '-signkey',
142
- keyFile,
143
- '-out',
144
- crtFile,
145
- '-extfile',
146
- confFile,
147
- '-extensions',
148
- 'v3_req',
149
- ],
150
- { pipeOutput: true },
151
- );
152
- }
package/clean.js.flow DELETED
@@ -1,19 +0,0 @@
1
- // @flow
2
- import { cleanDir } from './fs';
3
-
4
- /**
5
- * Cleans up the build output directories.
6
- */
7
- export async function clean(
8
- globs: string[] = ['dist/*', 'out/*', 'build/*'],
9
- ): Promise<void> {
10
- await Promise.all(
11
- globs.map((glob) =>
12
- cleanDir(glob, {
13
- nosort: true,
14
- dot: true,
15
- ignore: ['.git', '.hg'],
16
- }),
17
- ),
18
- );
19
- }
package/copy.js.flow DELETED
@@ -1,79 +0,0 @@
1
- // @flow
2
- import path from 'path';
3
- import chokidar from 'chokidar';
4
- import { copyFile, makeDir, copyDir, cleanDir } from './fs';
5
- import { onKillSignal } from './cp';
6
- import { buildLog } from './run';
7
- import { dependencies } from './inline-resources';
8
-
9
- let timer = null;
10
- async function throttledCallback(cbFn) {
11
- if (!cbFn || typeof cbFn !== 'function') {
12
- return;
13
- }
14
- if (timer) {
15
- clearTimeout(timer);
16
- timer = null;
17
- }
18
- timer = setTimeout(() => {
19
- timer = null;
20
- cbFn();
21
- }, 200);
22
- }
23
-
24
- export type CopySrcOptions = {
25
- from: string,
26
- to: string,
27
- watch?: boolean,
28
- cbFn?: () => Promise<any> | void,
29
- };
30
-
31
- export async function copySrc({
32
- from,
33
- to,
34
- watch = process.argv.includes('--watch'),
35
- cbFn,
36
- }: CopySrcOptions = {}) {
37
- await copyDir(from, to);
38
- if (cbFn) await cbFn();
39
- if (watch) {
40
- const watcher = chokidar.watch([path.join(from, '/**/*')], {
41
- ignoreInitial: true,
42
- });
43
-
44
- watcher.on('all', async (event, filePath) => {
45
- const start = new Date();
46
- const src = path.relative(from, filePath);
47
- const dest = path.join(to, src);
48
- switch (event) {
49
- case 'add':
50
- case 'change':
51
- await makeDir(path.dirname(dest));
52
- await copyFile(filePath, dest);
53
- break;
54
- case 'unlink':
55
- case 'unlinkDir':
56
- cleanDir(dest, { nosort: true, dot: true });
57
- break;
58
- default:
59
- return;
60
- }
61
- // Check dependencies
62
- if (dependencies[dest]) {
63
- await Promise.all(
64
- dependencies[dest].map(async (dep) => {
65
- const toCopy = path.join(from, path.relative(to, dep));
66
- await copyFile(toCopy, dep);
67
- buildLog(`copied '${dep}' due to changed dependency`);
68
- }),
69
- );
70
- }
71
- const end = new Date();
72
- const time = end.getTime() - start.getTime();
73
- buildLog(`${event} '${dest}' after ${time} ms`, end);
74
- throttledCallback(cbFn);
75
- });
76
-
77
- onKillSignal(() => watcher.close());
78
- }
79
- }
package/cp.js.flow DELETED
@@ -1,172 +0,0 @@
1
- // @flow
2
- import cp from 'child_process';
3
- import crossSpawn from 'cross-spawn';
4
- import { buildLog } from './run';
5
-
6
- export type NativeSpawnOptions = {|
7
- cwd?: string,
8
- env?: Object,
9
- argv0?: string,
10
- stdio?: string | Array<any>,
11
- detached?: boolean,
12
- uid?: number,
13
- gid?: number,
14
- shell?: boolean | string,
15
- windowsVerbatimArguments?: boolean,
16
- windowsHide?: boolean,
17
- |};
18
-
19
- export type SpawnOptions = {|
20
- ...NativeSpawnOptions,
21
- pipeOutput?: boolean,
22
- captureOutput?: boolean,
23
- rejectOnErrorCode?: boolean,
24
- |};
25
-
26
- export type SpawnResult = {|
27
- output: string,
28
- stdout: string,
29
- stderr: string,
30
- code: number,
31
- signal: string,
32
- |};
33
-
34
- export async function spawnAdv(
35
- command: string,
36
- args?: string[],
37
- opts?: ?SpawnOptions,
38
- ): Promise<SpawnResult> {
39
- const {
40
- pipeOutput = false,
41
- captureOutput = false,
42
- rejectOnErrorCode = false,
43
- ...options
44
- } = opts || {};
45
-
46
- return new Promise((resolve, reject) => {
47
- try {
48
- const toStr = () => `${command}${args ? ` ${args.join(' ')}` : ''}`;
49
- const p = crossSpawn(command, args, {
50
- ...options,
51
- // $FlowFixMe
52
- ...(pipeOutput && !captureOutput && !(options && options.stdio)
53
- ? { stdio: 'inherit' }
54
- : {}),
55
- });
56
-
57
- let output = '';
58
- let stdout = '';
59
- let stderr = '';
60
- if (captureOutput) {
61
- if (p.stdout) {
62
- if (pipeOutput) {
63
- p.stdout.pipe(process.stdout);
64
- }
65
- p.stdout.on('data', (d) => {
66
- const str = d.toString();
67
- stdout += str;
68
- output += str;
69
- });
70
- } else {
71
- buildLog(`Warning: cannot capture stdout for \`${toStr()}\``);
72
- }
73
- if (p.stderr) {
74
- if (pipeOutput) {
75
- p.stderr.pipe(process.stderr);
76
- }
77
- p.stderr.on('data', (d) => {
78
- const str = d.toString();
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,
99
- });
100
- }
101
- exitHandled = true;
102
- }
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);
123
- }
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
- });
168
- });
169
-
170
- export const onKillSignal = (cbFn: () => any) => {
171
- ['SIGINT', 'SIGTERM'].forEach((sig) => process.on(sig, cbFn));
172
- };