build-strap 3.0.0-dev.40 → 4.0.0-dev.1
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 +35 -0
- package/npm.js +97 -138
- 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 +26 -0
- package/yarn.js +70 -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/src/flow.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { spawn } from './cp';
|
|
3
|
-
|
|
4
|
-
export type FlowOptions = {|
|
|
5
|
-
allBranches?: boolean,
|
|
6
|
-
incremental?: boolean,
|
|
7
|
-
|};
|
|
8
|
-
|
|
9
|
-
// Run the flow linter
|
|
10
|
-
export async function flow(opts?: FlowOptions): Promise<string> {
|
|
11
|
-
const { allBranches = false, incremental = true } = opts || {};
|
|
12
|
-
return spawn(
|
|
13
|
-
'flow',
|
|
14
|
-
[
|
|
15
|
-
incremental ? 'status' : 'check',
|
|
16
|
-
...(allBranches ? ['--show-all-branches'] : []),
|
|
17
|
-
],
|
|
18
|
-
{ stdio: 'inherit', shell: true },
|
|
19
|
-
);
|
|
20
|
-
}
|
package/src/fs.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import glob, { type Options as GlobOptions } from 'glob';
|
|
5
|
-
import rimraf from 'rimraf';
|
|
6
|
-
|
|
7
|
-
export const readFile = async (
|
|
8
|
-
file: string,
|
|
9
|
-
options:
|
|
10
|
-
| string
|
|
11
|
-
| {
|
|
12
|
-
encoding: string,
|
|
13
|
-
flag?: string,
|
|
14
|
-
...
|
|
15
|
-
} = 'utf8',
|
|
16
|
-
): Promise<string> => fs.readFile(file, options);
|
|
17
|
-
|
|
18
|
-
export const writeFile = async (
|
|
19
|
-
file: string,
|
|
20
|
-
data: string | Buffer,
|
|
21
|
-
options?: string | Object,
|
|
22
|
-
): Promise<void> => fs.writeFile(file, data, options);
|
|
23
|
-
|
|
24
|
-
export const renameFile = async (
|
|
25
|
-
source: string,
|
|
26
|
-
target: string,
|
|
27
|
-
): Promise<void> => fs.rename(source, target);
|
|
28
|
-
|
|
29
|
-
export const copyFile = async (source: string, target: string): Promise<void> =>
|
|
30
|
-
fs.copyFile(source, target);
|
|
31
|
-
|
|
32
|
-
export const readDir = async (
|
|
33
|
-
pattern: string,
|
|
34
|
-
options?: Object,
|
|
35
|
-
): Promise<string[]> =>
|
|
36
|
-
new Promise((resolve, reject) =>
|
|
37
|
-
glob(pattern, options || {}, (err, result) =>
|
|
38
|
-
err ? reject(err) : resolve(result),
|
|
39
|
-
),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
export const makeDir = async (name: string): Promise<void> =>
|
|
43
|
-
fs.ensureDir(name);
|
|
44
|
-
|
|
45
|
-
export const moveDir = async (
|
|
46
|
-
source: string,
|
|
47
|
-
target: string,
|
|
48
|
-
): Promise<void> => {
|
|
49
|
-
const dirs = await readDir('**/*.*', {
|
|
50
|
-
cwd: source,
|
|
51
|
-
nosort: true,
|
|
52
|
-
dot: true,
|
|
53
|
-
});
|
|
54
|
-
await Promise.all(
|
|
55
|
-
dirs.map(async (dir) => {
|
|
56
|
-
const from = path.resolve(source, dir);
|
|
57
|
-
const to = path.resolve(target, dir);
|
|
58
|
-
await makeDir(path.dirname(to));
|
|
59
|
-
await renameFile(from, to);
|
|
60
|
-
}),
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const copyDir = async (
|
|
65
|
-
source: string,
|
|
66
|
-
target: string,
|
|
67
|
-
fileGlob: string = '**/*.*',
|
|
68
|
-
globOptions?: ?Object = null,
|
|
69
|
-
renameFn: (name: string) => string = (n) => n,
|
|
70
|
-
): Promise<void> => {
|
|
71
|
-
const paths = await readDir(fileGlob, {
|
|
72
|
-
cwd: source,
|
|
73
|
-
nosort: true,
|
|
74
|
-
nodir: true,
|
|
75
|
-
dot: true,
|
|
76
|
-
...globOptions,
|
|
77
|
-
});
|
|
78
|
-
await Promise.all(
|
|
79
|
-
paths.map(async (p) => {
|
|
80
|
-
const from = path.resolve(source, p);
|
|
81
|
-
const to = path.resolve(target, renameFn(p));
|
|
82
|
-
await makeDir(path.dirname(to));
|
|
83
|
-
await copyFile(from, to);
|
|
84
|
-
}),
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const cleanDir = async (
|
|
89
|
-
pattern: string,
|
|
90
|
-
globOptions?: GlobOptions | boolean,
|
|
91
|
-
): Promise<void> =>
|
|
92
|
-
new Promise((resolve, reject) =>
|
|
93
|
-
rimraf(pattern, { glob: globOptions }, (err) =>
|
|
94
|
-
err ? reject(err) : resolve(),
|
|
95
|
-
),
|
|
96
|
-
);
|
package/src/git.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { exec } from './cp';
|
|
3
|
-
|
|
4
|
-
export async function git(args: string[]): Promise<string> {
|
|
5
|
-
return (await exec(`git ${args.join(' ')}`)).stdout.toString();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export async function gitBranch(): Promise<string> {
|
|
9
|
-
return (await git(['symbolic-ref', '--short', 'HEAD']))
|
|
10
|
-
.replace(/[_+/]/g, '-')
|
|
11
|
-
.trim();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function gitRevId(): Promise<string> {
|
|
15
|
-
return (await git(['rev-parse', '--short=12', 'HEAD']))
|
|
16
|
-
.replace(/[+]/g, '')
|
|
17
|
-
.trim();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type GitInfo = {
|
|
21
|
-
branch: string,
|
|
22
|
-
revision: string,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
let info = null;
|
|
26
|
-
export async function gitInfo(noCache: boolean = false): Promise<GitInfo> {
|
|
27
|
-
if (!info || noCache) {
|
|
28
|
-
info = {
|
|
29
|
-
branch: await gitBranch(),
|
|
30
|
-
revision: await gitRevId(),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return info;
|
|
34
|
-
}
|
package/src/hg.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import { exec } from './cp';
|
|
3
|
-
|
|
4
|
-
export async function hg(args: string[], cwd?: string): Promise<string> {
|
|
5
|
-
// $FlowFixMe
|
|
6
|
-
return (await exec(`hg ${args.join(' ')}`, cwd ? { cwd } : {})).stdout;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export async function hgBranch(cwd?: string): Promise<string> {
|
|
10
|
-
return (await hg(['branch'], cwd)).replace(/[_+/]/g, '-').trim();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export async function hgRevId(cwd?: string): Promise<string> {
|
|
14
|
-
return (await hg(['id', '-i'], cwd)).replace(/[+]/g, '').trim();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type HgInfo = {
|
|
18
|
-
branch: string,
|
|
19
|
-
revision: string,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
let info = null;
|
|
23
|
-
export async function hgInfo(
|
|
24
|
-
noCache: boolean = false,
|
|
25
|
-
cwd?: string,
|
|
26
|
-
): Promise<HgInfo> {
|
|
27
|
-
if (!info || noCache) {
|
|
28
|
-
info = {
|
|
29
|
-
branch: await hgBranch(cwd),
|
|
30
|
-
revision: await hgRevId(cwd),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return info;
|
|
34
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
export * from './ant';
|
|
3
|
-
export * from './artifactory';
|
|
4
|
-
export * from './cert';
|
|
5
|
-
export * from './clean';
|
|
6
|
-
export * from './copy';
|
|
7
|
-
export * from './cp';
|
|
8
|
-
export * from './docker';
|
|
9
|
-
export * from './docker.container';
|
|
10
|
-
export * from './docker.network';
|
|
11
|
-
export * from './docker.volume';
|
|
12
|
-
export * from './dockerCleanup';
|
|
13
|
-
export * from './dockerCompose';
|
|
14
|
-
export * from './flow';
|
|
15
|
-
export * from './fs';
|
|
16
|
-
export * from './git';
|
|
17
|
-
export * from './hg';
|
|
18
|
-
export * from './inline-resources';
|
|
19
|
-
export * from './npm';
|
|
20
|
-
export * from './pkg';
|
|
21
|
-
export * from './publish';
|
|
22
|
-
export * from './run';
|
|
23
|
-
export * from './test';
|
|
24
|
-
export * from './tgz';
|
|
25
|
-
export * from './version';
|
|
26
|
-
export * from './yarn';
|
package/src/inline-resources.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import glob from 'glob';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { readFile, writeFile } from './fs';
|
|
6
|
-
|
|
7
|
-
type DependencyMap = {
|
|
8
|
-
[string]: string[],
|
|
9
|
-
};
|
|
10
|
-
// So we know to copy extra files when a dependency is modified
|
|
11
|
-
export const dependencies: DependencyMap = {};
|
|
12
|
-
|
|
13
|
-
function recordDependency(parent, child): void {
|
|
14
|
-
dependencies[child] = dependencies[child] || [];
|
|
15
|
-
if (!dependencies[child].includes(parent)) {
|
|
16
|
-
dependencies[child].push(parent);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Inline resources in a tsc/ngc compilation.
|
|
22
|
-
* @param projectPath {string} Path to the project.
|
|
23
|
-
*/
|
|
24
|
-
export async function inlineResources(projectPath: string): Promise<void> {
|
|
25
|
-
// Match only TypeScript files in projectPath.
|
|
26
|
-
const files = glob.sync('**/*.ts', { cwd: projectPath });
|
|
27
|
-
|
|
28
|
-
// For each file, inline the templates and styles under it and write the new file.
|
|
29
|
-
await Promise.all(
|
|
30
|
-
files.map(async (filePath) => {
|
|
31
|
-
const fullFilePath = path.join(projectPath, filePath);
|
|
32
|
-
const content = await readFile(fullFilePath, 'utf-8');
|
|
33
|
-
const inlined = inlineResourcesFromString(content, (url) => {
|
|
34
|
-
// Resolve the template url.
|
|
35
|
-
const templatePath = path.join(path.dirname(fullFilePath), url);
|
|
36
|
-
recordDependency(fullFilePath, templatePath);
|
|
37
|
-
return templatePath;
|
|
38
|
-
});
|
|
39
|
-
await writeFile(fullFilePath, inlined);
|
|
40
|
-
}),
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function requireResourcesLoader(content: string): string {
|
|
45
|
-
return [requireTemplate, requireStyle, removeModuleId].reduce(
|
|
46
|
-
(c, fn) => fn(c, '!raw-loader!'),
|
|
47
|
-
content,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// This is a webpack loader
|
|
52
|
-
export function webpackInlineResourceLoader(content: string): string {
|
|
53
|
-
this.cacheable(true);
|
|
54
|
-
const dir = this.context;
|
|
55
|
-
const that = this;
|
|
56
|
-
return inlineResourcesFromString(content, (url) => {
|
|
57
|
-
// Resolve the template url.
|
|
58
|
-
const fullPath = path.join(dir, url);
|
|
59
|
-
// Make sure this file gets watched
|
|
60
|
-
that.addDependency(fullPath);
|
|
61
|
-
return fullPath;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type UrlResolver = (url: string) => string;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Inline resources from a string content.
|
|
69
|
-
* @param content {string} The source file's content.
|
|
70
|
-
* @param urlResolver {Function} A resolver that takes a URL and return a path.
|
|
71
|
-
* @returns {string} The content with resources inlined.
|
|
72
|
-
*/
|
|
73
|
-
export function inlineResourcesFromString(
|
|
74
|
-
content: string,
|
|
75
|
-
urlResolver: UrlResolver,
|
|
76
|
-
): string {
|
|
77
|
-
// Curry through the inlining functions.
|
|
78
|
-
return [inlineTemplate, inlineStyle, removeModuleId].reduce(
|
|
79
|
-
(c, fn) => fn(c, urlResolver),
|
|
80
|
-
content,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// The cbFn is given the template url, and should return the string to replace it
|
|
85
|
-
function processTemplate(content: string, cbFn: UrlResolver) {
|
|
86
|
-
return content.replace(
|
|
87
|
-
/templateUrl:\s*'([^']+?\.html)'/g,
|
|
88
|
-
(m, templateUrl) => `template: ${cbFn(templateUrl)}`,
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Inline the templates for a source file. Simply search for instances of `templateUrl: ...` and
|
|
94
|
-
* replace with `template: ...` (with the content of the file included).
|
|
95
|
-
* @param content {string} The source file's content.
|
|
96
|
-
* @param urlResolver {Function} A resolver that takes a URL and return a path.
|
|
97
|
-
* @return {string} The content with all templates inlined.
|
|
98
|
-
*/
|
|
99
|
-
function inlineTemplate(content: string, urlResolver: UrlResolver): string {
|
|
100
|
-
return processTemplate(
|
|
101
|
-
content,
|
|
102
|
-
(templateUrl) =>
|
|
103
|
-
`\`${fs
|
|
104
|
-
.readFileSync(urlResolver(templateUrl), 'utf-8')
|
|
105
|
-
.replace(/([\n\r]\s*)+/gm, ' ')}\``,
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function requireTemplate(content: string, loader: string = ''): string {
|
|
110
|
-
return processTemplate(content, (url) => `require('${loader}${url}')`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// The cbFn is given the url of a single css file, and should return the string to replace it
|
|
114
|
-
function processStyle(content: string, cbFn: UrlResolver): string {
|
|
115
|
-
return content.replace(
|
|
116
|
-
/styleUrls:\s*(\[[\s\S]*?\])/gm,
|
|
117
|
-
(m, styleUrls) =>
|
|
118
|
-
// eslint-disable-next-line no-eval
|
|
119
|
-
`styles: [${eval(styleUrls)
|
|
120
|
-
.map((styleUrl) => cbFn(styleUrl))
|
|
121
|
-
.join(',\n')}]`,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Inline the styles for a source file. Simply search for instances of `styleUrls: [...]` and
|
|
127
|
-
* replace with `styles: [...]` (with the content of the file included).
|
|
128
|
-
* @param urlResolver {Function} A resolver that takes a URL and return a path.
|
|
129
|
-
* @param content {string} The source file's content.
|
|
130
|
-
* @return {string} The content with all styles inlined.
|
|
131
|
-
*/
|
|
132
|
-
function inlineStyle(content: string, urlResolver: UrlResolver): string {
|
|
133
|
-
return processStyle(
|
|
134
|
-
content,
|
|
135
|
-
(styleUrl) =>
|
|
136
|
-
`\`${fs
|
|
137
|
-
.readFileSync(urlResolver(styleUrl), 'utf-8')
|
|
138
|
-
.replace(/([\n\r]\s*)+/gm, ' ')}\``,
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function requireStyle(content: string, loader: string = ''): string {
|
|
143
|
-
return processStyle(content, (url) => `require('${loader}${url}')`);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Remove every mention of `moduleId: module.id`.
|
|
148
|
-
* @param content {string} The source file's content.
|
|
149
|
-
* @returns {string} The content with all moduleId: mentions removed.
|
|
150
|
-
*/
|
|
151
|
-
function removeModuleId(
|
|
152
|
-
content: string,
|
|
153
|
-
// eslint-disable-next-line no-unused-vars
|
|
154
|
-
urlResolver?: UrlResolver | string,
|
|
155
|
-
): string {
|
|
156
|
-
return content.replace(/\s*moduleId:\s*module\.id\s*,?\s*/gm, '');
|
|
157
|
-
}
|
package/src/maps.js
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/src/npm.js
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/src/pkg.js
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
|
-
}
|