build-strap 5.0.0-dev.69 → 5.0.0-dev.73
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/package.json +1 -1
- package/src/brew.js +2 -2
- package/src/env.d.ts +3 -3
- package/src/env.js +5 -5
- package/src/gh.d.ts +5 -1
- package/src/gh.js +4 -3
- package/src/git.d.ts +2 -1
- package/src/git.js +5 -4
package/package.json
CHANGED
package/src/brew.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
|
|
|
2
2
|
import os from 'os';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { spawn } from './cp.js';
|
|
5
|
-
import {
|
|
5
|
+
import { appendToEnv, cmdExists, ensureProcessPathEnvIncludes, } from './env.js';
|
|
6
6
|
const brewPath = async () => {
|
|
7
7
|
for (const testPath of [
|
|
8
8
|
'/opt/homebrew/bin/brew',
|
|
@@ -26,7 +26,7 @@ const brewPathExists = async () => {
|
|
|
26
26
|
};
|
|
27
27
|
const appendBrewShellEnv = async (opts) => {
|
|
28
28
|
const brewDir = path.dirname(await brewPath());
|
|
29
|
-
await
|
|
29
|
+
await appendToEnv(`\neval "$(${brewDir}/brew shellenv)"`, opts);
|
|
30
30
|
ensureProcessPathEnvIncludes(brewDir);
|
|
31
31
|
};
|
|
32
32
|
export const ensureBrewInstalled = async () => {
|
package/src/env.d.ts
CHANGED
|
@@ -15,12 +15,12 @@ interface ReadShellEnvVarOptions {
|
|
|
15
15
|
shell?: string;
|
|
16
16
|
}
|
|
17
17
|
export declare const readShellEnvVar: (name: string, { refreshEnv, envFile, shell, }?: ReadShellEnvVarOptions) => Promise<string | null>;
|
|
18
|
-
export interface
|
|
18
|
+
export interface AppendToEnvOptions {
|
|
19
19
|
envFile?: string | null;
|
|
20
20
|
testContent?: string | StringGenFn;
|
|
21
21
|
}
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
22
|
+
export declare const appendToEnv: (content: string | StringGenFn, { envFile, testContent }?: AppendToEnvOptions) => Promise<void>;
|
|
23
|
+
export declare const appendEnvVar: (name: string, value: string, { envFile }?: ReadShellEnvVarOptions) => Promise<void>;
|
|
24
24
|
export declare const ensureEnvVarValue: (name: string, value: string, opts?: ReadShellEnvVarOptions | undefined) => Promise<void>;
|
|
25
25
|
export declare const ensureEnvVarSet: (name: string, getValue: () => Promise<string>, opts?: ReadShellEnvVarOptions | undefined) => Promise<void>;
|
|
26
26
|
export declare const ensureProcessPathEnvIncludes: (binPath: string) => void;
|
package/src/env.js
CHANGED
|
@@ -60,7 +60,7 @@ export const whichCmd = async (cmd) => {
|
|
|
60
60
|
}
|
|
61
61
|
return binPath;
|
|
62
62
|
};
|
|
63
|
-
export const cmdExists = async (cmd) => !!whichCmd(cmd);
|
|
63
|
+
export const cmdExists = async (cmd) => !!(await whichCmd(cmd));
|
|
64
64
|
export const readShellEnvVar = async (name, { refreshEnv = true, envFile = shellEnvFile(), shell = os.userInfo().shell, } = {}) => {
|
|
65
65
|
if (refreshEnv && (!envFile || !(await fs.pathExists(envFile)))) {
|
|
66
66
|
throw new Error(`Could not find shell env file: ${envFile}`);
|
|
@@ -74,17 +74,17 @@ export const readShellEnvVar = async (name, { refreshEnv = true, envFile = shell
|
|
|
74
74
|
return null;
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
export const
|
|
77
|
+
export const appendToEnv = async (content, { envFile = shellEnvFile(), testContent } = {}) => {
|
|
78
78
|
if (!envFile) {
|
|
79
79
|
throw new Error('envFile must be set');
|
|
80
80
|
}
|
|
81
81
|
await appendIfMissing(envFile, content, testContent);
|
|
82
82
|
};
|
|
83
|
-
export const
|
|
83
|
+
export const appendEnvVar = async (name, value, { envFile = shellEnvFile() } = {}) => appendToEnv(`\nexport ${name}=${value}`, { envFile });
|
|
84
84
|
export const ensureEnvVarValue = async (name, value, opts) => {
|
|
85
85
|
const currentValue = await readShellEnvVar(name, opts);
|
|
86
86
|
if (currentValue !== value) {
|
|
87
|
-
await
|
|
87
|
+
await appendEnvVar(name, value, opts);
|
|
88
88
|
}
|
|
89
89
|
process.env[name] = value;
|
|
90
90
|
};
|
|
@@ -92,7 +92,7 @@ export const ensureEnvVarSet = async (name, getValue, opts) => {
|
|
|
92
92
|
const currentValue = await readShellEnvVar(name, opts);
|
|
93
93
|
if (!currentValue) {
|
|
94
94
|
const newValue = await getValue();
|
|
95
|
-
await
|
|
95
|
+
await appendEnvVar(name, newValue, opts);
|
|
96
96
|
process.env[name] = newValue;
|
|
97
97
|
}
|
|
98
98
|
};
|
package/src/gh.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { SpawnOptions } from './cp.js';
|
|
2
2
|
export declare const gh: (args: string[], options?: SpawnOptions | undefined) => Promise<import("./cp.js").SpawnResult>;
|
|
3
3
|
export declare const ghRepoClone: (repo: string, repoDir: string) => Promise<void>;
|
|
4
|
-
export declare const ensureGhRepo: (repo: string, rootDir
|
|
4
|
+
export declare const ensureGhRepo: (repo: string, { rootDir, targetDir, targetName, }?: {
|
|
5
|
+
rootDir?: string | undefined;
|
|
6
|
+
targetDir?: string | undefined;
|
|
7
|
+
targetName?: string | undefined;
|
|
8
|
+
}) => Promise<void>;
|
|
5
9
|
export declare const ensureGhAuthLogin: ({ host, scopes, }?: {
|
|
6
10
|
host?: string | undefined;
|
|
7
11
|
scopes?: string | undefined;
|
package/src/gh.js
CHANGED
|
@@ -9,10 +9,11 @@ export const ghRepoClone = async (repo, repoDir) => {
|
|
|
9
9
|
stdio: 'inherit',
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
export const ensureGhRepo = async (repo, rootDir = '.') => {
|
|
13
|
-
const repoDir =
|
|
12
|
+
export const ensureGhRepo = async (repo, { rootDir = '.', targetDir, targetName, } = {}) => {
|
|
13
|
+
const repoDir = targetDir ||
|
|
14
|
+
path.join(rootDir, targetName || repo.split('/').pop() || repo);
|
|
14
15
|
if (!(await fs.pathExists(repoDir))) {
|
|
15
|
-
buildLog(`${repo} not found, cloning...`);
|
|
16
|
+
buildLog(`${repo} not found, cloning into ${repoDir}...`);
|
|
16
17
|
await ghRepoClone(repo, repoDir);
|
|
17
18
|
}
|
|
18
19
|
};
|
package/src/git.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpawnOptions } from './cp.js';
|
|
2
|
-
export declare const git: (args: string[], opts?: SpawnOptions | undefined) => Promise<
|
|
2
|
+
export declare const git: (args: string[], opts?: SpawnOptions | undefined) => Promise<import("./cp.js").SpawnResult>;
|
|
3
|
+
export declare const gitOutput: (args: string[], opts?: SpawnOptions | undefined) => Promise<string>;
|
|
3
4
|
export declare function gitBranch(): Promise<string>;
|
|
4
5
|
export declare function gitRevId(): Promise<string>;
|
|
5
6
|
declare type GitInfo = {
|
package/src/git.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { spawn } from './cp.js';
|
|
2
2
|
import { userQuestion } from './prompt.js';
|
|
3
3
|
import { buildLog } from './run.js';
|
|
4
|
-
export const git = async (args, opts) =>
|
|
4
|
+
export const git = async (args, opts) => spawn('git', args, opts);
|
|
5
|
+
export const gitOutput = async (args, opts) => (await git(args, { captureOutput: true, ...opts })).stdout.trim();
|
|
5
6
|
export async function gitBranch() {
|
|
6
|
-
return (await
|
|
7
|
+
return (await gitOutput(['symbolic-ref', '--short', 'HEAD']))
|
|
7
8
|
.replace(/[_+/]/g, '-')
|
|
8
9
|
.trim();
|
|
9
10
|
}
|
|
10
11
|
export async function gitRevId() {
|
|
11
|
-
return (await
|
|
12
|
+
return (await gitOutput(['rev-parse', '--short=12', 'HEAD']))
|
|
12
13
|
.replace(/[+]/g, '')
|
|
13
14
|
.trim();
|
|
14
15
|
}
|
|
@@ -25,7 +26,7 @@ export async function gitInfo(noCache = false) {
|
|
|
25
26
|
export const ensureGitLfsInstalled = async () => {
|
|
26
27
|
await git(['lfs', 'install'], { stdio: 'inherit' });
|
|
27
28
|
};
|
|
28
|
-
export const gitConfigRead = async (key, global = true) =>
|
|
29
|
+
export const gitConfigRead = async (key, global = true) => gitOutput(['config', ...(global ? ['--global'] : []), key], {
|
|
29
30
|
rejectOnErrorCode: false,
|
|
30
31
|
});
|
|
31
32
|
export const gitConfigWrite = async (key, value, global = true) => {
|