build-strap 3.0.0 → 4.0.0-dev.4
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 +48 -0
- package/npm.js +133 -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 +150 -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/maps.js.flow
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
// Util functions for using objects as maps and preserving type information
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* An object with arbitrary keys, where every key's value is of the same type.
|
|
6
|
-
*/
|
|
7
|
-
export type ObjMap<V, K: string = string> = {
|
|
8
|
-
+[K]: V,
|
|
9
|
-
};
|
|
10
|
-
// Alias for above, generics in opposite order (for backwards compat)
|
|
11
|
-
export type MapObj<K, V> = ObjMap<V, K>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Given an input object, return an array of the keys.
|
|
15
|
-
* This is a wrapper around the standard `Object.keys` that preserves type information.
|
|
16
|
-
* @param {ObjMap} obj the input object
|
|
17
|
-
* @returns {Array} an array of keys. These will always be strings, but flow may assign
|
|
18
|
-
* a more specific type when possible
|
|
19
|
-
*/
|
|
20
|
-
export const keys = <V, K: string = string>(obj?: ?ObjMap<V, K>): K[] =>
|
|
21
|
-
(Object.keys(obj || {}): any);
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Given an input object, return an array of the values.
|
|
25
|
-
* This is a wrapper around the standard `Object.values` that preserves type information.
|
|
26
|
-
* @param {ObjMap} obj the input object
|
|
27
|
-
* @returns {Array} an array of values
|
|
28
|
-
*/
|
|
29
|
-
export const values = <V, K: string = string>(obj?: ?ObjMap<V, K>): V[] =>
|
|
30
|
-
(Object.values(obj || {}): any);
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Given a `ObjMap`, return an array of the entries.
|
|
34
|
-
* This is a wrapper around the standard `Object.entries` that preserves type information.
|
|
35
|
-
* It assumes an object with homogenous values.
|
|
36
|
-
* @param {ObjMap} obj the input object
|
|
37
|
-
* @returns {Array} an array of entry [key, value] tuples
|
|
38
|
-
*/
|
|
39
|
-
export const entries = <V, K: string = string>(obj?: ?ObjMap<V, K>): [K, V][] =>
|
|
40
|
-
(Object.entries(obj || {}): any);
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Given a `ObjMap`, iterate over each entry and run it through the given `map` function.
|
|
44
|
-
* @param {ObjMap} obj the input object
|
|
45
|
-
* @param {Function} map the mapping operation
|
|
46
|
-
* @returns {ObjMap} a new object
|
|
47
|
-
*/
|
|
48
|
-
export const mapValues = <V, K: string, R>(
|
|
49
|
-
obj?: ?ObjMap<V, K>,
|
|
50
|
-
map: (V, K, ObjMap<V, K>) => R,
|
|
51
|
-
): ObjMap<R, K> =>
|
|
52
|
-
entries(obj).reduce(
|
|
53
|
-
(acc, [k, v]) =>
|
|
54
|
-
Object.assign(acc, {
|
|
55
|
-
[k]: map(v, k, obj || {}),
|
|
56
|
-
}),
|
|
57
|
-
{},
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Given a `ObjMap`, iterate over each entry and run it through the given async `map` function.
|
|
62
|
-
* The promise returned by the `map` is awaited, such that the resulting `ObjMap` values are
|
|
63
|
-
* the result of the resolved promise.
|
|
64
|
-
* @param {ObjMap} obj the input object
|
|
65
|
-
* @param {Function} map the async mapping operation
|
|
66
|
-
* @returns {Promise} a promise for a new object
|
|
67
|
-
*/
|
|
68
|
-
export const mapValuesAsync = async <V, K: string, R>(
|
|
69
|
-
obj?: ?ObjMap<V, K>,
|
|
70
|
-
map: (V, K, ObjMap<V, K>) => Promise<R>,
|
|
71
|
-
): Promise<ObjMap<R, K>> =>
|
|
72
|
-
entries(obj).reduce(
|
|
73
|
-
async (acc, [k, v]) =>
|
|
74
|
-
Object.assign(await acc, {
|
|
75
|
-
[k]: await map(v, k, obj || {}),
|
|
76
|
-
}),
|
|
77
|
-
{},
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Given a `ObjMap`, iterate over each entry and run it through the given `filter` function.
|
|
82
|
-
* Any entry for which the `filter` returns `false` is removed from the resulting `ObjMap`.
|
|
83
|
-
* All other entries are left as-is. The resulting output is a subset of the input.
|
|
84
|
-
* If no `filter` is specified, default to filtering out nullish values.
|
|
85
|
-
* @param {ObjMap} obj the input object
|
|
86
|
-
* @param {Function} filter the filter operation
|
|
87
|
-
* @returns {ObjMap} a new object, a subset of the input
|
|
88
|
-
*/
|
|
89
|
-
export const filterKeys = <V, K: string = string>(
|
|
90
|
-
obj?: ?ObjMap<V, K>,
|
|
91
|
-
filter?: (V, K, ObjMap<V, K>) => boolean = (v) => v != null,
|
|
92
|
-
): ObjMap<V, K> =>
|
|
93
|
-
entries(obj).reduce(
|
|
94
|
-
(acc, [k, v]) =>
|
|
95
|
-
filter(v, k, obj || {})
|
|
96
|
-
? Object.assign(acc, {
|
|
97
|
-
[k]: v,
|
|
98
|
-
})
|
|
99
|
-
: acc,
|
|
100
|
-
{},
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Given an object, removes any top level keys with a nullish value.
|
|
105
|
-
* The type system should preserve the incoming object type, with all such keys typed as `empty`.
|
|
106
|
-
* @param {Object} obj the input object
|
|
107
|
-
* @returns {Object} a new object, a subset of the input
|
|
108
|
-
*/
|
|
109
|
-
export const filterNullish = <T: { ... }>(
|
|
110
|
-
obj: T,
|
|
111
|
-
): $ObjMap<T, <V>(V) => $NonMaybeType<V>> => filterKeys(obj);
|
package/npm.js.flow
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { platform } from 'os';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs-extra';
|
|
5
|
-
|
|
6
|
-
import { spawn, exec } from './cp';
|
|
7
|
-
import { getCfg, getPkgName } from './pkg';
|
|
8
|
-
import { getVersion, getDevBranch } from './version';
|
|
9
|
-
import { buildLog } from './run';
|
|
10
|
-
|
|
11
|
-
export type NpmCreds = {
|
|
12
|
-
username: string,
|
|
13
|
-
password: string,
|
|
14
|
-
email: string,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type NpmConfig = {
|
|
18
|
-
publish: boolean,
|
|
19
|
-
registry?: string,
|
|
20
|
-
access?: 'public' | 'restricted',
|
|
21
|
-
dryRun?: boolean,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export function getNpmConfig(): NpmConfig {
|
|
25
|
-
return getCfg().npm || {};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const envNpmCreds: ?NpmCreds =
|
|
29
|
-
(process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
|
|
30
|
-
|
|
31
|
-
const npmExe = (npmPath?: string) =>
|
|
32
|
-
npmPath || (platform() === 'win32' ? 'npm.cmd' : 'npm');
|
|
33
|
-
|
|
34
|
-
export async function npmExec(
|
|
35
|
-
args: string[],
|
|
36
|
-
npmPath?: string,
|
|
37
|
-
): Promise<string> {
|
|
38
|
-
return (await exec(`${npmExe(npmPath)} ${args.join(' ')}`)).stdout.toString();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function npmGetVersions(
|
|
42
|
-
packageName: string,
|
|
43
|
-
npmPath?: string,
|
|
44
|
-
): Promise<string[]> {
|
|
45
|
-
try {
|
|
46
|
-
return JSON.parse(
|
|
47
|
-
await npmExec(['show', packageName, 'versions'], npmPath),
|
|
48
|
-
);
|
|
49
|
-
} catch (err) {
|
|
50
|
-
buildLog(
|
|
51
|
-
`warning: failed to find existing package for ${packageName} in npm registry: ${err.message}`,
|
|
52
|
-
);
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type NpmPublishOptions = {|
|
|
58
|
-
publishPath: string, // distDir, or package.tgz file
|
|
59
|
-
npmConfig?: NpmConfig,
|
|
60
|
-
npmCreds?: NpmCreds,
|
|
61
|
-
npmAuthToken?: string,
|
|
62
|
-
tag?: string,
|
|
63
|
-
skipExisting?: boolean,
|
|
64
|
-
npmPath?: string, // path to executable
|
|
65
|
-
|};
|
|
66
|
-
|
|
67
|
-
export async function npmPublish({
|
|
68
|
-
publishPath,
|
|
69
|
-
npmConfig,
|
|
70
|
-
npmCreds,
|
|
71
|
-
npmAuthToken,
|
|
72
|
-
tag,
|
|
73
|
-
skipExisting = false,
|
|
74
|
-
npmPath,
|
|
75
|
-
}: NpmPublishOptions = {}): Promise<boolean> {
|
|
76
|
-
const creds = npmCreds || envNpmCreds;
|
|
77
|
-
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
78
|
-
const name = getPkgName();
|
|
79
|
-
const { publish, registry, access, dryRun } = npmConfig || getNpmConfig();
|
|
80
|
-
if (!publish) {
|
|
81
|
-
buildLog(
|
|
82
|
-
'npm publish info missing from package.json, skipping npm publish',
|
|
83
|
-
);
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
const resolvedPath = path.resolve(publishPath);
|
|
87
|
-
const workDir = (await fs.stat(resolvedPath)).isDirectory()
|
|
88
|
-
? resolvedPath
|
|
89
|
-
: path.dirname(resolvedPath);
|
|
90
|
-
if (creds || registry || authToken) {
|
|
91
|
-
// Write out .npmrc with credentials
|
|
92
|
-
const theRegistry = registry || 'https://registry.npmjs.org/';
|
|
93
|
-
const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
|
|
94
|
-
await fs.mkdirp(workDir);
|
|
95
|
-
await fs.writeFile(
|
|
96
|
-
path.join(workDir, '.npmrc'),
|
|
97
|
-
`registry=${theRegistry}
|
|
98
|
-
${authToken ? `//${host}:_authToken=${authToken}` : ''}
|
|
99
|
-
${
|
|
100
|
-
creds
|
|
101
|
-
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString(
|
|
102
|
-
'base64',
|
|
103
|
-
)}
|
|
104
|
-
always-auth=true
|
|
105
|
-
email=${creds.email}`
|
|
106
|
-
: ''
|
|
107
|
-
}`,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
const existing = await npmGetVersions(name, npmPath);
|
|
111
|
-
const { isRelease, npm: npmVersion, branch } = await getVersion();
|
|
112
|
-
if (existing.includes(npmVersion)) {
|
|
113
|
-
if (skipExisting) {
|
|
114
|
-
buildLog(
|
|
115
|
-
'npm package with this same version already exists. Skipping publish...',
|
|
116
|
-
);
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
throw new Error(
|
|
120
|
-
'Failed to publish npm package, this version already exists!',
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
await spawn(
|
|
124
|
-
npmExe(npmPath),
|
|
125
|
-
[
|
|
126
|
-
'publish',
|
|
127
|
-
resolvedPath,
|
|
128
|
-
'--tag',
|
|
129
|
-
tag ||
|
|
130
|
-
(isRelease
|
|
131
|
-
? 'latest'
|
|
132
|
-
: branch === (await getDevBranch())
|
|
133
|
-
? 'next'
|
|
134
|
-
: 'branch'),
|
|
135
|
-
...(access ? ['--access', access] : []),
|
|
136
|
-
...(dryRun ? ['--dry-run'] : []),
|
|
137
|
-
],
|
|
138
|
-
{
|
|
139
|
-
stdio: 'inherit',
|
|
140
|
-
cwd: workDir,
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
package/pkg.js.flow
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type { ArtifactoryConfig } from './artifactory';
|
|
3
|
-
import type { CertConfig } from './cert';
|
|
4
|
-
import type { DockerConfig } from './docker';
|
|
5
|
-
import type { NpmConfig } from './npm';
|
|
6
|
-
|
|
7
|
-
export type BuildStrapConfig = {
|
|
8
|
-
repoType?: 'git' | 'hg',
|
|
9
|
-
copyright?: string,
|
|
10
|
-
releaseBranch?: string,
|
|
11
|
-
devBranch?: string,
|
|
12
|
-
artifactory?: ArtifactoryConfig,
|
|
13
|
-
cert?: CertConfig,
|
|
14
|
-
docker?: DockerConfig,
|
|
15
|
-
npm?: NpmConfig,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type StringMap = {
|
|
19
|
-
[string]: string,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export type PackageJson = {
|
|
23
|
-
name: string,
|
|
24
|
-
version: string,
|
|
25
|
-
description?: string,
|
|
26
|
-
private?: boolean,
|
|
27
|
-
license?: string,
|
|
28
|
-
authors?: string[],
|
|
29
|
-
repository?: string,
|
|
30
|
-
main?: string,
|
|
31
|
-
dependencies?: StringMap,
|
|
32
|
-
devDependencies?: StringMap,
|
|
33
|
-
peerDependencies?: StringMap,
|
|
34
|
-
engines?: StringMap,
|
|
35
|
-
scripts?: StringMap,
|
|
36
|
-
// our addition
|
|
37
|
-
buildStrap: BuildStrapConfig,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
let _pkg: ?PackageJson = null;
|
|
41
|
-
export function getPkg(): PackageJson {
|
|
42
|
-
if (_pkg == null) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
'Must call setPkg() with package.json content before building.',
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return _pkg;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getCfg(): BuildStrapConfig {
|
|
51
|
-
return getPkg().buildStrap || {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function setPkg(p: PackageJson) {
|
|
55
|
-
_pkg = p;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const pkgNameRegex = /^(?:(@[^/]+)\/)?(.+)$/i;
|
|
59
|
-
|
|
60
|
-
export function getPkgName(includeScope: boolean = false): string {
|
|
61
|
-
const pkg = getPkg();
|
|
62
|
-
if (!(pkg.name && pkg.name.length)) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'Package name not found in package.json, but this is a required property!',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
if (includeScope) {
|
|
68
|
-
return pkg.name;
|
|
69
|
-
}
|
|
70
|
-
const [, , shortName] = pkg.name.match(pkgNameRegex) || [];
|
|
71
|
-
if (!shortName) {
|
|
72
|
-
throw new Error('Package name in package.json has invalid format.');
|
|
73
|
-
}
|
|
74
|
-
return shortName;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function getPkgScope(): ?string {
|
|
78
|
-
const pkgName = getPkgName(true);
|
|
79
|
-
return pkgName.match(pkgNameRegex)?.[1] || null;
|
|
80
|
-
}
|
package/publish.js.flow
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import { run, buildLog } from './run';
|
|
5
|
-
import { getVersion, type Version } from './version';
|
|
6
|
-
import { getPkgName } from './pkg';
|
|
7
|
-
import {
|
|
8
|
-
artifactoryNpm,
|
|
9
|
-
artifactoryStandard,
|
|
10
|
-
type ArtifactoryConfig,
|
|
11
|
-
type ArtifactoryCreds,
|
|
12
|
-
} from './artifactory';
|
|
13
|
-
import { npmPublish } from './npm';
|
|
14
|
-
import type { NpmConfig, NpmCreds } from './npm';
|
|
15
|
-
import { tgzDir, type ArtifactInfo } from './tgz';
|
|
16
|
-
|
|
17
|
-
export type CreateArtifactOptions = {
|
|
18
|
-
distDir: string, // What to bundle up and publish
|
|
19
|
-
outDir: string, // Where the bundled tgz file should go
|
|
20
|
-
fileName?: string, // (optional) Specify the tgz file name
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type Artifact = {
|
|
24
|
-
name: string,
|
|
25
|
-
version: Version,
|
|
26
|
-
info: ArtifactInfo,
|
|
27
|
-
fileName: string,
|
|
28
|
-
filePath: string,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// create tgz from distDir in outDir
|
|
32
|
-
export async function createArtifact({
|
|
33
|
-
distDir,
|
|
34
|
-
outDir,
|
|
35
|
-
fileName,
|
|
36
|
-
}: CreateArtifactOptions): Promise<Artifact> {
|
|
37
|
-
const version = await getVersion();
|
|
38
|
-
const name = getPkgName();
|
|
39
|
-
|
|
40
|
-
buildLog(`gzipping ${name} v${version.info}...`);
|
|
41
|
-
|
|
42
|
-
const tgzFileName = fileName || `${name}-${version.info}.tgz`;
|
|
43
|
-
const tgzFilePath = path.join(outDir, tgzFileName);
|
|
44
|
-
const info = await tgzDir(distDir, tgzFilePath, {
|
|
45
|
-
prefix: 'package',
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
buildLog(`md5: ${info.md5}`);
|
|
49
|
-
buildLog(`sha1: ${info.sha1}`);
|
|
50
|
-
buildLog(`sha512: ${info.sha512}`);
|
|
51
|
-
buildLog(`size: ${info.size} bytes`);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
name,
|
|
55
|
-
version,
|
|
56
|
-
info,
|
|
57
|
-
fileName: tgzFileName,
|
|
58
|
-
filePath: tgzFilePath,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export type PublishConfiguration = {
|
|
63
|
-
...CreateArtifactOptions,
|
|
64
|
-
doPublish: boolean, // Actually publish?
|
|
65
|
-
prePublishFn?: () => any, // (optional) Callback to invoke before publishing
|
|
66
|
-
artifactoryConfig?: ArtifactoryConfig, // (optional) Artifactory config info (normally in package.json)
|
|
67
|
-
artifactoryCreds?: ArtifactoryCreds, // (optional) Artifactory credentials (normally from ENV var)
|
|
68
|
-
npmPath?: string, // (optional) Path to npm executable
|
|
69
|
-
npmTag?: string, // (optional) tag to apply to npm package
|
|
70
|
-
npmSkipExisting?: boolean, // (optional) if true, don't error when artifact already exists (skip publish)
|
|
71
|
-
npmConfig?: NpmConfig, // (optional) Npm config info (normally in package.json)
|
|
72
|
-
npmCreds?: NpmCreds, // (optional) Npm credentials (normally from ENV var)
|
|
73
|
-
npmAuthToken?: string, // (optional) Npm auth token (normally from ENV var)
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// tgz the distDir, and copy it to the outDir
|
|
77
|
-
// if toArtifactory is true, also publishes to artifactory
|
|
78
|
-
export async function publish({
|
|
79
|
-
distDir,
|
|
80
|
-
outDir,
|
|
81
|
-
doPublish,
|
|
82
|
-
prePublishFn,
|
|
83
|
-
fileName,
|
|
84
|
-
artifactoryConfig,
|
|
85
|
-
artifactoryCreds,
|
|
86
|
-
npmPath,
|
|
87
|
-
npmTag,
|
|
88
|
-
npmSkipExisting = false,
|
|
89
|
-
npmConfig,
|
|
90
|
-
npmCreds,
|
|
91
|
-
npmAuthToken,
|
|
92
|
-
}: PublishConfiguration) {
|
|
93
|
-
if (typeof prePublishFn === 'function') {
|
|
94
|
-
await run(async () => {
|
|
95
|
-
await prePublishFn();
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const {
|
|
100
|
-
info,
|
|
101
|
-
filePath: tgzFilePath,
|
|
102
|
-
fileName: tgzFileName,
|
|
103
|
-
} = await createArtifact({ distDir, outDir, fileName });
|
|
104
|
-
|
|
105
|
-
if (!doPublish) {
|
|
106
|
-
buildLog(
|
|
107
|
-
'Skipping publish for dev build. Use `--publish` arg to publish for real.',
|
|
108
|
-
);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Publish to all repos configured in package.json
|
|
113
|
-
await fs.copyFile(
|
|
114
|
-
path.join(distDir, 'package.json'),
|
|
115
|
-
path.join(outDir, 'package.json'),
|
|
116
|
-
);
|
|
117
|
-
const artifact = fs.createReadStream(tgzFilePath);
|
|
118
|
-
await Promise.all([
|
|
119
|
-
npmPublish({
|
|
120
|
-
publishPath: tgzFilePath,
|
|
121
|
-
npmConfig,
|
|
122
|
-
npmCreds,
|
|
123
|
-
npmAuthToken,
|
|
124
|
-
tag: npmTag,
|
|
125
|
-
skipExisting: npmSkipExisting,
|
|
126
|
-
npmPath,
|
|
127
|
-
}),
|
|
128
|
-
artifactoryStandard(
|
|
129
|
-
artifact,
|
|
130
|
-
info,
|
|
131
|
-
tgzFileName,
|
|
132
|
-
artifactoryConfig,
|
|
133
|
-
artifactoryCreds,
|
|
134
|
-
),
|
|
135
|
-
artifactoryNpm(
|
|
136
|
-
distDir,
|
|
137
|
-
artifactoryConfig,
|
|
138
|
-
artifactoryCreds,
|
|
139
|
-
npmPath,
|
|
140
|
-
npmTag,
|
|
141
|
-
npmSkipExisting,
|
|
142
|
-
),
|
|
143
|
-
]);
|
|
144
|
-
}
|
package/run.js.flow
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
export function format(time?: Date = new Date()): string {
|
|
3
|
-
return time.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, '$1');
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const silenceLogs = process.argv.includes('--silence-buildLog');
|
|
7
|
-
|
|
8
|
-
export function buildLog(msg: string, time?: Date) {
|
|
9
|
-
if (silenceLogs) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
console.info(`[${format(time || new Date())}] ${msg}`);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type RunnableModule<T> =
|
|
16
|
-
| (() => Promise<T>)
|
|
17
|
-
| { default: () => Promise<T> };
|
|
18
|
-
|
|
19
|
-
export async function run<T>(
|
|
20
|
-
fn: RunnableModule<T>,
|
|
21
|
-
...options: any[]
|
|
22
|
-
): Promise<T> {
|
|
23
|
-
if (fn == null) {
|
|
24
|
-
throw new Error(`Invalid argument passed to run(${fn})`);
|
|
25
|
-
}
|
|
26
|
-
const task = typeof fn === 'function' ? fn : fn.default;
|
|
27
|
-
if (typeof task !== 'function') {
|
|
28
|
-
throw new Error(
|
|
29
|
-
'First argument to run must be a function or module with default function.',
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
const start = new Date();
|
|
33
|
-
buildLog(`Starting '${task.name}'...`, start);
|
|
34
|
-
const result = await task(...options);
|
|
35
|
-
const end = new Date();
|
|
36
|
-
const time = end.getTime() - start.getTime();
|
|
37
|
-
buildLog(`Finished '${task.name}' after ${time} ms`, end);
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type RunCliOptions<T> = {
|
|
42
|
-
resolveFn?: (path: string) => RunnableModule<T>,
|
|
43
|
-
defaultAction?: string | RunnableModule<T>,
|
|
44
|
-
argv?: string[],
|
|
45
|
-
passthroughArgv?: boolean,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export async function runCli<T>({
|
|
49
|
-
resolveFn = (path: string) =>
|
|
50
|
-
// $FlowFixMe
|
|
51
|
-
require(`./${path}`).default, // eslint-disable-line
|
|
52
|
-
defaultAction = 'publish',
|
|
53
|
-
argv = process.argv,
|
|
54
|
-
passthroughArgv = false,
|
|
55
|
-
}: RunCliOptions<T> = {}): Promise<T> {
|
|
56
|
-
const module =
|
|
57
|
-
argv.length > 2
|
|
58
|
-
? resolveFn(argv[2])
|
|
59
|
-
: typeof defaultAction === 'string'
|
|
60
|
-
? resolveFn(defaultAction)
|
|
61
|
-
: defaultAction;
|
|
62
|
-
const args = Array.isArray(passthroughArgv)
|
|
63
|
-
? passthroughArgv.includes(argv[2] || defaultAction)
|
|
64
|
-
? argv.slice(3)
|
|
65
|
-
: []
|
|
66
|
-
: passthroughArgv
|
|
67
|
-
? argv.slice(3)
|
|
68
|
-
: [];
|
|
69
|
-
return run(module, ...args).catch((err) => {
|
|
70
|
-
console.error((err && err.stack) || err);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
throw err;
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function handleEntryPoint<T>(
|
|
77
|
-
mainModule: typeof module,
|
|
78
|
-
mainModuleFilename: string,
|
|
79
|
-
cliOptions?: RunCliOptions<T>,
|
|
80
|
-
) {
|
|
81
|
-
if (require.main === mainModule) {
|
|
82
|
-
delete require.cache[mainModuleFilename]; // eslint-disable-line no-underscore-dangle
|
|
83
|
-
runCli(cliOptions);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
handleEntryPoint(module, __filename);
|
|
88
|
-
|
|
89
|
-
export default run;
|
package/src/ant.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { spawn } from './cp';
|
|
3
|
-
import type { SpawnOptions } from './cp';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Named value pair to use when configuring an Ant build property
|
|
7
|
-
*/
|
|
8
|
-
export type AntPropertyConfiguration = {|
|
|
9
|
-
name: string,
|
|
10
|
-
value: string,
|
|
11
|
-
|};
|
|
12
|
-
|
|
13
|
-
export type AntSpawnOptions = {|
|
|
14
|
-
properties?: AntPropertyConfiguration[], // Ant property values to configure
|
|
15
|
-
args?: string[], // Any additional command line arguments to pass
|
|
16
|
-
spawnOptions?: SpawnOptions, // Optional spawn configuration. Defaults to run the project root directory
|
|
17
|
-
|};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Executes the given ant command
|
|
21
|
-
* @param {string} target the ant target to invoke
|
|
22
|
-
* @param {AntSpawnOptions} options
|
|
23
|
-
*/
|
|
24
|
-
export async function ant(target: string, opts?: AntSpawnOptions) {
|
|
25
|
-
const { properties = [], args = [], spawnOptions } = opts || {};
|
|
26
|
-
|
|
27
|
-
const execOptions = {
|
|
28
|
-
stdio: 'inherit',
|
|
29
|
-
pipeOutput: true,
|
|
30
|
-
...spawnOptions,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
await spawn(
|
|
34
|
-
'ant',
|
|
35
|
-
[
|
|
36
|
-
target,
|
|
37
|
-
...args,
|
|
38
|
-
...properties.map(({ name, value }) => `-D${name}=${value}`),
|
|
39
|
-
],
|
|
40
|
-
execOptions,
|
|
41
|
-
);
|
|
42
|
-
}
|