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.
Files changed (107) hide show
  1. package/README.md +3 -34
  2. package/package.json +23 -19
  3. package/src/ant.d.ts +19 -0
  4. package/src/ant.js +12 -36
  5. package/src/cert.d.ts +12 -0
  6. package/src/cert.js +87 -148
  7. package/src/clean.d.ts +4 -0
  8. package/src/clean.js +5 -13
  9. package/src/copy.d.ts +7 -0
  10. package/src/copy.js +48 -74
  11. package/src/cp.d.ts +17 -0
  12. package/src/cp.js +81 -165
  13. package/src/docker.container.d.ts +73 -0
  14. package/src/docker.container.js +208 -350
  15. package/src/docker.d.ts +68 -0
  16. package/src/docker.js +163 -339
  17. package/src/docker.network.d.ts +42 -0
  18. package/src/docker.network.js +67 -141
  19. package/src/docker.volume.d.ts +26 -0
  20. package/src/docker.volume.js +50 -124
  21. package/src/dockerCleanup.d.ts +38 -0
  22. package/src/dockerCleanup.js +62 -136
  23. package/src/dockerCompose.d.ts +154 -0
  24. package/src/dockerCompose.js +390 -716
  25. package/src/fs.d.ts +5 -0
  26. package/src/fs.js +33 -91
  27. package/src/git.d.ts +9 -0
  28. package/src/git.js +19 -29
  29. package/src/index.d.ts +20 -0
  30. package/src/index.js +20 -26
  31. package/src/maps.d.ts +33 -0
  32. package/src/maps.js +12 -82
  33. package/src/npm.d.ts +48 -0
  34. package/src/npm.js +128 -131
  35. package/src/pkg.d.ts +38 -0
  36. package/src/pkg.js +27 -74
  37. package/src/publish.d.ts +27 -0
  38. package/src/publish.js +51 -138
  39. package/src/run.d.ts +13 -0
  40. package/src/run.js +39 -84
  41. package/src/tgz.d.ts +13 -0
  42. package/src/tgz.js +54 -88
  43. package/src/version.d.ts +34 -0
  44. package/src/version.js +85 -126
  45. package/src/yarn.d.ts +44 -0
  46. package/src/yarn.js +147 -115
  47. package/ant.js +0 -43
  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 +0 -153
  53. package/cert.js.flow +0 -152
  54. package/clean.js +0 -20
  55. package/clean.js.flow +0 -19
  56. package/copy.js +0 -80
  57. package/copy.js.flow +0 -79
  58. package/cp.js +0 -173
  59. package/cp.js.flow +0 -172
  60. package/docker.container.js +0 -390
  61. package/docker.container.js.flow +0 -389
  62. package/docker.js +0 -365
  63. package/docker.js.flow +0 -364
  64. package/docker.network.js +0 -160
  65. package/docker.network.js.flow +0 -159
  66. package/docker.volume.js +0 -136
  67. package/docker.volume.js.flow +0 -136
  68. package/dockerCleanup.js +0 -152
  69. package/dockerCleanup.js.flow +0 -151
  70. package/dockerCompose.js +0 -766
  71. package/dockerCompose.js.flow +0 -765
  72. package/flow.js +0 -21
  73. package/flow.js.flow +0 -20
  74. package/fs.js +0 -95
  75. package/fs.js.flow +0 -96
  76. package/git.js +0 -35
  77. package/git.js.flow +0 -34
  78. package/hg.js +0 -35
  79. package/hg.js.flow +0 -34
  80. package/index.js +0 -27
  81. package/index.js.flow +0 -26
  82. package/inline-resources.js +0 -158
  83. package/inline-resources.js.flow +0 -157
  84. package/maps.js +0 -112
  85. package/maps.js.flow +0 -111
  86. package/npm.js +0 -145
  87. package/npm.js.flow +0 -144
  88. package/pkg.js +0 -81
  89. package/pkg.js.flow +0 -80
  90. package/publish.js +0 -145
  91. package/publish.js.flow +0 -144
  92. package/run.js +0 -90
  93. package/run.js.flow +0 -89
  94. package/src/artifactory.js +0 -616
  95. package/src/cert.conf +0 -20
  96. package/src/flow.js +0 -20
  97. package/src/hg.js +0 -34
  98. package/src/inline-resources.js +0 -157
  99. package/src/test.js +0 -55
  100. package/test.js +0 -56
  101. package/test.js.flow +0 -55
  102. package/tgz.js +0 -102
  103. package/tgz.js.flow +0 -101
  104. package/version.js +0 -143
  105. package/version.js.flow +0 -142
  106. package/yarn.js +0 -124
  107. package/yarn.js.flow +0 -123
package/src/npm.js CHANGED
@@ -1,144 +1,141 @@
1
- // @flow
1
+ import fs from 'fs-extra';
2
2
  import { platform } from 'os';
3
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 || {};
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 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();
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
- 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
- }
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(workDir);
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
- creds
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
- 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;
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
- 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;
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
- // @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;
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
- export function getCfg(): BuildStrapConfig {
51
- return getPkg().buildStrap || {};
9
+ export function getCfg() {
10
+ return getPkg().buildStrap || {};
52
11
  }
53
-
54
- export function setPkg(p: PackageJson) {
55
- _pkg = p;
12
+ export function setPkg(p) {
13
+ _pkg = p;
56
14
  }
57
-
58
15
  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;
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
- export function getPkgScope(): ?string {
78
- const pkgName = getPkgName(true);
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
  }
@@ -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 { 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
-
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
- 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
- };
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
- // 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();
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>;