@shopify/cli-kit 3.34.0 → 3.36.0
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/dist/content-tokens.js +1 -1
- package/dist/content-tokens.js.map +1 -1
- package/dist/error.js +2 -2
- package/dist/error.js.map +1 -1
- package/dist/git.js +2 -2
- package/dist/git.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/metadata.d.ts +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/monorail.d.ts +1 -1
- package/dist/monorail.js +1 -1
- package/dist/monorail.js.map +1 -1
- package/dist/output.js +3 -7
- package/dist/output.js.map +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/{typing → private/common/ts}/deep-required.d.ts +3 -3
- package/dist/{typing → private/common/ts}/deep-required.js +0 -0
- package/dist/private/common/ts/deep-required.js.map +1 -0
- package/dist/{typing → private/common/ts}/overloaded-parameters.d.ts +0 -0
- package/dist/{typing → private/common/ts}/overloaded-parameters.js +0 -0
- package/dist/private/common/ts/overloaded-parameters.js.map +1 -0
- package/dist/private/node/api/graphql.js +2 -3
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.d.ts +11 -2
- package/dist/private/node/api/headers.js +29 -3
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/api/rest.d.ts +5 -3
- package/dist/private/node/api/rest.js +8 -7
- package/dist/private/node/api/rest.js.map +1 -1
- package/dist/private/node/constants.d.ts +42 -0
- package/dist/private/node/constants.js +58 -0
- package/dist/private/node/constants.js.map +1 -0
- package/dist/private/node/environment/service.js +2 -2
- package/dist/private/node/environment/service.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +1 -1
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/exchange.js +1 -1
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/identity-token-validation.js +1 -1
- package/dist/private/node/session/identity-token-validation.js.map +1 -1
- package/dist/private/node/session/post-auth.js +10 -10
- package/dist/private/node/session/post-auth.js.map +1 -1
- package/dist/private/node/session/store.js +6 -6
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session/validate.js +2 -2
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.js +2 -2
- package/dist/private/node/session.js.map +1 -1
- package/dist/{typing → private/node}/simple-definitions.d.ts +0 -0
- package/dist/{typing → private/node}/simple-definitions.js +0 -0
- package/dist/private/node/simple-definitions.js.map +1 -0
- package/dist/private/node/ui/alert.d.ts +1 -1
- package/dist/private/node/ui/alert.js +2 -2
- package/dist/private/node/ui/alert.js.map +1 -1
- package/dist/private/node/ui/components/Alert.d.ts +5 -0
- package/dist/private/node/ui/components/Alert.js +9 -6
- package/dist/private/node/ui/components/Alert.js.map +1 -1
- package/dist/private/node/ui/components/Alert.test.js +30 -4
- package/dist/private/node/ui/components/Alert.test.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.d.ts +12 -0
- package/dist/private/node/ui/components/AutocompletePrompt.js +111 -0
- package/dist/private/node/ui/components/AutocompletePrompt.js.map +1 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.d.ts +1 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +473 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -0
- package/dist/private/node/ui/components/Banner.d.ts +0 -1
- package/dist/private/node/ui/components/Banner.js +4 -4
- package/dist/private/node/ui/components/Banner.js.map +1 -1
- package/dist/private/node/ui/components/Banner.test.js +10 -5
- package/dist/private/node/ui/components/Banner.test.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.js +1 -1
- package/dist/private/node/ui/components/FatalError.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.test.js +4 -8
- package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
- package/dist/private/node/ui/components/{Table.d.ts → Prompts/InfoTable.d.ts} +2 -2
- package/dist/private/node/ui/components/{Table.js → Prompts/InfoTable.js} +6 -6
- package/dist/private/node/ui/components/Prompts/InfoTable.js.map +1 -0
- package/dist/private/node/ui/components/SelectInput.d.ts +9 -2
- package/dist/private/node/ui/components/SelectInput.js +96 -52
- package/dist/private/node/ui/components/SelectInput.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.test.js +140 -54
- package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.d.ts +6 -4
- package/dist/private/node/ui/components/SelectPrompt.js +18 -11
- package/dist/private/node/ui/components/SelectPrompt.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +113 -23
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Table/Column.d.ts +5 -0
- package/dist/private/node/ui/components/Table/Column.js +2 -0
- package/dist/private/node/ui/components/Table/Column.js.map +1 -0
- package/dist/private/node/ui/components/Table/Row.d.ts +12 -0
- package/dist/private/node/ui/components/Table/Row.js +24 -0
- package/dist/private/node/ui/components/Table/Row.js.map +1 -0
- package/dist/private/node/ui/components/Table/ScalarDict.d.ts +5 -0
- package/dist/private/node/ui/components/Table/ScalarDict.js +2 -0
- package/dist/private/node/ui/components/Table/ScalarDict.js.map +1 -0
- package/dist/private/node/ui/components/Table/Table.d.ts +12 -0
- package/dist/private/node/ui/components/Table/Table.js +30 -0
- package/dist/private/node/ui/components/Table/Table.js.map +1 -0
- package/dist/private/node/ui/components/Table/Table.test.d.ts +1 -0
- package/dist/private/node/ui/components/Table/Table.test.js +41 -0
- package/dist/private/node/ui/components/Table/Table.test.js.map +1 -0
- package/dist/private/node/ui/components/Tasks.d.ts +6 -5
- package/dist/private/node/ui/components/Tasks.js +32 -11
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +55 -9
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.d.ts +4 -1
- package/dist/private/node/ui/components/TextInput.js +22 -13
- package/dist/private/node/ui/components/TextInput.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.test.js +47 -40
- package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.d.ts +3 -1
- package/dist/private/node/ui/components/TextPrompt.js +28 -15
- package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.test.js +71 -15
- package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.d.ts +3 -0
- package/dist/private/node/ui/components/TokenizedText.js +33 -1
- package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
- package/dist/private/node/ui/utilities.d.ts +2 -0
- package/dist/private/node/ui/utilities.js +6 -0
- package/dist/private/node/ui/utilities.js.map +1 -0
- package/dist/public/common/string.d.ts +11 -0
- package/dist/public/common/string.js +21 -0
- package/dist/public/common/string.js.map +1 -1
- package/dist/{typing → public/common/ts}/pick-by-prefix.d.ts +4 -3
- package/dist/{typing → public/common/ts}/pick-by-prefix.js +0 -0
- package/dist/public/common/ts/pick-by-prefix.js.map +1 -0
- package/dist/public/common/version.d.ts +1 -0
- package/dist/public/common/version.js +2 -0
- package/dist/public/common/version.js.map +1 -0
- package/dist/public/node/analytics.js +2 -2
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.d.ts +4 -1
- package/dist/public/node/api/admin.js +5 -4
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/http.d.ts +0 -0
- package/dist/public/node/api/http.js +2 -0
- package/dist/public/node/api/http.js.map +1 -0
- package/dist/public/node/api/oxygen.js +1 -1
- package/dist/public/node/api/oxygen.js.map +1 -1
- package/dist/public/node/archiver.js +2 -1
- package/dist/public/node/archiver.js.map +1 -1
- package/dist/public/node/cli.js +6 -6
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/dot-env.js +2 -2
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/environment/local.js +17 -17
- package/dist/public/node/environment/local.js.map +1 -1
- package/dist/public/node/environment/spin.js +6 -6
- package/dist/public/node/environment/spin.js.map +1 -1
- package/dist/public/node/error-handler.js +13 -10
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/framework.js +2 -2
- package/dist/public/node/framework.js.map +1 -1
- package/dist/public/node/fs.d.ts +241 -4
- package/dist/public/node/fs.js +366 -2
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.d.ts +90 -0
- package/dist/public/node/git.js +174 -0
- package/dist/public/node/git.js.map +1 -0
- package/dist/public/node/github.js +1 -1
- package/dist/public/node/github.js.map +1 -1
- package/dist/{http/fetch.d.ts → public/node/http.d.ts} +18 -7
- package/dist/{http/fetch.js → public/node/http.js} +21 -8
- package/dist/public/node/http.js.map +1 -0
- package/dist/public/node/liquid.js +9 -9
- package/dist/public/node/liquid.js.map +1 -1
- package/dist/public/node/node-package-manager.d.ts +20 -9
- package/dist/public/node/node-package-manager.js +19 -25
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/path.d.ts +22 -0
- package/dist/{path.js → public/node/path.js} +8 -20
- package/dist/public/node/path.js.map +1 -0
- package/dist/public/node/presets.js +5 -5
- package/dist/public/node/presets.js.map +1 -1
- package/dist/public/node/ruby.js +29 -33
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/session.js +2 -2
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/ui.d.ts +63 -9
- package/dist/public/node/ui.js +83 -8
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vscode.js +8 -8
- package/dist/public/node/vscode.js.map +1 -1
- package/dist/secure-store.js +4 -4
- package/dist/secure-store.js.map +1 -1
- package/dist/store.d.ts +10 -10
- package/dist/store.js +21 -22
- package/dist/store.js.map +1 -1
- package/dist/testing/store.js +3 -3
- package/dist/testing/store.js.map +1 -1
- package/dist/testing/ui.d.ts +4 -1
- package/dist/testing/ui.js +24 -1
- package/dist/testing/ui.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui/executor.d.ts +2 -14
- package/dist/ui/executor.js +38 -72
- package/dist/ui/executor.js.map +1 -1
- package/dist/ui.js +9 -26
- package/dist/ui.js.map +1 -1
- package/package.json +4 -6
- package/dist/constants.d.ts +0 -48
- package/dist/constants.js +0 -67
- package/dist/constants.js.map +0 -1
- package/dist/file.d.ts +0 -98
- package/dist/file.js +0 -216
- package/dist/file.js.map +0 -1
- package/dist/http/fetch.js.map +0 -1
- package/dist/http/formdata.d.ts +0 -3
- package/dist/http/formdata.js +0 -6
- package/dist/http/formdata.js.map +0 -1
- package/dist/http.d.ts +0 -26
- package/dist/http.js +0 -31
- package/dist/http.js.map +0 -1
- package/dist/npm.d.ts +0 -27
- package/dist/npm.js +0 -20
- package/dist/npm.js.map +0 -1
- package/dist/path.d.ts +0 -25
- package/dist/path.js.map +0 -1
- package/dist/private/node/ui/components/Table.js.map +0 -1
- package/dist/typing/deep-required.js.map +0 -1
- package/dist/typing/overloaded-parameters.js.map +0 -1
- package/dist/typing/pick-by-prefix.js.map +0 -1
- package/dist/typing/simple-definitions.js.map +0 -1
- package/dist/ui/inquirer/autocomplete.d.ts +0 -11
- package/dist/ui/inquirer/autocomplete.js +0 -110
- package/dist/ui/inquirer/autocomplete.js.map +0 -1
- package/dist/ui/inquirer/input.d.ts +0 -16
- package/dist/ui/inquirer/input.js +0 -45
- package/dist/ui/inquirer/input.js.map +0 -1
- package/dist/ui/inquirer/password.d.ts +0 -7
- package/dist/ui/inquirer/password.js +0 -8
- package/dist/ui/inquirer/password.js.map +0 -1
- package/dist/ui/inquirer/select.d.ts +0 -14
- package/dist/ui/inquirer/select.js +0 -26
- package/dist/ui/inquirer/select.js.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Abort } from '../../error.js';
|
|
2
|
+
import { DefaultLogFields, ListLogLine } from 'simple-git';
|
|
3
|
+
export declare const gitFactory: import("simple-git").SimpleGitFactory;
|
|
4
|
+
/**
|
|
5
|
+
* Initialize a git repository at the given directory.
|
|
6
|
+
*
|
|
7
|
+
* @param directory - The directory where the git repository will be initialized.
|
|
8
|
+
* @param initialBranch - The name of the initial branch.
|
|
9
|
+
*/
|
|
10
|
+
export declare function initializeGitRepository(directory: string, initialBranch?: string): Promise<void>;
|
|
11
|
+
export interface GitIgnoreTemplate {
|
|
12
|
+
[section: string]: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a .gitignore file in the given directory.
|
|
16
|
+
*
|
|
17
|
+
* @param directory - The directory where the .gitignore file will be created.
|
|
18
|
+
* @param template - The template to use to create the .gitignore file.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createGitIgnore(directory: string, template: GitIgnoreTemplate): void;
|
|
21
|
+
/**
|
|
22
|
+
* Options to use when cloning a git repository.
|
|
23
|
+
*
|
|
24
|
+
* @param repoUrl - The URL of the repository to clone.
|
|
25
|
+
* @param destination - The directory where the repository will be cloned.
|
|
26
|
+
* @param progressUpdater - A function that will be called with the progress of the clone.
|
|
27
|
+
* @param shallow - Whether to clone the repository shallowly.
|
|
28
|
+
* @param latestTag - Whether to clone the latest tag instead of the default branch.
|
|
29
|
+
*/
|
|
30
|
+
export interface GitCloneOptions {
|
|
31
|
+
repoUrl: string;
|
|
32
|
+
destination: string;
|
|
33
|
+
progressUpdater?: (statusString: string) => void;
|
|
34
|
+
shallow?: boolean;
|
|
35
|
+
latestTag?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clone a git repository.
|
|
39
|
+
*
|
|
40
|
+
* @param cloneOptions - The options to use to clone the repository.
|
|
41
|
+
* @returns A promise that resolves when the clone is complete.
|
|
42
|
+
*/
|
|
43
|
+
export declare function downloadGitRepository(cloneOptions: GitCloneOptions): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the latest commit of a git repository.
|
|
46
|
+
*
|
|
47
|
+
* @param directory - The directory of the git repository.
|
|
48
|
+
* @returns The latest commit of the repository.
|
|
49
|
+
*/
|
|
50
|
+
export declare function getLatestGitCommit(directory?: string): Promise<DefaultLogFields & ListLogLine>;
|
|
51
|
+
/**
|
|
52
|
+
* Add all files to the git index from the given directory.
|
|
53
|
+
*
|
|
54
|
+
* @param directory - The directory where the git repository is located.
|
|
55
|
+
* @returns A promise that resolves when the files are added to the index.
|
|
56
|
+
*/
|
|
57
|
+
export declare function addAllToGitFromDirectory(directory?: string): Promise<void>;
|
|
58
|
+
export interface CreateGitCommitOptions {
|
|
59
|
+
directory?: string;
|
|
60
|
+
author?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a git commit.
|
|
64
|
+
*
|
|
65
|
+
* @param message - The message of the commit.
|
|
66
|
+
* @param options - The options to use to create the commit.
|
|
67
|
+
* @returns The hash of the created commit.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the HEAD symbolic reference of a git repository.
|
|
72
|
+
*
|
|
73
|
+
* @param directory - The directory of the git repository.
|
|
74
|
+
* @returns The HEAD symbolic reference of the repository.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getHeadSymbolicRef(directory?: string): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* If "git" is not present in the environment it throws
|
|
79
|
+
* an abort error.
|
|
80
|
+
*/
|
|
81
|
+
export declare function ensureGitIsPresentOrAbort(): Promise<void>;
|
|
82
|
+
export declare class OutsideGitDirectoryError extends Abort {
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* If command run from outside a .git directory tree
|
|
86
|
+
* it throws an abort error.
|
|
87
|
+
*
|
|
88
|
+
* @param directory - The directory to check.
|
|
89
|
+
*/
|
|
90
|
+
export declare function ensureInsideGitDirectory(directory?: string): Promise<void>;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { hasGit, isTerminalInteractive } from './environment/local.js';
|
|
2
|
+
import { appendFileSync } from './fs.js';
|
|
3
|
+
import { Abort } from '../../error.js';
|
|
4
|
+
import { content, token, debug } from '../../output.js';
|
|
5
|
+
import git from 'simple-git';
|
|
6
|
+
export const gitFactory = git;
|
|
7
|
+
/**
|
|
8
|
+
* Initialize a git repository at the given directory.
|
|
9
|
+
*
|
|
10
|
+
* @param directory - The directory where the git repository will be initialized.
|
|
11
|
+
* @param initialBranch - The name of the initial branch.
|
|
12
|
+
*/
|
|
13
|
+
export async function initializeGitRepository(directory, initialBranch = 'main') {
|
|
14
|
+
debug(content `Initializing git repository at ${token.path(directory)}...`);
|
|
15
|
+
await ensureGitIsPresentOrAbort();
|
|
16
|
+
// We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+
|
|
17
|
+
const repo = git(directory);
|
|
18
|
+
await repo.init();
|
|
19
|
+
await repo.checkoutLocalBranch(initialBranch);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a .gitignore file in the given directory.
|
|
23
|
+
*
|
|
24
|
+
* @param directory - The directory where the .gitignore file will be created.
|
|
25
|
+
* @param template - The template to use to create the .gitignore file.
|
|
26
|
+
*/
|
|
27
|
+
export function createGitIgnore(directory, template) {
|
|
28
|
+
debug(content `Creating .gitignore at ${token.path(directory)}...`);
|
|
29
|
+
const filePath = `${directory}/.gitignore`;
|
|
30
|
+
let fileContent = '';
|
|
31
|
+
for (const [section, lines] of Object.entries(template)) {
|
|
32
|
+
fileContent += `# ${section}\n`;
|
|
33
|
+
fileContent += `${lines.join('\n')}\n\n`;
|
|
34
|
+
}
|
|
35
|
+
appendFileSync(filePath, fileContent);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Clone a git repository.
|
|
39
|
+
*
|
|
40
|
+
* @param cloneOptions - The options to use to clone the repository.
|
|
41
|
+
* @returns A promise that resolves when the clone is complete.
|
|
42
|
+
*/
|
|
43
|
+
export async function downloadGitRepository(cloneOptions) {
|
|
44
|
+
const { repoUrl, destination, progressUpdater, shallow, latestTag } = cloneOptions;
|
|
45
|
+
debug(content `Git-cloning repository ${repoUrl} into ${token.path(destination)}...`);
|
|
46
|
+
await ensureGitIsPresentOrAbort();
|
|
47
|
+
const [repository, branch] = repoUrl.split('#');
|
|
48
|
+
const options = { '--recurse-submodules': null };
|
|
49
|
+
if (branch && latestTag) {
|
|
50
|
+
throw new Abort("Error cloning the repository. Git can't clone the latest release with a 'branch'.");
|
|
51
|
+
}
|
|
52
|
+
if (branch) {
|
|
53
|
+
options['--branch'] = branch;
|
|
54
|
+
}
|
|
55
|
+
if (shallow && latestTag) {
|
|
56
|
+
throw new Abort("Error cloning the repository. Git can't clone the latest release with the 'shallow' property.");
|
|
57
|
+
}
|
|
58
|
+
if (shallow) {
|
|
59
|
+
options['--depth'] = 1;
|
|
60
|
+
}
|
|
61
|
+
const progress = ({ stage, progress, processed, total }) => {
|
|
62
|
+
const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`;
|
|
63
|
+
if (progressUpdater)
|
|
64
|
+
progressUpdater(updateString);
|
|
65
|
+
};
|
|
66
|
+
const simpleGitOptions = {
|
|
67
|
+
progress,
|
|
68
|
+
...(!isTerminalInteractive() && { config: ['core.askpass=true'] }),
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
await git(simpleGitOptions).clone(repository, destination, options);
|
|
72
|
+
if (latestTag) {
|
|
73
|
+
const localGitRepository = git(destination);
|
|
74
|
+
const latestTag = await getLocalLatestTag(localGitRepository, repoUrl);
|
|
75
|
+
await localGitRepository.checkout(latestTag);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
if (err instanceof Error) {
|
|
80
|
+
const abortError = new Abort(err.message);
|
|
81
|
+
abortError.stack = err.stack;
|
|
82
|
+
throw abortError;
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the most recent tag of a local git repository.
|
|
89
|
+
*
|
|
90
|
+
* @param repository - The local git repository.
|
|
91
|
+
* @param repoUrl - The URL of the repository.
|
|
92
|
+
* @returns The most recent tag of the repository.
|
|
93
|
+
*/
|
|
94
|
+
async function getLocalLatestTag(repository, repoUrl) {
|
|
95
|
+
const latest = (await repository.tags()).latest;
|
|
96
|
+
if (!latest) {
|
|
97
|
+
throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`);
|
|
98
|
+
}
|
|
99
|
+
return latest;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the latest commit of a git repository.
|
|
103
|
+
*
|
|
104
|
+
* @param directory - The directory of the git repository.
|
|
105
|
+
* @returns The latest commit of the repository.
|
|
106
|
+
*/
|
|
107
|
+
export async function getLatestGitCommit(directory) {
|
|
108
|
+
const logs = await git({ baseDir: directory }).log({
|
|
109
|
+
maxCount: 1,
|
|
110
|
+
});
|
|
111
|
+
if (!logs.latest) {
|
|
112
|
+
throw new Abort('Must have at least one commit to run command', content `Run ${token.genericShellCommand("git commit -m 'Initial commit'")} to create your first commit.`);
|
|
113
|
+
}
|
|
114
|
+
return logs.latest;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Add all files to the git index from the given directory.
|
|
118
|
+
*
|
|
119
|
+
* @param directory - The directory where the git repository is located.
|
|
120
|
+
* @returns A promise that resolves when the files are added to the index.
|
|
121
|
+
*/
|
|
122
|
+
export async function addAllToGitFromDirectory(directory) {
|
|
123
|
+
const simpleGit = git({ baseDir: directory });
|
|
124
|
+
await simpleGit.raw('add', '--all');
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a git commit.
|
|
128
|
+
*
|
|
129
|
+
* @param message - The message of the commit.
|
|
130
|
+
* @param options - The options to use to create the commit.
|
|
131
|
+
* @returns The hash of the created commit.
|
|
132
|
+
*/
|
|
133
|
+
export async function createGitCommit(message, options) {
|
|
134
|
+
const simpleGit = git({ baseDir: options?.directory });
|
|
135
|
+
const commitOptions = options?.author ? { '--author': options.author } : undefined;
|
|
136
|
+
const result = await simpleGit.commit(message, commitOptions);
|
|
137
|
+
return result.commit;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get the HEAD symbolic reference of a git repository.
|
|
141
|
+
*
|
|
142
|
+
* @param directory - The directory of the git repository.
|
|
143
|
+
* @returns The HEAD symbolic reference of the repository.
|
|
144
|
+
*/
|
|
145
|
+
export async function getHeadSymbolicRef(directory) {
|
|
146
|
+
const ref = await git({ baseDir: directory }).raw('symbolic-ref', '-q', 'HEAD');
|
|
147
|
+
if (!ref) {
|
|
148
|
+
throw new Abort("Git HEAD can't be detached to run command", content `Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link('documentation', 'https://git-scm.com/book/en/v2/Git-Internals-Git-References')} for more details`);
|
|
149
|
+
}
|
|
150
|
+
return ref.trim();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* If "git" is not present in the environment it throws
|
|
154
|
+
* an abort error.
|
|
155
|
+
*/
|
|
156
|
+
export async function ensureGitIsPresentOrAbort() {
|
|
157
|
+
if (!(await hasGit())) {
|
|
158
|
+
throw new Abort(`Git is necessary in the environment to continue`, content `Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
export class OutsideGitDirectoryError extends Abort {
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* If command run from outside a .git directory tree
|
|
165
|
+
* it throws an abort error.
|
|
166
|
+
*
|
|
167
|
+
* @param directory - The directory to check.
|
|
168
|
+
*/
|
|
169
|
+
export async function ensureInsideGitDirectory(directory) {
|
|
170
|
+
if (!(await git({ baseDir: directory }).checkIsRepo())) {
|
|
171
|
+
throw new OutsideGitDirectoryError(`${token.path(directory || process.cwd())} is not a Git directory`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//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BAAmB,CACrB,CAAA;KACF;IACD,OAAO,GAAG,CAAC,IAAI,EAAE,CAAA;AACnB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB;IAC7C,IAAI,CAAC,CAAC,MAAM,MAAM,EAAE,CAAC,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,iDAAiD,EACjD,OAAO,CAAA,WAAW,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,+DAA+D,CAAC,EAAE,CACvG,CAAA;KACF;AACH,CAAC;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;CAAG;AACtD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,SAAkB;IAC/D,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE;QACpD,MAAM,IAAI,wBAAwB,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,yBAAyB,CAAC,CAAA;KACvG;AACH,CAAC","sourcesContent":["import {hasGit, isTerminalInteractive} from './environment/local.js'\nimport {appendFileSync} from './fs.js'\nimport {Abort} from '../../error.js'\nimport {content, token, debug} from '../../output.js'\nimport git, {TaskOptions, SimpleGitProgressEvent, DefaultLogFields, ListLogLine, SimpleGit} from 'simple-git'\n\nexport const gitFactory = git\n\n/**\n * Initialize a git repository at the given directory.\n *\n * @param directory - The directory where the git repository will be initialized.\n * @param initialBranch - The name of the initial branch.\n */\nexport async function initializeGitRepository(directory: string, initialBranch = 'main'): Promise<void> {\n debug(content`Initializing git repository at ${token.path(directory)}...`)\n await ensureGitIsPresentOrAbort()\n // We use init and checkout instead of `init --initial-branch` because the latter is only supported in git 2.28+\n const repo = git(directory)\n await repo.init()\n await repo.checkoutLocalBranch(initialBranch)\n}\n\nexport interface GitIgnoreTemplate {\n [section: string]: string[]\n}\n/**\n * Create a .gitignore file in the given directory.\n *\n * @param directory - The directory where the .gitignore file will be created.\n * @param template - The template to use to create the .gitignore file.\n */\nexport function createGitIgnore(directory: string, template: GitIgnoreTemplate): void {\n debug(content`Creating .gitignore at ${token.path(directory)}...`)\n const filePath = `${directory}/.gitignore`\n\n let fileContent = ''\n for (const [section, lines] of Object.entries(template)) {\n fileContent += `# ${section}\\n`\n fileContent += `${lines.join('\\n')}\\n\\n`\n }\n\n appendFileSync(filePath, fileContent)\n}\n\n/**\n * Options to use when cloning a git repository.\n *\n * @param repoUrl - The URL of the repository to clone.\n * @param destination - The directory where the repository will be cloned.\n * @param progressUpdater - A function that will be called with the progress of the clone.\n * @param shallow - Whether to clone the repository shallowly.\n * @param latestTag - Whether to clone the latest tag instead of the default branch.\n */\nexport interface GitCloneOptions {\n repoUrl: string\n destination: string\n progressUpdater?: (statusString: string) => void\n shallow?: boolean\n latestTag?: boolean\n}\n/**\n * Clone a git repository.\n *\n * @param cloneOptions - The options to use to clone the repository.\n * @returns A promise that resolves when the clone is complete.\n */\nexport async function downloadGitRepository(cloneOptions: GitCloneOptions): Promise<void> {\n const {repoUrl, destination, progressUpdater, shallow, latestTag} = cloneOptions\n debug(content`Git-cloning repository ${repoUrl} into ${token.path(destination)}...`)\n await ensureGitIsPresentOrAbort()\n const [repository, branch] = repoUrl.split('#')\n const options: TaskOptions = {'--recurse-submodules': null}\n\n if (branch && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with a 'branch'.\")\n }\n if (branch) {\n options['--branch'] = branch\n }\n\n if (shallow && latestTag) {\n throw new Abort(\"Error cloning the repository. Git can't clone the latest release with the 'shallow' property.\")\n }\n if (shallow) {\n options['--depth'] = 1\n }\n\n const progress = ({stage, progress, processed, total}: SimpleGitProgressEvent) => {\n const updateString = `${stage}, ${processed}/${total} objects (${progress}% complete)`\n if (progressUpdater) progressUpdater(updateString)\n }\n\n const simpleGitOptions = {\n progress,\n ...(!isTerminalInteractive() && {config: ['core.askpass=true']}),\n }\n try {\n await git(simpleGitOptions).clone(repository!, destination, options)\n\n if (latestTag) {\n const localGitRepository = git(destination)\n const latestTag = await getLocalLatestTag(localGitRepository, repoUrl)\n await localGitRepository.checkout(latestTag)\n }\n } catch (err) {\n if (err instanceof Error) {\n const abortError = new Abort(err.message)\n abortError.stack = err.stack\n throw abortError\n }\n throw err\n }\n}\n\n/**\n * Get the most recent tag of a local git repository.\n *\n * @param repository - The local git repository.\n * @param repoUrl - The URL of the repository.\n * @returns The most recent tag of the repository.\n */\nasync function getLocalLatestTag(repository: SimpleGit, repoUrl: string): Promise<string> {\n const latest = (await repository.tags()).latest\n\n if (!latest) {\n throw new Abort(`Couldn't obtain the most recent tag of the repository ${repoUrl}`)\n }\n\n return latest\n}\n\n/**\n * Get the latest commit of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The latest commit of the repository.\n */\nexport async function getLatestGitCommit(directory?: string): Promise<DefaultLogFields & ListLogLine> {\n const logs = await git({baseDir: directory}).log({\n maxCount: 1,\n })\n if (!logs.latest) {\n throw new Abort(\n 'Must have at least one commit to run command',\n content`Run ${token.genericShellCommand(\"git commit -m 'Initial commit'\")} to create your first commit.`,\n )\n }\n return logs.latest\n}\n\n/**\n * Add all files to the git index from the given directory.\n *\n * @param directory - The directory where the git repository is located.\n * @returns A promise that resolves when the files are added to the index.\n */\nexport async function addAllToGitFromDirectory(directory?: string): Promise<void> {\n const simpleGit = git({baseDir: directory})\n await simpleGit.raw('add', '--all')\n}\n\nexport interface CreateGitCommitOptions {\n directory?: string\n author?: string\n}\n\n/**\n * Create a git commit.\n *\n * @param message - The message of the commit.\n * @param options - The options to use to create the commit.\n * @returns The hash of the created commit.\n */\nexport async function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string> {\n const simpleGit = git({baseDir: options?.directory})\n\n const commitOptions = options?.author ? {'--author': options.author} : undefined\n const result = await simpleGit.commit(message, commitOptions)\n\n return result.commit\n}\n\n/**\n * Get the HEAD symbolic reference of a git repository.\n *\n * @param directory - The directory of the git repository.\n * @returns The HEAD symbolic reference of the repository.\n */\nexport async function getHeadSymbolicRef(directory?: string): Promise<string> {\n const ref = await git({baseDir: directory}).raw('symbolic-ref', '-q', 'HEAD')\n if (!ref) {\n throw new Abort(\n \"Git HEAD can't be detached to run command\",\n content`Run ${token.genericShellCommand('git checkout [branchName]')} to reattach HEAD or see git ${token.link(\n 'documentation',\n 'https://git-scm.com/book/en/v2/Git-Internals-Git-References',\n )} for more details`,\n )\n }\n return ref.trim()\n}\n\n/**\n * If \"git\" is not present in the environment it throws\n * an abort error.\n */\nexport async function ensureGitIsPresentOrAbort(): Promise<void> {\n if (!(await hasGit())) {\n throw new Abort(\n `Git is necessary in the environment to continue`,\n content`Install ${token.link('git', 'https://git-scm.com/book/en/v2/Getting-Started-Installing-Git')}`,\n )\n }\n}\n\nexport class OutsideGitDirectoryError extends Abort {}\n/**\n * If command run from outside a .git directory tree\n * it throws an abort error.\n *\n * @param directory - The directory to check.\n */\nexport async function ensureInsideGitDirectory(directory?: string): Promise<void> {\n if (!(await git({baseDir: directory}).checkIsRepo())) {\n throw new OutsideGitDirectoryError(`${token.path(directory || process.cwd())} is not a Git directory`)\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { err, ok } from './result.js';
|
|
2
|
-
import { fetch } from '
|
|
2
|
+
import { fetch } from './http.js';
|
|
3
3
|
import { content, debug } from '../../output.js';
|
|
4
4
|
class GitHubClientError extends Error {
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../../src/public/node/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAC,KAAK,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../../src/public/node/github.ts"],"names":[],"mappings":"AAAA,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F,CAAC;AAQD;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,SAAiB;IAC9D,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAA;IAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACvD,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5D,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAErE,OAAO;QACL,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,IAAI,IAAI,IAAI,IAAI,EAAE;QACxC,MAAM;QACN,QAAQ;KACT,CAAA;AACH,CAAC","sourcesContent":["import {err, ok, Result} from './result.js'\nimport {fetch} from './http.js'\nimport {content, debug} from '../../output.js'\n\nclass GitHubClientError extends Error {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(url: string, statusCode: number, bodyJson: any) {\n super(\n `The request to GitHub API URL ${url} failed with status code ${statusCode} and the following error message: ${bodyJson.message}`,\n )\n }\n}\n\nexport interface GithubRelease {\n id: number\n url: string\n tag_name: string\n name: string\n body: string\n draft: boolean\n prerelease: boolean\n created_at: string\n published_at: string\n tarball_url: string\n}\n\ninterface GetLatestGitHubReleaseOptions {\n filter: (release: GithubRelease) => boolean\n}\n\n/**\n * Given a GitHub repository it obtains the latest release.\n * @param owner - Repository owner (e.g., shopify)\n * @param repo - Repository name (e.g., cli)\n * @param options - Options\n */\nexport async function getLatestGitHubRelease(\n owner: string,\n repo: string,\n options: GetLatestGitHubReleaseOptions = {filter: () => true},\n): Promise<GithubRelease> {\n debug(content`Getting the latest release of GitHub repository ${owner}/${repo}...`)\n const url = `https://api.github.com/repos/${owner}/${repo}/releases`\n const fetchResult = await fetch(url)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jsonBody: any = await fetchResult.json()\n\n if (fetchResult.status !== 200) {\n throw new GitHubClientError(url, fetchResult.status, jsonBody)\n }\n\n return jsonBody.find(options.filter)\n}\n\ninterface ParseRepositoryURLOutput {\n full: string\n site: string\n user: string\n name: string\n ref: string\n subDirectory: string\n ssh: string\n http: string\n}\n\n/**\n * Given a GitHub repository URL, it parses it and returns its coomponents.\n * @param url - The GitHub repository URL\n */\nexport function parseGitHubRepositoryURL(url: string): Result<ParseRepositoryURLOutput, Error> {\n const match =\n /^(?:(?:https:\\/\\/)?([^:/]+\\.[^:/]+)\\/|git@([^:/]+)[:/]|([^/]+):)?([^/\\s]+)\\/([^/\\s#]+)(?:((?:\\/[^/\\s#]+)+))?(?:\\/)?(?:#(.+))?/.exec(\n url,\n )\n\n if (!match) {\n const exampleFormats = [\n 'github:user/repo',\n 'user/repo/subdirectory',\n 'git@github.com:user/repo',\n 'user/repo#dev',\n 'https://github.com/user/repo',\n ]\n\n return err(new Error(`Parsing the url ${url} failed. Supported formats are ${exampleFormats.join(', ')}.`))\n }\n\n const site = match[1] || match[2] || match[3] || 'github.com'\n const normalizedSite = site === 'github' ? 'github.com' : site\n const user = match[4]!\n const name = match[5]!.replace(/\\.git$/, '')\n const subDirectory = match[6]?.slice(1)!\n const ref = match[7]!\n const branch = ref ? `#${ref}` : ''\n const ssh = `git@${normalizedSite}:${user}/${name}`\n const http = `https://${normalizedSite}/${user}/${name}`\n const full = ['https:/', normalizedSite, user, name, subDirectory].join('/').concat(branch)\n\n return ok({full, site: normalizedSite, user, name, ref, subDirectory, ssh, http})\n}\n\nexport interface GithubRepositoryReference {\n baseURL: string\n branch?: string\n filePath?: string\n}\n\n/**\n * Given a GitHub repository URL it parses it and extracts the branch, file path,\n * and base URL components\n * @param reference - A GitHub repository URL (e.g. https://github.com/Shopify/cli/blob/main/package.json)\n */\nexport function parseGitHubRepositoryReference(reference: string): GithubRepositoryReference {\n const url = new URL(reference)\n const branch = url.hash ? url.hash.slice(1) : undefined\n const [_, user, repo, ...repoPath] = url.pathname.split('/')\n const filePath = repoPath.length > 0 ? repoPath.join('/') : undefined\n\n return {\n baseURL: `${url.origin}/${user}/${repo}`,\n branch,\n filePath,\n }\n}\n"]}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
import nodeFetch, { RequestInfo, RequestInit } from 'node-fetch';
|
|
3
|
+
export { createApp, createRouter, IncomingMessage, ServerResponse, CompatibilityEvent, createError, send, sendError, sendRedirect, H3Error, } from 'h3';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new FormData object.
|
|
6
|
+
*
|
|
7
|
+
* @returns A FormData object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function formData(): FormData;
|
|
10
|
+
export declare type Response = ReturnType<typeof nodeFetch>;
|
|
4
11
|
/**
|
|
5
12
|
* An interface that abstracts way node-fetch. When Node has built-in
|
|
6
13
|
* support for "fetch" in the standard library, we can drop the node-fetch
|
|
@@ -8,15 +15,19 @@ declare type Response = ReturnType<typeof nodeFetch>;
|
|
|
8
15
|
* Note that we are exposing types from "node-fetch". The reason being is that
|
|
9
16
|
* they are consistent with the Web API so if we drop node-fetch in the future
|
|
10
17
|
* it won't require changes from the callers.
|
|
18
|
+
*
|
|
11
19
|
* @param url - This defines the resource that you wish to fetch.
|
|
12
|
-
* @param init - An object containing any custom settings that you want to apply to the request
|
|
20
|
+
* @param init - An object containing any custom settings that you want to apply to the request.
|
|
13
21
|
* @returns A promise that resolves with the response.
|
|
14
22
|
*/
|
|
15
|
-
export
|
|
23
|
+
export declare function fetch(url: RequestInfo, init?: RequestInit): Response;
|
|
16
24
|
/**
|
|
17
25
|
* A fetch function to use with Shopify services. The function ensures the right
|
|
18
26
|
* TLS configuragion is used based on the environment in which the service is running
|
|
19
|
-
* (e.g.
|
|
27
|
+
* (e.g. Spin).
|
|
28
|
+
*
|
|
29
|
+
* @param url - This defines the resource that you wish to fetch.
|
|
30
|
+
* @param init - An object containing any custom settings that you want to apply to the request.
|
|
31
|
+
* @returns A promise that resolves with the response.
|
|
20
32
|
*/
|
|
21
33
|
export declare function shopifyFetch(url: RequestInfo, init?: RequestInit): Response;
|
|
22
|
-
export {};
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { httpsAgent } from '
|
|
2
|
-
import { content, debug } from '
|
|
3
|
-
import
|
|
1
|
+
import { buildHeaders, httpsAgent, sanitizedHeadersOutput } from '../../private/node/api/headers.js';
|
|
2
|
+
import { content, debug } from '../../output.js';
|
|
3
|
+
import FormData from 'form-data';
|
|
4
4
|
import nodeFetch from 'node-fetch';
|
|
5
|
-
|
|
5
|
+
export { createApp, createRouter, createError, send, sendError, sendRedirect, H3Error, } from 'h3';
|
|
6
|
+
/**
|
|
7
|
+
* Create a new FormData object.
|
|
8
|
+
*
|
|
9
|
+
* @returns A FormData object.
|
|
10
|
+
*/
|
|
11
|
+
export function formData() {
|
|
12
|
+
return new FormData();
|
|
13
|
+
}
|
|
6
14
|
/**
|
|
7
15
|
* An interface that abstracts way node-fetch. When Node has built-in
|
|
8
16
|
* support for "fetch" in the standard library, we can drop the node-fetch
|
|
@@ -10,18 +18,23 @@ import { performance } from 'perf_hooks';
|
|
|
10
18
|
* Note that we are exposing types from "node-fetch". The reason being is that
|
|
11
19
|
* they are consistent with the Web API so if we drop node-fetch in the future
|
|
12
20
|
* it won't require changes from the callers.
|
|
21
|
+
*
|
|
13
22
|
* @param url - This defines the resource that you wish to fetch.
|
|
14
|
-
* @param init - An object containing any custom settings that you want to apply to the request
|
|
23
|
+
* @param init - An object containing any custom settings that you want to apply to the request.
|
|
15
24
|
* @returns A promise that resolves with the response.
|
|
16
25
|
*/
|
|
17
|
-
export
|
|
26
|
+
export async function fetch(url, init) {
|
|
18
27
|
const response = await nodeFetch(url, init);
|
|
19
28
|
return response;
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
31
|
* A fetch function to use with Shopify services. The function ensures the right
|
|
23
32
|
* TLS configuragion is used based on the environment in which the service is running
|
|
24
|
-
* (e.g.
|
|
33
|
+
* (e.g. Spin).
|
|
34
|
+
*
|
|
35
|
+
* @param url - This defines the resource that you wish to fetch.
|
|
36
|
+
* @param init - An object containing any custom settings that you want to apply to the request.
|
|
37
|
+
* @returns A promise that resolves with the response.
|
|
25
38
|
*/
|
|
26
39
|
export async function shopifyFetch(url, init) {
|
|
27
40
|
const options = {
|
|
@@ -41,4 +54,4 @@ ${sanitizedHeadersOutput((options?.headers ?? {}))}
|
|
|
41
54
|
debug(`Request to ${url.toString()} completed with status ${response.status} in ${Math.round(t1 - t0)} ms`);
|
|
42
55
|
return response;
|
|
43
56
|
}
|
|
44
|
-
//# sourceMappingURL=
|
|
57
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/public/node/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,UAAU,EAAE,sBAAsB,EAAC,MAAM,mCAAmC,CAAA;AAClG,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AAC9C,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,SAAqC,MAAM,YAAY,CAAA;AAE9D,OAAO,EACL,SAAS,EACT,YAAY,EAIZ,WAAW,EACX,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,OAAO,GACR,MAAM,IAAI,CAAA;AAEX;;;;GAIG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,IAAI,QAAQ,EAAE,CAAA;AACvB,CAAC;AAID;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,GAAgB,EAAE,IAAkB;IAC9D,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAC3C,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAgB,EAAE,IAAkB;IACrE,MAAM,OAAO,GAAgB;QAC3B,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;QACf,OAAO,EAAE;YACP,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC;YACzB,GAAG,CAAC,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC;SACzB;KACF,CAAA;IAED,KAAK,CAAC,OAAO,CAAA;UACL,OAAO,CAAC,MAAM,IAAI,KAAK,mBAAmB,GAAG,CAAC,QAAQ,EAAE;EAChE,sBAAsB,CAAC,CAAC,OAAO,EAAE,OAAO,IAAI,EAAE,CAA+B,CAAC;CAC/E,CAAC,CAAA;IACA,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,EAAC,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,UAAU,EAAE,EAAC,CAAC,CAAA;IAC3E,MAAM,EAAE,GAAG,WAAW,CAAC,GAAG,EAAE,CAAA;IAC5B,KAAK,CAAC,cAAc,GAAG,CAAC,QAAQ,EAAE,0BAA0B,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IAC3G,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["import {buildHeaders, httpsAgent, sanitizedHeadersOutput} from '../../private/node/api/headers.js'\nimport {content, debug} from '../../output.js'\nimport FormData from 'form-data'\nimport nodeFetch, {RequestInfo, RequestInit} from 'node-fetch'\n\nexport {\n createApp,\n createRouter,\n IncomingMessage,\n ServerResponse,\n CompatibilityEvent,\n createError,\n send,\n sendError,\n sendRedirect,\n H3Error,\n} from 'h3'\n\n/**\n * Create a new FormData object.\n *\n * @returns A FormData object.\n */\nexport function formData(): FormData {\n return new FormData()\n}\n\nexport type Response = ReturnType<typeof nodeFetch>\n\n/**\n * An interface that abstracts way node-fetch. When Node has built-in\n * support for \"fetch\" in the standard library, we can drop the node-fetch\n * dependency from here.\n * Note that we are exposing types from \"node-fetch\". The reason being is that\n * they are consistent with the Web API so if we drop node-fetch in the future\n * it won't require changes from the callers.\n *\n * @param url - This defines the resource that you wish to fetch.\n * @param init - An object containing any custom settings that you want to apply to the request.\n * @returns A promise that resolves with the response.\n */\nexport async function fetch(url: RequestInfo, init?: RequestInit): Response {\n const response = await nodeFetch(url, init)\n return response\n}\n\n/**\n * A fetch function to use with Shopify services. The function ensures the right\n * TLS configuragion is used based on the environment in which the service is running\n * (e.g. Spin).\n *\n * @param url - This defines the resource that you wish to fetch.\n * @param init - An object containing any custom settings that you want to apply to the request.\n * @returns A promise that resolves with the response.\n */\nexport async function shopifyFetch(url: RequestInfo, init?: RequestInit): Response {\n const options: RequestInit = {\n ...(init ?? {}),\n headers: {\n ...(await buildHeaders()),\n ...(init?.headers ?? {}),\n },\n }\n\n debug(content`\nSending ${options.method ?? 'GET'} request to URL ${url.toString()} and headers:\n${sanitizedHeadersOutput((options?.headers ?? {}) as {[header: string]: string})}\n`)\n const t0 = performance.now()\n const response = await nodeFetch(url, {...init, agent: await httpsAgent()})\n const t1 = performance.now()\n debug(`Request to ${url.toString()} completed with status ${response.status} in ${Math.round(t1 - t0)} ms`)\n return response\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mkdir, readFile, copyFile, chmod, isDirectory, writeFile, fileHasExecutablePermissions, glob } from './fs.js';
|
|
2
|
+
import { joinPath, dirname, relativePath } from './path.js';
|
|
3
3
|
import { content, token, debug } from '../../output.js';
|
|
4
4
|
import { Liquid } from 'liquidjs';
|
|
5
5
|
/**
|
|
@@ -25,30 +25,30 @@ export function renderLiquidTemplate(templateContent, data) {
|
|
|
25
25
|
*/
|
|
26
26
|
export async function recursiveLiquidTemplateCopy(from, to, data) {
|
|
27
27
|
debug(content `Copying template from directory ${token.path(from)} to ${token.path(to)}`);
|
|
28
|
-
const templateFiles = await glob(
|
|
28
|
+
const templateFiles = await glob(joinPath(from, '**/*'), { dot: true });
|
|
29
29
|
const sortedTemplateFiles = templateFiles
|
|
30
30
|
.map((path) => path.split('/'))
|
|
31
31
|
.sort((lhs, rhs) => (lhs.length < rhs.length ? 1 : -1))
|
|
32
32
|
.map((components) => components.join('/'));
|
|
33
33
|
await Promise.all(sortedTemplateFiles.map(async (templateItemPath) => {
|
|
34
|
-
const outputPath = await renderLiquidTemplate(
|
|
34
|
+
const outputPath = await renderLiquidTemplate(joinPath(to, relativePath(from, templateItemPath)), data);
|
|
35
35
|
if (await isDirectory(templateItemPath)) {
|
|
36
36
|
await mkdir(outputPath);
|
|
37
37
|
}
|
|
38
38
|
else if (templateItemPath.endsWith('.liquid')) {
|
|
39
39
|
await mkdir(dirname(outputPath));
|
|
40
|
-
const content = await
|
|
40
|
+
const content = await readFile(templateItemPath);
|
|
41
41
|
const contentOutput = await renderLiquidTemplate(content, data);
|
|
42
|
-
const isExecutable = await
|
|
42
|
+
const isExecutable = await fileHasExecutablePermissions(templateItemPath);
|
|
43
43
|
const outputPathWithoutLiquid = outputPath.replace('.liquid', '');
|
|
44
|
-
await
|
|
45
|
-
await
|
|
44
|
+
await copyFile(templateItemPath, outputPathWithoutLiquid);
|
|
45
|
+
await writeFile(outputPathWithoutLiquid, contentOutput);
|
|
46
46
|
if (isExecutable) {
|
|
47
47
|
await chmod(outputPathWithoutLiquid, 0o755);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
await
|
|
51
|
+
await copyFile(templateItemPath, outputPath);
|
|
52
52
|
}
|
|
53
53
|
}));
|
|
54
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liquid.js","sourceRoot":"","sources":["../../../src/public/node/liquid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"liquid.js","sourceRoot":"","sources":["../../../src/public/node/liquid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,4BAA4B,EAAE,IAAI,EAAC,MAAM,SAAS,CAAA;AACpH,OAAO,EAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAC,MAAM,WAAW,CAAA;AACzD,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAA;AAE/B;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,eAAuB,EAAE,IAAY;IACxE,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA;IAC3B,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,CAAA;AAC3D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,IAAY,EAAE,EAAU,EAAE,IAAY;IACtF,KAAK,CAAC,OAAO,CAAA,mCAAmC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;IACxF,MAAM,aAAa,GAAa,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAC,GAAG,EAAE,IAAI,EAAC,CAAC,CAAA;IAE/E,MAAM,mBAAmB,GAAG,aAAa;SACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAA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MAAM,QAAQ,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAA;SAC7C;IACH,CAAC,CAAC,CACH,CAAA;AACH,CAAC","sourcesContent":["import {mkdir, readFile, copyFile, chmod, isDirectory, writeFile, fileHasExecutablePermissions, glob} from './fs.js'\nimport {joinPath, dirname, relativePath} from './path.js'\nimport {content, token, debug} from '../../output.js'\nimport {Liquid} from 'liquidjs'\n\n/**\n * Renders a template using the Liquid template engine.\n *\n * @param templateContent - Template content.\n * @param data - Data to feed the template engine.\n * @returns Rendered template.\n */\nexport function renderLiquidTemplate(templateContent: string, data: object): Promise<string> {\n const engine = new Liquid()\n return engine.render(engine.parse(templateContent), data)\n}\n\n/**\n * Given a directory, it traverses the files and directories recursively\n * and replaces variables in directory and file names, and files' content\n * using the Liquid template engine.\n * Files indicate that they are liquid template by using the .liquid extension.\n *\n * @param from - Directory that contains the template.\n * @param to - Output directory.\n * @param data - Data to feed the template engine.\n */\nexport async function recursiveLiquidTemplateCopy(from: string, to: string, data: object): Promise<void> {\n debug(content`Copying template from directory ${token.path(from)} to ${token.path(to)}`)\n const templateFiles: string[] = await glob(joinPath(from, '**/*'), {dot: true})\n\n const sortedTemplateFiles = templateFiles\n .map((path) => path.split('/'))\n .sort((lhs, rhs) => (lhs.length < rhs.length ? 1 : -1))\n .map((components) => components.join('/'))\n await Promise.all(\n sortedTemplateFiles.map(async (templateItemPath) => {\n const outputPath = await renderLiquidTemplate(joinPath(to, relativePath(from, templateItemPath)), data)\n if (await isDirectory(templateItemPath)) {\n await mkdir(outputPath)\n } else if (templateItemPath.endsWith('.liquid')) {\n await mkdir(dirname(outputPath))\n const content = await readFile(templateItemPath)\n const contentOutput = await renderLiquidTemplate(content, data)\n const isExecutable = await fileHasExecutablePermissions(templateItemPath)\n const outputPathWithoutLiquid = outputPath.replace('.liquid', '')\n await copyFile(templateItemPath, outputPathWithoutLiquid)\n await writeFile(outputPathWithoutLiquid, contentOutput)\n if (isExecutable) {\n await chmod(outputPathWithoutLiquid, 0o755)\n }\n } else {\n await copyFile(templateItemPath, outputPath)\n }\n }),\n )\n}\n"]}
|
|
@@ -118,10 +118,20 @@ export interface PackageJson {
|
|
|
118
118
|
* The name attribute of the package.json
|
|
119
119
|
*/
|
|
120
120
|
name?: string;
|
|
121
|
+
/**
|
|
122
|
+
* The author attribute of the package.json
|
|
123
|
+
*/
|
|
124
|
+
author?: string;
|
|
121
125
|
/**
|
|
122
126
|
* The version attribute of the package.json
|
|
123
127
|
*/
|
|
124
128
|
version?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The scripts attribute of the package.json
|
|
131
|
+
*/
|
|
132
|
+
scripts?: {
|
|
133
|
+
[key: string]: string;
|
|
134
|
+
};
|
|
125
135
|
/**
|
|
126
136
|
* The dependencies attribute of the package.json
|
|
127
137
|
*/
|
|
@@ -156,6 +166,10 @@ export interface PackageJson {
|
|
|
156
166
|
overrides?: {
|
|
157
167
|
[key: string]: string;
|
|
158
168
|
};
|
|
169
|
+
/**
|
|
170
|
+
* The prettier attribute of the package.json
|
|
171
|
+
*/
|
|
172
|
+
prettier?: string;
|
|
159
173
|
}
|
|
160
174
|
/**
|
|
161
175
|
* Reads and parses a package.json
|
|
@@ -225,19 +239,16 @@ export declare function addNPMDependenciesWithoutVersionIfNeeded(dependencies: s
|
|
|
225
239
|
*/
|
|
226
240
|
export declare function findUpAndReadPackageJson(fromDirectory: string): Promise<{
|
|
227
241
|
path: string;
|
|
228
|
-
content:
|
|
242
|
+
content: PackageJson;
|
|
229
243
|
}>;
|
|
230
244
|
export declare function addResolutionOrOverride(directory: string, dependencies: {
|
|
231
245
|
[key: string]: string;
|
|
232
246
|
}): Promise<void>;
|
|
233
|
-
interface FindPackageVersionUpOptions {
|
|
234
|
-
fromModuleURL: import('url').URL | string;
|
|
235
|
-
}
|
|
236
247
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* @param
|
|
240
|
-
* @
|
|
248
|
+
* Writes the package.json file to the given directory.
|
|
249
|
+
*
|
|
250
|
+
* @param directory - Directory where the package.json file will be written.
|
|
251
|
+
* @param packageJSON - Package.json file to write.
|
|
241
252
|
*/
|
|
242
|
-
export declare function
|
|
253
|
+
export declare function writePackageJSON(directory: string, packageJSON: PackageJson): Promise<void>;
|
|
243
254
|
export {};
|