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/npm.js
CHANGED
|
@@ -1,144 +1,141 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
2
|
import { platform } from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
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 || {};
|
|
4
|
+
import { spawn } from './cp.js';
|
|
5
|
+
import { getCfg, getPkgName } from './pkg.js';
|
|
6
|
+
import { buildLog } from './run.js';
|
|
7
|
+
import { getDevBranch, getVersion } from './version.js';
|
|
8
|
+
export function getNpmConfig() {
|
|
9
|
+
return getCfg().npm || {};
|
|
26
10
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
export const envNpmCreds = (process.env.NPM_CREDS && JSON.parse(process.env.NPM_CREDS)) || null;
|
|
12
|
+
const npmExe = (npmPath) => npmPath || (platform() === 'win32' ? 'npm.cmd' : 'npm');
|
|
13
|
+
export async function npm({ args = [], spawnOptions, npmPath, } = {}) {
|
|
14
|
+
const localNpm = path.join(path.dirname(process.execPath), 'lib/node_modules/npm/bin/npm-cli.js');
|
|
15
|
+
const spawnOpts = {
|
|
16
|
+
env: process.env,
|
|
17
|
+
shell: true,
|
|
18
|
+
stdio: 'inherit',
|
|
19
|
+
...spawnOptions,
|
|
20
|
+
};
|
|
21
|
+
return npmPath
|
|
22
|
+
? spawn(npmPath, args, spawnOpts)
|
|
23
|
+
: (await fs.pathExists(localNpm))
|
|
24
|
+
? // prefer to use local copy of npm
|
|
25
|
+
spawn(process.execPath, [localNpm, ...args], spawnOpts)
|
|
26
|
+
: // fall back to globally installed npm
|
|
27
|
+
spawn(npmExe(), args, spawnOpts);
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
export async function npmGetVersions(packageName, npmPath) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse((await npm({
|
|
32
|
+
args: ['show', packageName, 'versions', '--json'],
|
|
33
|
+
npmPath,
|
|
34
|
+
spawnOptions: {
|
|
35
|
+
captureOutput: true,
|
|
36
|
+
stdio: 'pipe',
|
|
37
|
+
},
|
|
38
|
+
})).stdout.trim());
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
buildLog(`warning: failed to find existing package for ${packageName} in npm registry: ${err.message}`);
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
55
44
|
}
|
|
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) {
|
|
45
|
+
export async function npmWriteRc({ authToken, creds, outPath, registry, }) {
|
|
91
46
|
// Write out .npmrc with credentials
|
|
92
47
|
const theRegistry = registry || 'https://registry.npmjs.org/';
|
|
93
48
|
const [, host] = /^(?:http(?:s)?:\/\/)?(.+)$/.exec(theRegistry) || [];
|
|
94
|
-
await fs.mkdirp(
|
|
95
|
-
await fs.writeFile(
|
|
96
|
-
path.join(workDir, '.npmrc'),
|
|
97
|
-
`registry=${theRegistry}
|
|
49
|
+
await fs.mkdirp(path.dirname(outPath));
|
|
50
|
+
await fs.writeFile(outPath, `registry=${theRegistry}
|
|
98
51
|
${authToken ? `//${host}:_authToken=${authToken}` : ''}
|
|
99
|
-
${
|
|
100
|
-
|
|
101
|
-
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString(
|
|
102
|
-
'base64',
|
|
103
|
-
)}
|
|
52
|
+
${creds
|
|
53
|
+
? `_auth=${Buffer.from(`${creds.username}:${creds.password}`).toString('base64')}
|
|
104
54
|
always-auth=true
|
|
105
55
|
email=${creds.email}`
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
56
|
+
: ''}`);
|
|
57
|
+
}
|
|
58
|
+
export async function npmPublish({ npmAuthToken, npmConfig, npmCreds, npmPath, publishPath = '.', skipExisting = false, tag, workDir: passedWorkDir, } = {}) {
|
|
59
|
+
const creds = npmCreds || envNpmCreds;
|
|
60
|
+
const authToken = npmAuthToken || process.env.NPM_TOKEN;
|
|
61
|
+
const name = getPkgName();
|
|
62
|
+
const { access, dryRun, publish, registry } = npmConfig || getNpmConfig();
|
|
63
|
+
if (!publish) {
|
|
64
|
+
buildLog('npm publish info missing from package.json, skipping npm publish');
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const resolvedPath = path.resolve(publishPath);
|
|
68
|
+
const workDir = passedWorkDir ||
|
|
69
|
+
((await fs.stat(resolvedPath)).isDirectory()
|
|
70
|
+
? resolvedPath
|
|
71
|
+
: path.dirname(resolvedPath));
|
|
72
|
+
if (!(await fs.pathExists(path.join(workDir, 'package.json')))) {
|
|
73
|
+
buildLog(`warning: no package.json found in ${workDir}, skipping npm publish`);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
if (creds || registry || authToken) {
|
|
77
|
+
// Write out .npmrc with credentials
|
|
78
|
+
await npmWriteRc({
|
|
79
|
+
authToken: authToken ? `\${NPM_TOKEN}` : undefined,
|
|
80
|
+
creds,
|
|
81
|
+
outPath: path.join(workDir, '.npmrc'),
|
|
82
|
+
registry,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const existing = await npmGetVersions(name, npmPath);
|
|
86
|
+
const { branch, isRelease, npm: npmVersion } = await getVersion();
|
|
87
|
+
if (existing.includes(npmVersion)) {
|
|
88
|
+
if (skipExisting) {
|
|
89
|
+
buildLog('npm package with this same version already exists. Skipping publish...');
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
throw new Error('Failed to publish npm package, this version already exists!');
|
|
93
|
+
}
|
|
94
|
+
await npm({
|
|
95
|
+
args: [
|
|
96
|
+
'publish',
|
|
97
|
+
resolvedPath,
|
|
98
|
+
'--tag',
|
|
99
|
+
tag ||
|
|
100
|
+
(isRelease
|
|
101
|
+
? 'latest'
|
|
102
|
+
: branch === (await getDevBranch())
|
|
103
|
+
? 'next'
|
|
104
|
+
: 'branch'),
|
|
105
|
+
...(access ? ['--access', access] : []),
|
|
106
|
+
...(dryRun ? ['--dry-run'] : []),
|
|
107
|
+
'--color=always',
|
|
108
|
+
],
|
|
109
|
+
npmPath,
|
|
110
|
+
spawnOptions: {
|
|
111
|
+
cwd: workDir,
|
|
112
|
+
env: {
|
|
113
|
+
...process.env,
|
|
114
|
+
NPM_TOKEN: authToken,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
export async function npmPack({ destination, npmConfig, npmPath, workDir = '.', }) {
|
|
121
|
+
const { dryRun } = npmConfig || getNpmConfig();
|
|
122
|
+
if (destination) {
|
|
123
|
+
await fs.ensureDir(destination);
|
|
118
124
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
...(access ? ['--access', access] : []),
|
|
136
|
-
...(dryRun ? ['--dry-run'] : []),
|
|
137
|
-
],
|
|
138
|
-
{
|
|
139
|
-
stdio: 'inherit',
|
|
140
|
-
cwd: workDir,
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
return true;
|
|
125
|
+
const { stdout } = await npm({
|
|
126
|
+
args: [
|
|
127
|
+
'pack',
|
|
128
|
+
...(dryRun ? ['--dry-run'] : []),
|
|
129
|
+
...(destination ? ['--pack-destination', path.resolve(destination)] : []),
|
|
130
|
+
'--color=always',
|
|
131
|
+
],
|
|
132
|
+
npmPath,
|
|
133
|
+
spawnOptions: {
|
|
134
|
+
captureOutput: true,
|
|
135
|
+
cwd: path.resolve(workDir),
|
|
136
|
+
pipeOutput: true,
|
|
137
|
+
stdio: 'pipe',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
return path.resolve(destination || '.', stdout.trim());
|
|
144
141
|
}
|
package/src/pkg.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CertConfig } from './cert.js';
|
|
2
|
+
import { DockerConfig } from './docker.js';
|
|
3
|
+
import { NpmConfig } from './npm.js';
|
|
4
|
+
export interface BuildStrapConfig {
|
|
5
|
+
cert?: CertConfig;
|
|
6
|
+
copyright?: string;
|
|
7
|
+
devBranch?: string;
|
|
8
|
+
docker?: DockerConfig;
|
|
9
|
+
npm?: NpmConfig;
|
|
10
|
+
releaseBranch?: string;
|
|
11
|
+
repoType?: 'git' | 'hg';
|
|
12
|
+
}
|
|
13
|
+
export interface PackageJson {
|
|
14
|
+
authors?: string[];
|
|
15
|
+
buildStrap: BuildStrapConfig;
|
|
16
|
+
dependencies?: Record<string, string>;
|
|
17
|
+
description?: string;
|
|
18
|
+
devDependencies?: Record<string, string>;
|
|
19
|
+
engines?: Record<string, string>;
|
|
20
|
+
license?: string;
|
|
21
|
+
main?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
peerDependencies?: Record<string, string>;
|
|
24
|
+
private?: boolean;
|
|
25
|
+
repository?: string | {
|
|
26
|
+
type: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
scripts?: Record<string, string>;
|
|
30
|
+
type?: string;
|
|
31
|
+
types?: string;
|
|
32
|
+
version: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function getPkg(): PackageJson;
|
|
35
|
+
export declare function getCfg(): BuildStrapConfig;
|
|
36
|
+
export declare function setPkg(p: PackageJson): void;
|
|
37
|
+
export declare function getPkgName(includeScope?: boolean): string;
|
|
38
|
+
export declare function getPkgScope(): null | string;
|
package/src/pkg.js
CHANGED
|
@@ -1,80 +1,33 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
1
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
2
|
+
let _pkg = null;
|
|
3
|
+
export function getPkg() {
|
|
4
|
+
if (_pkg == null) {
|
|
5
|
+
throw new Error('Must call setPkg() with package.json content before building.');
|
|
6
|
+
}
|
|
7
|
+
return _pkg;
|
|
48
8
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return getPkg().buildStrap || {};
|
|
9
|
+
export function getCfg() {
|
|
10
|
+
return getPkg().buildStrap || {};
|
|
52
11
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
_pkg = p;
|
|
12
|
+
export function setPkg(p) {
|
|
13
|
+
_pkg = p;
|
|
56
14
|
}
|
|
57
|
-
|
|
58
15
|
const pkgNameRegex = /^(?:(@[^/]+)\/)?(.+)$/i;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw new Error('Package name in package.json has invalid format.');
|
|
73
|
-
}
|
|
74
|
-
return shortName;
|
|
16
|
+
export function getPkgName(includeScope = false) {
|
|
17
|
+
const pkg = getPkg();
|
|
18
|
+
if (!(pkg.name && pkg.name.length)) {
|
|
19
|
+
throw new Error('Package name not found in package.json, but this is a required property!');
|
|
20
|
+
}
|
|
21
|
+
if (includeScope) {
|
|
22
|
+
return pkg.name;
|
|
23
|
+
}
|
|
24
|
+
const [, , shortName] = pkg.name.match(pkgNameRegex) || [];
|
|
25
|
+
if (!shortName) {
|
|
26
|
+
throw new Error('Package name in package.json has invalid format.');
|
|
27
|
+
}
|
|
28
|
+
return shortName;
|
|
75
29
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return pkgName.match(pkgNameRegex)?.[1] || null;
|
|
30
|
+
export function getPkgScope() {
|
|
31
|
+
const pkgName = getPkgName(true);
|
|
32
|
+
return pkgName.match(pkgNameRegex)?.[1] || null;
|
|
80
33
|
}
|
package/src/publish.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NpmConfig, NpmCreds } from './npm.js';
|
|
2
|
+
import { ArtifactInfo } from './tgz.js';
|
|
3
|
+
import { type Version } from './version.js';
|
|
4
|
+
export interface CreateArtifactOptions {
|
|
5
|
+
distDir: string;
|
|
6
|
+
fileName?: string;
|
|
7
|
+
outDir: string;
|
|
8
|
+
}
|
|
9
|
+
export interface Artifact {
|
|
10
|
+
fileName: string;
|
|
11
|
+
filePath: string;
|
|
12
|
+
info: ArtifactInfo;
|
|
13
|
+
name: string;
|
|
14
|
+
version: Version;
|
|
15
|
+
}
|
|
16
|
+
export declare function createArtifact({ distDir, fileName, outDir, }: CreateArtifactOptions): Promise<Artifact>;
|
|
17
|
+
export interface PublishConfiguration extends CreateArtifactOptions {
|
|
18
|
+
doPublish: boolean;
|
|
19
|
+
npmAuthToken?: string;
|
|
20
|
+
npmConfig?: NpmConfig;
|
|
21
|
+
npmCreds?: NpmCreds;
|
|
22
|
+
npmPath?: string;
|
|
23
|
+
npmSkipExisting?: boolean;
|
|
24
|
+
npmTag?: string;
|
|
25
|
+
prePublishFn?: () => any;
|
|
26
|
+
}
|
|
27
|
+
export declare function publish({ distDir, doPublish, fileName, npmAuthToken, npmConfig, npmCreds, npmPath, npmSkipExisting, npmTag, outDir, prePublishFn, }: PublishConfiguration): Promise<void>;
|
package/src/publish.js
CHANGED
|
@@ -1,144 +1,57 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import path from 'path';
|
|
3
1
|
import fs from 'fs-extra';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { getPkgName } from './pkg';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { npmPublish } from './npm.js';
|
|
4
|
+
import { getPkgName } from './pkg.js';
|
|
5
|
+
import { buildLog, run } from './run.js';
|
|
6
|
+
import { tgzDir } from './tgz.js';
|
|
7
|
+
import { getVersion } from './version.js';
|
|
31
8
|
// create tgz from distDir in outDir
|
|
32
|
-
export async function createArtifact({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
name,
|
|
55
|
-
version,
|
|
56
|
-
info,
|
|
57
|
-
fileName: tgzFileName,
|
|
58
|
-
filePath: tgzFilePath,
|
|
59
|
-
};
|
|
9
|
+
export async function createArtifact({ distDir, fileName, outDir, }) {
|
|
10
|
+
const version = await getVersion();
|
|
11
|
+
const name = getPkgName();
|
|
12
|
+
buildLog(`gzipping ${name} v${version.info}...`);
|
|
13
|
+
const tgzFileName = fileName || `${name}-${version.info}.tgz`;
|
|
14
|
+
const tgzFilePath = path.join(outDir, tgzFileName);
|
|
15
|
+
const info = await tgzDir(distDir, tgzFilePath, {
|
|
16
|
+
prefix: 'package',
|
|
17
|
+
});
|
|
18
|
+
buildLog(`md5: ${info.md5}`);
|
|
19
|
+
buildLog(`sha1: ${info.sha1}`);
|
|
20
|
+
buildLog(`sha512: ${info.sha512}`);
|
|
21
|
+
buildLog(`size: ${info.size} bytes`);
|
|
22
|
+
return {
|
|
23
|
+
fileName: tgzFileName,
|
|
24
|
+
filePath: tgzFilePath,
|
|
25
|
+
info,
|
|
26
|
+
name,
|
|
27
|
+
version,
|
|
28
|
+
};
|
|
60
29
|
}
|
|
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
30
|
// tgz the distDir, and copy it to the outDir
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
await
|
|
95
|
-
|
|
31
|
+
export async function publish({ distDir, doPublish, fileName, npmAuthToken, npmConfig, npmCreds, npmPath, npmSkipExisting = false, npmTag, outDir, prePublishFn, }) {
|
|
32
|
+
if (typeof prePublishFn === 'function') {
|
|
33
|
+
await run(async () => {
|
|
34
|
+
await prePublishFn();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const { filePath: tgzFilePath } = await createArtifact({
|
|
38
|
+
distDir,
|
|
39
|
+
fileName,
|
|
40
|
+
outDir,
|
|
41
|
+
});
|
|
42
|
+
if (!doPublish) {
|
|
43
|
+
buildLog('Skipping publish for dev build. Use `--publish` arg to publish for real.');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// Publish to all repos configured in package.json
|
|
47
|
+
await fs.copyFile(path.join(distDir, 'package.json'), path.join(outDir, 'package.json'));
|
|
48
|
+
await npmPublish({
|
|
49
|
+
npmAuthToken,
|
|
50
|
+
npmConfig,
|
|
51
|
+
npmCreds,
|
|
52
|
+
npmPath,
|
|
53
|
+
publishPath: tgzFilePath,
|
|
54
|
+
skipExisting: npmSkipExisting,
|
|
55
|
+
tag: npmTag,
|
|
96
56
|
});
|
|
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
57
|
}
|
package/src/run.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function format(time?: Date): string;
|
|
2
|
+
export declare function buildLog(msg: string, time?: Date): void;
|
|
3
|
+
export declare type RunnableModule<Args extends string[], Result> = ((...args: Args) => Promise<Result>) | {
|
|
4
|
+
default: (...args: Args) => Promise<Result>;
|
|
5
|
+
};
|
|
6
|
+
export declare function run<Args extends string[], Result>(fn: RunnableModule<Args, Result>, ...options: Args): Promise<Result>;
|
|
7
|
+
export interface RunCliOptions<Args extends string[], Result> {
|
|
8
|
+
argv?: string[];
|
|
9
|
+
defaultAction?: string | RunnableModule<Args, Result>;
|
|
10
|
+
passthroughArgv?: Args | boolean;
|
|
11
|
+
resolveFn?: (path: string) => Promise<RunnableModule<Args, Result>> | RunnableModule<Args, Result>;
|
|
12
|
+
}
|
|
13
|
+
export declare function runCli<Args extends string[], Result>({ resolveFn, defaultAction, argv, passthroughArgv, }?: RunCliOptions<Args, Result>): Promise<Result>;
|