build-strap 4.0.0-dev.46 → 4.0.0-dev.5

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 (107) hide show
  1. package/README.md +3 -34
  2. package/ant.d.ts +19 -0
  3. package/ant.js +12 -37
  4. package/cert.d.ts +12 -0
  5. package/cert.js +89 -151
  6. package/clean.d.ts +4 -0
  7. package/clean.js +7 -16
  8. package/copy.d.ts +7 -0
  9. package/copy.js +49 -76
  10. package/cp.d.ts +17 -0
  11. package/cp.js +85 -170
  12. package/docker.container.d.ts +73 -0
  13. package/docker.container.js +219 -362
  14. package/docker.d.ts +68 -0
  15. package/docker.js +167 -344
  16. package/docker.network.d.ts +42 -0
  17. package/docker.network.js +69 -144
  18. package/docker.volume.d.ts +26 -0
  19. package/docker.volume.js +52 -126
  20. package/dockerCleanup.d.ts +38 -0
  21. package/dockerCleanup.js +66 -141
  22. package/dockerCompose.d.ts +154 -0
  23. package/dockerCompose.js +400 -727
  24. package/fs.d.ts +5 -0
  25. package/fs.js +38 -95
  26. package/git.d.ts +9 -0
  27. package/git.js +19 -30
  28. package/index.d.ts +20 -0
  29. package/index.js +20 -27
  30. package/maps.d.ts +33 -0
  31. package/maps.js +16 -87
  32. package/npm.d.ts +48 -0
  33. package/npm.js +131 -135
  34. package/package.json +23 -19
  35. package/pkg.d.ts +39 -0
  36. package/pkg.js +26 -74
  37. package/publish.d.ts +27 -0
  38. package/publish.js +52 -140
  39. package/run.d.ts +13 -0
  40. package/run.js +39 -85
  41. package/tgz.d.ts +13 -0
  42. package/tgz.js +61 -96
  43. package/version.d.ts +34 -0
  44. package/version.js +86 -128
  45. package/yarn.d.ts +44 -0
  46. package/yarn.js +150 -119
  47. package/ant.js.flow +0 -42
  48. package/artifactory.js +0 -617
  49. package/artifactory.js.flow +0 -616
  50. package/cert.conf +0 -20
  51. package/cert.js.flow +0 -152
  52. package/clean.js.flow +0 -19
  53. package/copy.js.flow +0 -79
  54. package/cp.js.flow +0 -172
  55. package/docker.container.js.flow +0 -389
  56. package/docker.js.flow +0 -364
  57. package/docker.network.js.flow +0 -159
  58. package/docker.volume.js.flow +0 -136
  59. package/dockerCleanup.js.flow +0 -151
  60. package/dockerCompose.js.flow +0 -765
  61. package/flow.js +0 -21
  62. package/flow.js.flow +0 -20
  63. package/fs.js.flow +0 -96
  64. package/git.js.flow +0 -34
  65. package/hg.js +0 -35
  66. package/hg.js.flow +0 -34
  67. package/index.js.flow +0 -26
  68. package/inline-resources.js +0 -158
  69. package/inline-resources.js.flow +0 -157
  70. package/maps.js.flow +0 -111
  71. package/npm.js.flow +0 -144
  72. package/pkg.js.flow +0 -80
  73. package/publish.js.flow +0 -144
  74. package/run.js.flow +0 -89
  75. package/src/ant.js +0 -42
  76. package/src/artifactory.js +0 -616
  77. package/src/cert.conf +0 -20
  78. package/src/cert.js +0 -152
  79. package/src/clean.js +0 -19
  80. package/src/copy.js +0 -79
  81. package/src/cp.js +0 -172
  82. package/src/docker.container.js +0 -389
  83. package/src/docker.js +0 -364
  84. package/src/docker.network.js +0 -159
  85. package/src/docker.volume.js +0 -136
  86. package/src/dockerCleanup.js +0 -151
  87. package/src/dockerCompose.js +0 -765
  88. package/src/flow.js +0 -20
  89. package/src/fs.js +0 -96
  90. package/src/git.js +0 -34
  91. package/src/hg.js +0 -34
  92. package/src/index.js +0 -26
  93. package/src/inline-resources.js +0 -157
  94. package/src/maps.js +0 -111
  95. package/src/npm.js +0 -144
  96. package/src/pkg.js +0 -80
  97. package/src/publish.js +0 -144
  98. package/src/run.js +0 -89
  99. package/src/test.js +0 -55
  100. package/src/tgz.js +0 -101
  101. package/src/version.js +0 -142
  102. package/src/yarn.js +0 -123
  103. package/test.js +0 -56
  104. package/test.js.flow +0 -55
  105. package/tgz.js.flow +0 -101
  106. package/version.js.flow +0 -142
  107. package/yarn.js.flow +0 -123
package/src/cert.js 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/src/clean.js 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/src/copy.js 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 = {}): Promise<void> {
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/src/cp.js 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
- };