build-strap 3.0.0-dev.42 → 4.0.0

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 (130) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +3 -34
  3. package/dist/src/ant.d.ts +19 -0
  4. package/dist/src/ant.js +18 -0
  5. package/dist/src/cert.d.ts +12 -0
  6. package/dist/src/cert.js +91 -0
  7. package/dist/src/clean.d.ts +4 -0
  8. package/dist/src/clean.js +11 -0
  9. package/dist/src/copy.d.ts +7 -0
  10. package/dist/src/copy.js +53 -0
  11. package/dist/src/cp.d.ts +17 -0
  12. package/dist/src/cp.js +88 -0
  13. package/dist/src/docker.container.d.ts +73 -0
  14. package/dist/src/docker.container.js +247 -0
  15. package/dist/src/docker.d.ts +68 -0
  16. package/dist/src/docker.js +188 -0
  17. package/dist/src/docker.network.d.ts +42 -0
  18. package/dist/src/docker.network.js +85 -0
  19. package/dist/src/docker.volume.d.ts +26 -0
  20. package/dist/src/docker.volume.js +62 -0
  21. package/dist/src/dockerCleanup.d.ts +38 -0
  22. package/dist/src/dockerCleanup.js +77 -0
  23. package/dist/src/dockerCompose.d.ts +154 -0
  24. package/dist/src/dockerCompose.js +439 -0
  25. package/dist/src/fs.d.ts +5 -0
  26. package/dist/src/fs.js +38 -0
  27. package/dist/src/git.d.ts +9 -0
  28. package/dist/src/git.js +24 -0
  29. package/dist/src/index.d.ts +20 -0
  30. package/dist/src/index.js +20 -0
  31. package/dist/src/maps.d.ts +33 -0
  32. package/dist/src/maps.js +41 -0
  33. package/dist/src/npm.d.ts +35 -0
  34. package/dist/src/npm.js +104 -0
  35. package/dist/src/pkg.d.ts +33 -0
  36. package/dist/src/pkg.js +33 -0
  37. package/dist/src/publish.d.ts +27 -0
  38. package/dist/src/publish.js +57 -0
  39. package/dist/src/run.d.ts +13 -0
  40. package/dist/src/run.js +44 -0
  41. package/dist/src/tgz.d.ts +13 -0
  42. package/dist/src/tgz.js +67 -0
  43. package/dist/src/version.d.ts +34 -0
  44. package/dist/src/version.js +101 -0
  45. package/dist/src/yarn.d.ts +26 -0
  46. package/dist/src/yarn.js +75 -0
  47. package/package.json +74 -20
  48. package/ant.js +0 -43
  49. package/ant.js.flow +0 -42
  50. package/artifactory.js +0 -617
  51. package/artifactory.js.flow +0 -616
  52. package/cert.conf +0 -20
  53. package/cert.js +0 -153
  54. package/cert.js.flow +0 -152
  55. package/clean.js +0 -20
  56. package/clean.js.flow +0 -19
  57. package/copy.js +0 -80
  58. package/copy.js.flow +0 -79
  59. package/cp.js +0 -173
  60. package/cp.js.flow +0 -172
  61. package/docker.container.js +0 -390
  62. package/docker.container.js.flow +0 -389
  63. package/docker.js +0 -368
  64. package/docker.js.flow +0 -367
  65. package/docker.network.js +0 -160
  66. package/docker.network.js.flow +0 -159
  67. package/docker.volume.js +0 -136
  68. package/docker.volume.js.flow +0 -136
  69. package/dockerCleanup.js +0 -152
  70. package/dockerCleanup.js.flow +0 -151
  71. package/dockerCompose.js +0 -766
  72. package/dockerCompose.js.flow +0 -765
  73. package/flow.js +0 -21
  74. package/flow.js.flow +0 -20
  75. package/fs.js +0 -95
  76. package/fs.js.flow +0 -96
  77. package/git.js +0 -35
  78. package/git.js.flow +0 -34
  79. package/hg.js +0 -35
  80. package/hg.js.flow +0 -34
  81. package/index.js +0 -27
  82. package/index.js.flow +0 -26
  83. package/inline-resources.js +0 -158
  84. package/inline-resources.js.flow +0 -157
  85. package/maps.js +0 -112
  86. package/maps.js.flow +0 -111
  87. package/npm.js +0 -145
  88. package/npm.js.flow +0 -144
  89. package/pkg.js +0 -81
  90. package/pkg.js.flow +0 -80
  91. package/publish.js +0 -145
  92. package/publish.js.flow +0 -144
  93. package/run.js +0 -90
  94. package/run.js.flow +0 -89
  95. package/src/ant.js +0 -42
  96. package/src/artifactory.js +0 -616
  97. package/src/cert.conf +0 -20
  98. package/src/cert.js +0 -152
  99. package/src/clean.js +0 -19
  100. package/src/copy.js +0 -79
  101. package/src/cp.js +0 -172
  102. package/src/docker.container.js +0 -389
  103. package/src/docker.js +0 -367
  104. package/src/docker.network.js +0 -159
  105. package/src/docker.volume.js +0 -136
  106. package/src/dockerCleanup.js +0 -151
  107. package/src/dockerCompose.js +0 -765
  108. package/src/flow.js +0 -20
  109. package/src/fs.js +0 -96
  110. package/src/git.js +0 -34
  111. package/src/hg.js +0 -34
  112. package/src/index.js +0 -26
  113. package/src/inline-resources.js +0 -157
  114. package/src/maps.js +0 -111
  115. package/src/npm.js +0 -144
  116. package/src/pkg.js +0 -80
  117. package/src/publish.js +0 -144
  118. package/src/run.js +0 -89
  119. package/src/test.js +0 -55
  120. package/src/tgz.js +0 -101
  121. package/src/version.js +0 -141
  122. package/src/yarn.js +0 -123
  123. package/test.js +0 -56
  124. package/test.js.flow +0 -55
  125. package/tgz.js +0 -102
  126. package/tgz.js.flow +0 -101
  127. package/version.js +0 -142
  128. package/version.js.flow +0 -141
  129. package/yarn.js +0 -124
  130. 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 = {}) {
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
- };