@sanity/cli 6.0.0-alpha.7 → 6.0.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -75
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js +2 -1
- package/dist/actions/build/renderDocumentWorker/tryLoadDocumentComponent.js.map +1 -1
- package/dist/actions/init/bootstrapLocalTemplate.d.ts +13 -0
- package/dist/actions/init/bootstrapLocalTemplate.js +136 -0
- package/dist/actions/init/bootstrapLocalTemplate.js.map +1 -0
- package/dist/actions/init/bootstrapRemoteTemplate.d.ts +12 -0
- package/dist/actions/init/bootstrapRemoteTemplate.js +109 -0
- package/dist/actions/init/bootstrapRemoteTemplate.js.map +1 -0
- package/dist/actions/init/bootstrapTemplate.d.ts +18 -0
- package/dist/actions/init/bootstrapTemplate.js +32 -0
- package/dist/actions/init/bootstrapTemplate.js.map +1 -0
- package/dist/actions/init/checkNextJsReactCompatibility.d.ts +9 -0
- package/dist/actions/init/checkNextJsReactCompatibility.js +21 -0
- package/dist/actions/init/checkNextJsReactCompatibility.js.map +1 -0
- package/dist/actions/init/countNestedFolders.d.ts +1 -0
- package/dist/actions/init/countNestedFolders.js +6 -0
- package/dist/actions/init/countNestedFolders.js.map +1 -0
- package/dist/actions/init/createAppCliConfig.d.ts +5 -0
- package/dist/actions/init/createAppCliConfig.js +19 -0
- package/dist/actions/init/createAppCliConfig.js.map +1 -0
- package/dist/actions/init/createCliConfig.d.ts +6 -0
- package/dist/actions/init/createCliConfig.js +27 -0
- package/dist/actions/init/createCliConfig.js.map +1 -0
- package/dist/actions/init/createPackageManifest.d.ts +6 -0
- package/dist/actions/init/createPackageManifest.js +86 -0
- package/dist/actions/init/createPackageManifest.js.map +1 -0
- package/dist/actions/init/createStudioConfig.d.ts +13 -0
- package/dist/actions/init/createStudioConfig.js +41 -0
- package/dist/actions/init/createStudioConfig.js.map +1 -0
- package/dist/actions/init/env/createOrAppendEnvVars.d.ts +12 -0
- package/dist/actions/init/env/createOrAppendEnvVars.js +25 -0
- package/dist/actions/init/env/createOrAppendEnvVars.js.map +1 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.d.ts +9 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.js +42 -0
- package/dist/actions/init/env/parseAndUpdateEnvVars.js.map +1 -0
- package/dist/actions/init/env/writeEnvVarsToFile.d.ts +12 -0
- package/dist/actions/init/env/writeEnvVarsToFile.js +49 -0
- package/dist/actions/init/env/writeEnvVarsToFile.js.map +1 -0
- package/dist/actions/init/fetchPostInitPrompt.d.ts +6 -0
- package/dist/actions/init/fetchPostInitPrompt.js +30 -0
- package/dist/actions/init/fetchPostInitPrompt.js.map +1 -0
- package/dist/actions/init/git.d.ts +1 -0
- package/dist/actions/init/git.js +65 -0
- package/dist/actions/init/git.js.map +1 -0
- package/dist/actions/init/processTemplate.d.ts +7 -0
- package/dist/actions/init/processTemplate.js +56 -0
- package/dist/actions/init/processTemplate.js.map +1 -0
- package/dist/actions/init/remoteTemplate.d.ts +0 -3
- package/dist/actions/init/remoteTemplate.js +2 -40
- package/dist/actions/init/remoteTemplate.js.map +1 -1
- package/dist/actions/init/resolvePackageManager.d.ts +10 -0
- package/dist/actions/init/resolvePackageManager.js +20 -0
- package/dist/actions/init/resolvePackageManager.js.map +1 -0
- package/dist/actions/init/setupMCP.d.ts +21 -0
- package/dist/actions/init/setupMCP.js +258 -0
- package/dist/actions/init/setupMCP.js.map +1 -0
- package/dist/actions/init/templates/appQuickstart.d.ts +3 -0
- package/dist/actions/init/templates/appQuickstart.js +28 -0
- package/dist/actions/init/templates/appQuickstart.js.map +1 -0
- package/dist/actions/init/templates/appSanityUi.d.ts +3 -0
- package/dist/actions/init/templates/appSanityUi.js +30 -0
- package/dist/actions/init/templates/appSanityUi.js.map +1 -0
- package/dist/actions/init/templates/blog.d.ts +3 -0
- package/dist/actions/init/templates/blog.js +4 -0
- package/dist/actions/init/templates/blog.js.map +1 -0
- package/dist/actions/init/templates/clean.d.ts +3 -0
- package/dist/actions/init/templates/clean.js +4 -0
- package/dist/actions/init/templates/clean.js.map +1 -0
- package/dist/actions/init/templates/getStarted.d.ts +3 -0
- package/dist/actions/init/templates/getStarted.js +35 -0
- package/dist/actions/init/templates/getStarted.js.map +1 -0
- package/dist/actions/init/templates/index.d.ts +3 -0
- package/dist/actions/init/templates/index.js +23 -0
- package/dist/actions/init/templates/index.js.map +1 -0
- package/dist/actions/init/templates/moviedb.d.ts +3 -0
- package/dist/actions/init/templates/moviedb.js +34 -0
- package/dist/actions/init/templates/moviedb.js.map +1 -0
- package/dist/actions/init/templates/nextjs/index.d.ts +6 -0
- package/dist/actions/init/templates/nextjs/index.js +213 -0
- package/dist/actions/init/templates/nextjs/index.js.map +1 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.d.ts +3 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.js +247 -0
- package/dist/actions/init/templates/nextjs/schemaTypes/blog.js.map +1 -0
- package/dist/actions/init/templates/quickstart.d.ts +3 -0
- package/dist/actions/init/templates/quickstart.js +4 -0
- package/dist/actions/init/templates/quickstart.js.map +1 -0
- package/dist/actions/init/templates/shopify.d.ts +3 -0
- package/dist/actions/init/templates/shopify.js +77 -0
- package/dist/actions/init/templates/shopify.js.map +1 -0
- package/dist/actions/init/templates/shopifyOnline.d.ts +3 -0
- package/dist/actions/init/templates/shopifyOnline.js +49 -0
- package/dist/actions/init/templates/shopifyOnline.js.map +1 -0
- package/dist/actions/init/types.d.ts +15 -0
- package/dist/actions/init/types.js +3 -0
- package/dist/actions/init/types.js.map +1 -0
- package/dist/actions/init/updateInitialTemplateMetadata.d.ts +1 -0
- package/dist/actions/init/updateInitialTemplateMetadata.js +17 -0
- package/dist/actions/init/updateInitialTemplateMetadata.js.map +1 -0
- package/dist/commands/init.d.ts +24 -14
- package/dist/commands/init.js +544 -26
- package/dist/commands/init.js.map +1 -1
- package/dist/prompts/init/nextjs.d.ts +5 -0
- package/dist/prompts/init/nextjs.js +56 -0
- package/dist/prompts/init/nextjs.js.map +1 -0
- package/dist/prompts/init/promptForTypescript.d.ts +0 -1
- package/dist/prompts/init/promptForTypescript.js +0 -6
- package/dist/prompts/init/promptForTypescript.js.map +1 -1
- package/dist/services/mcp.d.ts +10 -0
- package/dist/services/mcp.js +16 -0
- package/dist/services/mcp.js.map +1 -1
- package/dist/services/projects.d.ts +5 -2
- package/dist/services/projects.js +37 -0
- package/dist/services/projects.js.map +1 -1
- package/dist/studioDependencies.d.ts +16 -0
- package/dist/studioDependencies.js +24 -0
- package/dist/studioDependencies.js.map +1 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js.map +1 -1
- package/dist/typings/deepSortObject.d.js +2 -0
- package/dist/typings/deepSortObject.d.js.map +1 -0
- package/dist/util/copy.d.ts +5 -0
- package/dist/util/copy.js +37 -0
- package/dist/util/copy.js.map +1 -0
- package/dist/util/frameworkPort.d.ts +12 -0
- package/dist/util/frameworkPort.js +61 -0
- package/dist/util/frameworkPort.js.map +1 -0
- package/dist/util/fsUtils.d.ts +2 -0
- package/dist/util/fsUtils.js +34 -0
- package/dist/util/fsUtils.js.map +1 -0
- package/dist/util/getProjectDefaults.d.ts +11 -0
- package/dist/util/getProjectDefaults.js +77 -0
- package/dist/util/getProjectDefaults.js.map +1 -0
- package/dist/util/packageManager/packageManagerChoice.d.ts +2 -0
- package/dist/util/packageManager/packageManagerChoice.js +8 -0
- package/dist/util/packageManager/packageManagerChoice.js.map +1 -1
- package/dist/util/readdirRecursive.d.ts +5 -0
- package/dist/util/readdirRecursive.js +24 -0
- package/dist/util/readdirRecursive.js.map +1 -0
- package/dist/util/resolveLatestVersions.d.ts +7 -0
- package/dist/util/resolveLatestVersions.js +21 -0
- package/dist/util/resolveLatestVersions.js.map +1 -0
- package/oclif.manifest.json +36 -29
- package/package.json +17 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/services/projects.ts"],"sourcesContent":["import {debug, getGlobalCliClient, getProjectCliClient} from '@sanity/cli-core'\n\nimport {type Invite, type Role} from '../actions/users/types.js'\n\nexport const PROJECTS_API_VERSION = '2025-09-22'\n\nexport const CREATE_PROJECT_API_VERSION = 'v2025-05-14'\n\nexport interface CreateProjectOptions {\n displayName: string\n\n metadata?: {\n coupon?: string\n integration?: string\n }\n organizationId?: string\n subscription?: {planId: string}\n}\n\nexport interface CreateProjectResult {\n displayName: string\n projectId: string\n}\n\n/**\n * Create a new Sanity project\n */\nexport async function createProject(options: CreateProjectOptions): Promise<CreateProjectResult> {\n const client = await getGlobalCliClient({\n apiVersion: CREATE_PROJECT_API_VERSION,\n requireUser: true,\n })\n\n try {\n const response = await client.request({\n body: {\n ...options,\n metadata: {\n ...options?.metadata,\n integration: 'cli',\n },\n },\n method: 'POST',\n uri: '/projects',\n })\n\n return {\n displayName: options.displayName || '',\n projectId: response.projectId || response.id,\n }\n } catch (err) {\n debug('Error creating project', err)\n throw err\n }\n}\n\nexport async function getProjectById(projectId: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n return client.projects.getById(projectId)\n}\n\nexport async function getProjectRoles(projectId: string) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<Role[]>({uri: `/projects/${projectId}/roles`})\n}\n\ninterface InviteUserOptions {\n email: string\n projectId: string\n role: string\n}\n\nexport async function inviteUser({email, projectId, role}: InviteUserOptions) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request({\n body: {email, role},\n maxRedirects: 0,\n method: 'POST',\n uri: `/invitations/project/${projectId}`,\n useGlobalApi: true,\n })\n}\n\nexport async function listProjects() {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.projects.list()\n}\n\nexport async function getProjectInvites(projectId: string) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<Invite[]>({uri: `/invitations/project/${projectId}`})\n}\n"],"names":["debug","getGlobalCliClient","getProjectCliClient","PROJECTS_API_VERSION","CREATE_PROJECT_API_VERSION","createProject","options","client","apiVersion","requireUser","response","request","body","metadata","integration","method","uri","displayName","projectId","id","err","getProjectById","projects","getById","getProjectRoles","inviteUser","email","role","maxRedirects","useGlobalApi","listProjects","list","getProjectInvites"],"mappings":"AAAA,SAAQA,KAAK,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAO,mBAAkB;
|
|
1
|
+
{"version":3,"sources":["../../src/services/projects.ts"],"sourcesContent":["import {debug, getGlobalCliClient, getProjectCliClient} from '@sanity/cli-core'\nimport {SanityProject} from '@sanity/client'\n\nimport {type Invite, type Role} from '../actions/users/types.js'\n\nexport const PROJECTS_API_VERSION = '2025-09-22'\n\nexport const CREATE_PROJECT_API_VERSION = 'v2025-05-14'\n\nexport interface CreateProjectOptions {\n displayName: string\n\n metadata?: {\n coupon?: string\n integration?: string\n }\n organizationId?: string\n subscription?: {planId: string}\n}\n\nexport interface CreateProjectResult {\n displayName: string\n projectId: string\n}\n\n/**\n * Create a new Sanity project\n */\nexport async function createProject(options: CreateProjectOptions): Promise<CreateProjectResult> {\n const client = await getGlobalCliClient({\n apiVersion: CREATE_PROJECT_API_VERSION,\n requireUser: true,\n })\n\n try {\n const response = await client.request({\n body: {\n ...options,\n metadata: {\n ...options?.metadata,\n integration: 'cli',\n },\n },\n method: 'POST',\n uri: '/projects',\n })\n\n return {\n displayName: options.displayName || '',\n projectId: response.projectId || response.id,\n }\n } catch (err) {\n debug('Error creating project', err)\n throw err\n }\n}\n\nexport async function getProjectById(projectId: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n return client.projects.getById(projectId)\n}\n\nexport async function getProjectRoles(projectId: string) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<Role[]>({uri: `/projects/${projectId}/roles`})\n}\n\ninterface InviteUserOptions {\n email: string\n projectId: string\n role: string\n}\n\nexport async function inviteUser({email, projectId, role}: InviteUserOptions) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request({\n body: {email, role},\n maxRedirects: 0,\n method: 'POST',\n uri: `/invitations/project/${projectId}`,\n useGlobalApi: true,\n })\n}\n\nexport async function listProjects() {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.projects.list()\n}\n\nexport async function getProjectInvites(projectId: string) {\n const client = await getGlobalCliClient({\n apiVersion: PROJECTS_API_VERSION,\n requireUser: true,\n })\n\n return client.request<Invite[]>({uri: `/invitations/project/${projectId}`})\n}\n\nexport async function updateProjectInitializedAt(projectId: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n const project = await client.request<SanityProject>({uri: `/projects/${projectId}`})\n\n if (!project?.metadata?.cliInitializedAt) {\n await client.request({\n body: {metadata: {cliInitializedAt: new Date().toISOString()}},\n method: 'PATCH',\n uri: `/projects/${projectId}`,\n })\n }\n}\n\nexport async function updateProjectInitalTemplate(projectId: string, templateName: string) {\n const client = await getProjectCliClient({\n apiVersion: PROJECTS_API_VERSION,\n projectId,\n requireUser: true,\n })\n\n await client.request({\n body: {metadata: {initialTemplate: templateName}},\n method: 'PATCH',\n uri: `/projects/${projectId}`,\n })\n}\n"],"names":["debug","getGlobalCliClient","getProjectCliClient","PROJECTS_API_VERSION","CREATE_PROJECT_API_VERSION","createProject","options","client","apiVersion","requireUser","response","request","body","metadata","integration","method","uri","displayName","projectId","id","err","getProjectById","projects","getById","getProjectRoles","inviteUser","email","role","maxRedirects","useGlobalApi","listProjects","list","getProjectInvites","updateProjectInitializedAt","project","cliInitializedAt","Date","toISOString","updateProjectInitalTemplate","templ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B,EAAEE,WAAW;QACxCW,cAAc;IAChB;AACF;AAEA,OAAO,eAAeC;IACpB,MAAMvB,SAAS,MAAMN,mBAAmB;QACtCO,YAAYL;QACZM,aAAa;IACf;IAEA,OAAOF,OAAOe,QAAQ,CAACS,IAAI;AAC7B;AAEA,OAAO,eAAeC,kBAAkBd,SAAiB;IACvD,MAAMX,SAAS,MAAMN,mBAAmB;QACtCO,YAAYL;QACZM,aAAa;IACf;IAEA,OAAOF,OAAOI,OAAO,CAAW;QAACK,KAAK,CAAC,qBAAqB,EAAEE,WAAW;IAAA;AAC3E;AAEA,OAAO,eAAee,2BAA2Bf,SAAiB;IAChE,MAAMX,SAAS,MAAML,oBAAoB;QACvCM,YAAYL;QACZe;QACAT,aAAa;IACf;IAEA,MAAMyB,UAAU,MAAM3B,OAAOI,OAAO,CAAgB;QAACK,KAAK,CAAC,UAAU,EAAEE,WAAW;IAAA;IAElF,IAAI,CAACgB,SAASrB,UAAUsB,kBAAkB;QACxC,MAAM5B,OAAOI,OAAO,CAAC;YACnBC,MAAM;gBAACC,UAAU;oBAACsB,kBAAkB,IAAIC,OAAOC,WAAW;gBAAE;YAAC;YAC7DtB,QAAQ;YACRC,KAAK,CAAC,UAAU,EAAEE,WAAW;QAC/B;IACF;AACF;AAEA,OAAO,eAAeoB,4BAA4BpB,SAAiB,EAAEqB,YAAoB;IACvF,MAAMhC,SAAS,MAAML,oBAAoB;QACvCM,YAAYL;QACZe;QACAT,aAAa;IACf;IAEA,MAAMF,OAAOI,OAAO,CAAC;QACnBC,MAAM;YAACC,UAAU;gBAAC2B,iBAAiBD;YAAY;QAAC;QAChDxB,QAAQ;QACRC,KAAK,CAAC,UAAU,EAAEE,WAAW;IAC/B;AACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const studioDependencies: {
|
|
2
|
+
dependencies: {
|
|
3
|
+
sanity: string;
|
|
4
|
+
'@sanity/vision': string;
|
|
5
|
+
react: string;
|
|
6
|
+
'react-dom': string;
|
|
7
|
+
'styled-components': string;
|
|
8
|
+
};
|
|
9
|
+
devDependencies: {
|
|
10
|
+
'@sanity/eslint-config-studio': string;
|
|
11
|
+
'@types/react': string;
|
|
12
|
+
eslint: string;
|
|
13
|
+
prettier: string;
|
|
14
|
+
typescript: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const studioDependencies = {
|
|
2
|
+
// Dependencies for a default Sanity installation
|
|
3
|
+
dependencies: {
|
|
4
|
+
// Official studio dependencies
|
|
5
|
+
sanity: 'latest',
|
|
6
|
+
// Official studio plugin dependencies
|
|
7
|
+
'@sanity/vision': 'latest',
|
|
8
|
+
// Non-Sanity dependencies
|
|
9
|
+
react: '^19.1',
|
|
10
|
+
'react-dom': '^19.1',
|
|
11
|
+
'styled-components': '^6.1.18'
|
|
12
|
+
},
|
|
13
|
+
devDependencies: {
|
|
14
|
+
// Linting/tooling
|
|
15
|
+
'@sanity/eslint-config-studio': 'latest',
|
|
16
|
+
// When using typescript, we'll want the these types too, so might as well install them
|
|
17
|
+
'@types/react': '^19.1',
|
|
18
|
+
eslint: '^9.28',
|
|
19
|
+
prettier: '^3.5',
|
|
20
|
+
typescript: '^5.8'
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=studioDependencies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/studioDependencies.ts"],"sourcesContent":["export const studioDependencies = {\n // Dependencies for a default Sanity installation\n dependencies: {\n // Official studio dependencies\n sanity: 'latest',\n\n // Official studio plugin dependencies\n '@sanity/vision': 'latest',\n\n // Non-Sanity dependencies\n react: '^19.1',\n 'react-dom': '^19.1',\n 'styled-components': '^6.1.18',\n },\n\n devDependencies: {\n // Linting/tooling\n '@sanity/eslint-config-studio': 'latest',\n // When using typescript, we'll want the these types too, so might as well install them\n '@types/react': '^19.1',\n eslint: '^9.28',\n prettier: '^3.5',\n typescript: '^5.8', // Peer dependency of eslint-config-studio (implicitly)\n },\n}\n"],"names":["studioDependencies","dependencies","sanity","react","devDependencies","eslint","prettier","typescript"],"mappings":"AAAA,OAAO,MAAMA,qBAAqB;IAChC,iDAAiD;IACjDC,cAAc;QACZ,+BAA+B;QAC/BC,QAAQ;QAER,sCAAsC;QACtC,kBAAkB;QAElB,0BAA0B;QAC1BC,OAAO;QACP,aAAa;QACb,qBAAqB;IACvB;IAEAC,iBAAiB;QACf,kBAAkB;QAClB,gCAAgC;QAChC,uFAAuF;QACvF,gBAAgB;QAChBC,QAAQ;QACRC,UAAU;QACVC,YAAY;IACd;AACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -14,3 +14,36 @@ export interface PackageJson {
|
|
|
14
14
|
};
|
|
15
15
|
scripts?: Record<string, string>;
|
|
16
16
|
}
|
|
17
|
+
export interface CliApiConfig {
|
|
18
|
+
dataset?: string;
|
|
19
|
+
projectId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SanityJson {
|
|
22
|
+
__experimental_spaces?: {
|
|
23
|
+
api: {
|
|
24
|
+
dataset?: string;
|
|
25
|
+
projectId?: string;
|
|
26
|
+
};
|
|
27
|
+
default?: true;
|
|
28
|
+
name: string;
|
|
29
|
+
title: string;
|
|
30
|
+
}[];
|
|
31
|
+
api?: CliApiConfig;
|
|
32
|
+
env?: {
|
|
33
|
+
development?: SanityJson;
|
|
34
|
+
production?: SanityJson;
|
|
35
|
+
staging?: SanityJson;
|
|
36
|
+
};
|
|
37
|
+
parts?: {
|
|
38
|
+
description?: string;
|
|
39
|
+
implements?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
}[];
|
|
43
|
+
plugins?: string[];
|
|
44
|
+
project?: {
|
|
45
|
+
basePath?: string;
|
|
46
|
+
name?: string;
|
|
47
|
+
};
|
|
48
|
+
root?: boolean;
|
|
49
|
+
}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface PackageJson {\n name: string\n version: string\n\n author?: string\n\n dependencies?: Record<string, string>\n description?: string\n devDependencies?: Record<string, string>\n license?: string\n\n peerDependencies?: Record<string, string>\n private?: boolean\n repository?: {type: string; url: string}\n\n scripts?: Record<string, string>\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["export interface PackageJson {\n name: string\n version: string\n\n author?: string\n\n dependencies?: Record<string, string>\n description?: string\n devDependencies?: Record<string, string>\n license?: string\n\n peerDependencies?: Record<string, string>\n private?: boolean\n repository?: {type: string; url: string}\n\n scripts?: Record<string, string>\n}\n\nexport interface CliApiConfig {\n dataset?: string\n projectId?: string\n}\n\nexport interface SanityJson {\n __experimental_spaces?: {\n api: {\n dataset?: string\n projectId?: string\n }\n default?: true\n name: string\n title: string\n }[]\n api?: CliApiConfig\n env?: {\n development?: SanityJson\n production?: SanityJson\n staging?: SanityJson\n }\n parts?: {\n description?: string\n implements?: string\n name?: string\n path?: string\n }[]\n plugins?: string[]\n project?: {\n basePath?: string\n name?: string\n }\n root?: boolean\n}\n"],"names":[],"mappings":"AAuBA,WA4BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/typings/deepSortObject.d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readdirRecursive } from './readdirRecursive.js';
|
|
4
|
+
export async function copy(srcPath, dstPath, options) {
|
|
5
|
+
const rename = options?.rename;
|
|
6
|
+
const content = (await fs.stat(srcPath)).isDirectory() ? await readdirRecursive(srcPath) : [
|
|
7
|
+
{
|
|
8
|
+
isDir: false,
|
|
9
|
+
path: srcPath
|
|
10
|
+
}
|
|
11
|
+
];
|
|
12
|
+
const directories = content.filter((entry)=>entry.isDir).toSorted((a, b)=>b.path.length - a.path.length).toSorted((a, b)=>a.path.localeCompare(b.path)).map((entry)=>entry.path);
|
|
13
|
+
for (const subDir of directories){
|
|
14
|
+
const relativePath = path.relative(srcPath, subDir);
|
|
15
|
+
const fullDstPath = path.join(dstPath, relativePath);
|
|
16
|
+
await fs.mkdir(fullDstPath, {
|
|
17
|
+
recursive: true
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const files = content.filter((entry)=>!entry.isDir).toSorted((a, b)=>b.path.length - a.path.length).toSorted((a, b)=>a.path.localeCompare(b.path)).map((entry)=>{
|
|
21
|
+
const relativePath = path.relative(srcPath, entry.path);
|
|
22
|
+
const baseName = path.basename(relativePath);
|
|
23
|
+
const dirName = path.dirname(relativePath);
|
|
24
|
+
const dstName = rename ? rename(baseName) : baseName;
|
|
25
|
+
const fullDstPath = path.join(dstPath, dirName, dstName);
|
|
26
|
+
return {
|
|
27
|
+
from: entry.path,
|
|
28
|
+
to: fullDstPath
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
for (const file of files){
|
|
32
|
+
await fs.copyFile(file.from, file.to);
|
|
33
|
+
}
|
|
34
|
+
return files.length;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/copy.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport {readdirRecursive} from './readdirRecursive.js'\n\ninterface CopyOptions {\n rename?: (originalName: string) => string\n}\n\nexport async function copy(\n srcPath: string,\n dstPath: string,\n options?: CopyOptions,\n): Promise<number> {\n const rename = options?.rename\n const content = (await fs.stat(srcPath)).isDirectory()\n ? await readdirRecursive(srcPath)\n : [{isDir: false, path: srcPath}]\n\n const directories = content\n .filter((entry) => entry.isDir)\n .toSorted((a, b) => b.path.length - a.path.length)\n .toSorted((a, b) => a.path.localeCompare(b.path))\n .map((entry) => entry.path)\n\n for (const subDir of directories) {\n const relativePath = path.relative(srcPath, subDir)\n const fullDstPath = path.join(dstPath, relativePath)\n await fs.mkdir(fullDstPath, {recursive: true})\n }\n\n const files = content\n .filter((entry) => !entry.isDir)\n .toSorted((a, b) => b.path.length - a.path.length)\n .toSorted((a, b) => a.path.localeCompare(b.path))\n .map((entry) => {\n const relativePath = path.relative(srcPath, entry.path)\n const baseName = path.basename(relativePath)\n const dirName = path.dirname(relativePath)\n const dstName = rename ? rename(baseName) : baseName\n const fullDstPath = path.join(dstPath, dirName, dstName)\n return {from: entry.path, to: fullDstPath}\n })\n\n for (const file of files) {\n await fs.copyFile(file.from, file.to)\n }\n\n return files.length\n}\n"],"names":["fs","path","readdirRecursive","copy","srcPath","dstPath","options","rename","content","stat","isDirectory","isDir","directories","filter","entry","toSorted","a","b","length","localeCompare","map","subDir","relativePath","relative","fullDstPath","join","mkdir","recursive","files","baseName","basename","dirName","dirname","dstName","from","to","file","copyFile"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,SAAQC,gBAAgB,QAAO,wBAAuB;AAMtD,OAAO,eAAeC,KACpBC,OAAe,EACfC,OAAe,EACfC,OAAqB;IAErB,MAAMC,SAASD,SAASC;IACxB,MAAMC,UAAU,AAAC,CAAA,MAAMR,GAAGS,IAAI,CAACL,QAAO,EAAGM,WAAW,KAChD,MAAMR,iBAAiBE,WACvB;QAAC;YAACO,OAAO;YAAOV,MAAMG;QAAO;KAAE;IAEnC,MAAMQ,cAAcJ,QACjBK,MAAM,CAAC,CAACC,QAAUA,MAAMH,KAAK,EAC7BI,QAAQ,CAAC,CAACC,GAAGC,IAAMA,EAAEhB,IAAI,CAACiB,MAAM,GAAGF,EAAEf,IAAI,CAACiB,MAAM,EAChDH,QAAQ,CAAC,CAACC,GAAGC,IAAMD,EAAEf,IAAI,CAACkB,aAAa,CAACF,EAAEhB,IAAI,GAC9CmB,GAAG,CAAC,CAACN,QAAUA,MAAMb,IAAI;IAE5B,KAAK,MAAMoB,UAAUT,YAAa;QAChC,MAAMU,eAAerB,KAAKsB,QAAQ,CAACnB,SAASiB;QAC5C,MAAMG,cAAcvB,KAAKwB,IAAI,CAACpB,SAASiB;QACvC,MAAMtB,GAAG0B,KAAK,CAACF,aAAa;YAACG,WAAW;QAAI;IAC9C;IAEA,MAAMC,QAAQpB,QACXK,MAAM,CAAC,CAACC,QAAU,CAACA,MAAMH,KAAK,EAC9BI,QAAQ,CAAC,CAACC,GAAGC,IAAMA,EAAEhB,IAAI,CAACiB,MAAM,GAAGF,EAAEf,IAAI,CAACiB,MAAM,EAChDH,QAAQ,CAAC,CAACC,GAAGC,IAAMD,EAAEf,IAAI,CAACkB,aAAa,CAACF,EAAEhB,IAAI,GAC9CmB,GAAG,CAAC,CAACN;QACJ,MAAMQ,eAAerB,KAAKsB,QAAQ,CAACnB,SAASU,MAAMb,IAAI;QACtD,MAAM4B,WAAW5B,KAAK6B,QAAQ,CAACR;QAC/B,MAAMS,UAAU9B,KAAK+B,OAAO,CAACV;QAC7B,MAAMW,UAAU1B,SAASA,OAAOsB,YAAYA;QAC5C,MAAML,cAAcvB,KAAKwB,IAAI,CAACpB,SAAS0B,SAASE;QAChD,OAAO;YAACC,MAAMpB,MAAMb,IAAI;YAAEkC,IAAIX;QAAW;IAC3C;IAEF,KAAK,MAAMY,QAAQR,MAAO;QACxB,MAAM5B,GAAGqC,QAAQ,CAACD,KAAKF,IAAI,EAAEE,KAAKD,EAAE;IACtC;IAEA,OAAOP,MAAMV,MAAM;AACrB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the default development port for a given framework.
|
|
3
|
+
* Contains default ports for all frameworks supported by `@vercel/frameworks`.
|
|
4
|
+
* Falls back to port 3000 if framework is not found or not specified.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/vercel/vercel/blob/main/packages/frameworks/src/frameworks.ts
|
|
7
|
+
* for the complete list of supported frameworks
|
|
8
|
+
*
|
|
9
|
+
* @param frameworkSlug - The framework identifier from `@vercel/frameworks`
|
|
10
|
+
* @returns The default port number for the framework
|
|
11
|
+
*/
|
|
12
|
+
export declare function getDefaultPortForFramework(frameworkSlug?: string | null): number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const FALLBACK_PORT = 3000;
|
|
2
|
+
const portMap = {
|
|
3
|
+
angular: 4200,
|
|
4
|
+
astro: 4321,
|
|
5
|
+
blitzjs: 3000,
|
|
6
|
+
brunch: 3333,
|
|
7
|
+
'create-react-app': 3000,
|
|
8
|
+
docusaurus: 3000,
|
|
9
|
+
'docusaurus-2': 3000,
|
|
10
|
+
dojo: 3000,
|
|
11
|
+
eleventy: 8080,
|
|
12
|
+
ember: 4200,
|
|
13
|
+
fasthtml: 8000,
|
|
14
|
+
gatsby: 8000,
|
|
15
|
+
gridsome: 8080,
|
|
16
|
+
hexo: 4000,
|
|
17
|
+
hugo: 1313,
|
|
18
|
+
hydrogen: 3000,
|
|
19
|
+
'ionic-angular': 4200,
|
|
20
|
+
'ionic-react': 3000,
|
|
21
|
+
jekyll: 4000,
|
|
22
|
+
middleman: 4567,
|
|
23
|
+
nextjs: 3000,
|
|
24
|
+
nuxtjs: 3000,
|
|
25
|
+
parcel: 1234,
|
|
26
|
+
polymer: 8081,
|
|
27
|
+
preact: 8080,
|
|
28
|
+
redwoodjs: 8910,
|
|
29
|
+
remix: 3000,
|
|
30
|
+
saber: 3000,
|
|
31
|
+
sanity: 3333,
|
|
32
|
+
scully: 1668,
|
|
33
|
+
solidstart: 3000,
|
|
34
|
+
'solidstart-1': 3000,
|
|
35
|
+
stencil: 3333,
|
|
36
|
+
storybook: 6006,
|
|
37
|
+
svelte: 5000,
|
|
38
|
+
sveltekit: 5173,
|
|
39
|
+
'sveltekit-1': 5173,
|
|
40
|
+
umijs: 8000,
|
|
41
|
+
vite: 5173,
|
|
42
|
+
vitepress: 5173,
|
|
43
|
+
vue: 8080,
|
|
44
|
+
vuepress: 8080,
|
|
45
|
+
zola: 1111
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Returns the default development port for a given framework.
|
|
49
|
+
* Contains default ports for all frameworks supported by `@vercel/frameworks`.
|
|
50
|
+
* Falls back to port 3000 if framework is not found or not specified.
|
|
51
|
+
*
|
|
52
|
+
* @see https://github.com/vercel/vercel/blob/main/packages/frameworks/src/frameworks.ts
|
|
53
|
+
* for the complete list of supported frameworks
|
|
54
|
+
*
|
|
55
|
+
* @param frameworkSlug - The framework identifier from `@vercel/frameworks`
|
|
56
|
+
* @returns The default port number for the framework
|
|
57
|
+
*/ export function getDefaultPortForFramework(frameworkSlug) {
|
|
58
|
+
return portMap[frameworkSlug ?? ''] ?? FALLBACK_PORT;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=frameworkPort.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/frameworkPort.ts"],"sourcesContent":["const FALLBACK_PORT = 3000\n\nconst portMap: Record<string, number> = {\n angular: 4200,\n astro: 4321,\n blitzjs: 3000,\n brunch: 3333,\n 'create-react-app': 3000,\n docusaurus: 3000,\n 'docusaurus-2': 3000,\n dojo: 3000,\n eleventy: 8080,\n ember: 4200,\n fasthtml: 8000,\n gatsby: 8000,\n gridsome: 8080,\n hexo: 4000,\n hugo: 1313,\n hydrogen: 3000,\n 'ionic-angular': 4200,\n 'ionic-react': 3000,\n jekyll: 4000,\n middleman: 4567,\n nextjs: 3000,\n nuxtjs: 3000,\n parcel: 1234,\n polymer: 8081,\n preact: 8080,\n redwoodjs: 8910,\n remix: 3000,\n saber: 3000,\n sanity: 3333,\n scully: 1668,\n solidstart: 3000,\n 'solidstart-1': 3000,\n stencil: 3333,\n storybook: 6006,\n svelte: 5000,\n sveltekit: 5173,\n 'sveltekit-1': 5173,\n umijs: 8000,\n vite: 5173,\n vitepress: 5173,\n vue: 8080,\n vuepress: 8080,\n zola: 1111,\n}\n\n/**\n * Returns the default development port for a given framework.\n * Contains default ports for all frameworks supported by `@vercel/frameworks`.\n * Falls back to port 3000 if framework is not found or not specified.\n *\n * @see https://github.com/vercel/vercel/blob/main/packages/frameworks/src/frameworks.ts\n * for the complete list of supported frameworks\n *\n * @param frameworkSlug - The framework identifier from `@vercel/frameworks`\n * @returns The default port number for the framework\n */\nexport function getDefaultPortForFramework(frameworkSlug?: string | null): number {\n return portMap[frameworkSlug ?? ''] ?? FALLBACK_PORT\n}\n"],"names":["FALLBACK_PORT","portMap","angular","astro","blitzjs","brunch","docusaurus","dojo","eleventy","ember","fasthtml","gatsby","gridsome","hexo","hugo","hydrogen","jekyll","middleman","nextjs","nuxtjs","parcel","polymer","preact","redwoodjs","remix","saber","sanity","scully","solidstart","stencil","storybook","svelte","sveltekit","umijs","vite","vitepress","vue","vuepress","zola","getDefaultPortForFramework","frameworkSlug"],"mappings":"AAAA,MAAMA,gBAAgB;AAEtB,MAAMC,UAAkC;IACtCC,SAAS;IACTC,OAAO;IACPC,SAAS;IACTC,QAAQ;IACR,oBAAoB;IACpBC,YAAY;IACZ,gBAAgB;IAChBC,MAAM;IACNC,UAAU;IACVC,OAAO;IACPC,UAAU;IACVC,QAAQ;IACRC,UAAU;IACVC,MAAM;IACNC,MAAM;IACNC,UAAU;IACV,iBAAiB;IACjB,eAAe;IACfC,QAAQ;IACRC,WAAW;IACXC,QAAQ;IACRC,QAAQ;IACRC,QAAQ;IACRC,SAAS;IACTC,QAAQ;IACRC,WAAW;IACXC,OAAO;IACPC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,YAAY;IACZ,gBAAgB;IAChBC,SAAS;IACTC,WAAW;IACXC,QAAQ;IACRC,WAAW;IACX,eAAe;IACfC,OAAO;IACPC,MAAM;IACNC,WAAW;IACXC,KAAK;IACLC,UAAU;IACVC,MAAM;AACR;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASC,2BAA2BC,aAA6B;IACtE,OAAOvC,OAAO,CAACuC,iBAAiB,GAAG,IAAIxC;AACzC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export function validateEmptyPath(dir) {
|
|
5
|
+
const checkPath = absolutify(dir);
|
|
6
|
+
return pathIsEmpty(checkPath) ? true : 'Given path is not empty';
|
|
7
|
+
}
|
|
8
|
+
export function absolutify(dir) {
|
|
9
|
+
const pathName = expandHome(dir);
|
|
10
|
+
return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName);
|
|
11
|
+
}
|
|
12
|
+
function pathIsEmpty(dir) {
|
|
13
|
+
try {
|
|
14
|
+
const content = fs.readdirSync(dir);
|
|
15
|
+
return content.length === 0;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
if (err.code === 'ENOENT') {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function expandHome(filePath) {
|
|
24
|
+
if (filePath.codePointAt(0) === 126 /* ~ */ ) {
|
|
25
|
+
if (filePath.codePointAt(1) === 43 /* + */ ) {
|
|
26
|
+
return path.join(process.cwd(), filePath.slice(2));
|
|
27
|
+
}
|
|
28
|
+
const home = os.homedir();
|
|
29
|
+
return home ? path.join(home, filePath.slice(1)) : filePath;
|
|
30
|
+
}
|
|
31
|
+
return filePath;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=fsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/fsUtils.ts"],"sourcesContent":["import fs from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport function validateEmptyPath(dir: string): string | true {\n const checkPath = absolutify(dir)\n return pathIsEmpty(checkPath) ? true : 'Given path is not empty'\n}\n\nexport function absolutify(dir: string): string {\n const pathName = expandHome(dir)\n return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName)\n}\n\nfunction pathIsEmpty(dir: string): boolean {\n try {\n const content = fs.readdirSync(dir)\n return content.length === 0\n } catch (err) {\n if (err.code === 'ENOENT') {\n return true\n }\n\n throw err\n }\n}\n\nfunction expandHome(filePath: string): string {\n if (filePath.codePointAt(0) === 126 /* ~ */) {\n if (filePath.codePointAt(1) === 43 /* + */) {\n return path.join(process.cwd(), filePath.slice(2))\n }\n\n const home = os.homedir()\n return home ? path.join(home, filePath.slice(1)) : filePath\n }\n\n return filePath\n}\n"],"names":["fs","os","path","validateEmptyPath","dir","checkPath","absolutify","pathIsEmpty","pathName","expandHome","isAbsolute","resolve","process","cwd","content","readdirSync","length","err","code","filePath","codePointAt","join","slice","home","homedir"],"mappings":"AAAA,OAAOA,QAAQ,UAAS;AACxB,OAAOC,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B,OAAO,SAASC,kBAAkBC,GAAW;IAC3C,MAAMC,YAAYC,WAAWF;IAC7B,OAAOG,YAAYF,aAAa,OAAO;AACzC;AAEA,OAAO,SAASC,WAAWF,GAAW;IACpC,MAAMI,WAAWC,WAAWL;IAC5B,OAAOF,KAAKQ,UAAU,CAACF,YAAYA,WAAWN,KAAKS,OAAO,CAACC,QAAQC,GAAG,IAAIL;AAC5E;AAEA,SAASD,YAAYH,GAAW;IAC9B,IAAI;QACF,MAAMU,UAAUd,GAAGe,WAAW,CAACX;QAC/B,OAAOU,QAAQE,MAAM,KAAK;IAC5B,EAAE,OAAOC,KAAK;QACZ,IAAIA,IAAIC,IAAI,KAAK,UAAU;YACzB,OAAO;QACT;QAEA,MAAMD;IACR;AACF;AAEA,SAASR,WAAWU,QAAgB;IAClC,IAAIA,SAASC,WAAW,CAAC,OAAO,IAAI,KAAK,KAAI;QAC3C,IAAID,SAASC,WAAW,CAAC,OAAO,GAAG,KAAK,KAAI;YAC1C,OAAOlB,KAAKmB,IAAI,CAACT,QAAQC,GAAG,IAAIM,SAASG,KAAK,CAAC;QACjD;QAEA,MAAMC,OAAOtB,GAAGuB,OAAO;QACvB,OAAOD,OAAOrB,KAAKmB,IAAI,CAACE,MAAMJ,SAASG,KAAK,CAAC,MAAMH;IACrD;IAEA,OAAOA;AACT"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ProjectDefaults {
|
|
2
|
+
author: string | undefined;
|
|
3
|
+
description: string;
|
|
4
|
+
gitRemote: string;
|
|
5
|
+
license: string;
|
|
6
|
+
projectName: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function getProjectDefaults({ isPlugin, workDir, }: {
|
|
9
|
+
isPlugin: boolean;
|
|
10
|
+
workDir: string;
|
|
11
|
+
}): Promise<ProjectDefaults>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import getGitConfig from '@rexxars/gitconfiglocal';
|
|
4
|
+
import { getCliToken, subdebug } from '@sanity/cli-core';
|
|
5
|
+
import { getGitUserInfo } from 'git-user-info';
|
|
6
|
+
import promiseProps from 'promise-props-recursive';
|
|
7
|
+
import { getCliUser } from '../services/user.js';
|
|
8
|
+
const debug = subdebug('getProjectDefaults');
|
|
9
|
+
export function getProjectDefaults({ isPlugin, workDir }) {
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const isSanityRoot = workDir === cwd;
|
|
12
|
+
return promiseProps({
|
|
13
|
+
license: 'UNLICENSED',
|
|
14
|
+
author: getUserInfo(),
|
|
15
|
+
// Don't try to use git remote from main Sanity project for plugins
|
|
16
|
+
gitRemote: isPlugin && isSanityRoot ? '' : resolveGitRemote(cwd),
|
|
17
|
+
// Don't try to guess plugin name if we're initing from Sanity root
|
|
18
|
+
projectName: isPlugin && isSanityRoot ? '' : path.basename(cwd),
|
|
19
|
+
// If we're initing a plugin, don't use description from Sanity readme
|
|
20
|
+
description: getProjectDescription({
|
|
21
|
+
isPlugin,
|
|
22
|
+
isSanityRoot,
|
|
23
|
+
outputDir: cwd
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function resolveGitRemote(cwd) {
|
|
28
|
+
try {
|
|
29
|
+
await fs.stat(path.join(cwd, '.git'));
|
|
30
|
+
const cfg = await getGitConfig(cwd);
|
|
31
|
+
return cfg.remote && cfg.remote.origin && cfg.remote.origin.url;
|
|
32
|
+
} catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function getUserInfo() {
|
|
37
|
+
const user = await getGitUserInfo();
|
|
38
|
+
if (!user) {
|
|
39
|
+
return getSanityUserInfo();
|
|
40
|
+
}
|
|
41
|
+
if (user.name && user.email) {
|
|
42
|
+
return `${user.name} <${user.email}>`;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
async function getSanityUserInfo() {
|
|
47
|
+
const hasToken = Boolean(getCliToken());
|
|
48
|
+
if (!hasToken) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const user = await getCliUser();
|
|
53
|
+
return user ? `${user.name} <${user.email}>` : undefined;
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async function getProjectDescription({ isPlugin, isSanityRoot, outputDir }) {
|
|
59
|
+
const tryResolve = isSanityRoot && !isPlugin;
|
|
60
|
+
if (!tryResolve) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
// Try to grab a project description from a standard GitHub-generated readme
|
|
64
|
+
try {
|
|
65
|
+
const readmePath = path.join(outputDir, 'README.md');
|
|
66
|
+
const readme = await fs.readFile(readmePath, {
|
|
67
|
+
encoding: 'utf8'
|
|
68
|
+
});
|
|
69
|
+
const match = readme.match(/^# .*?\n+(\w.*?)(?:$|\n)/);
|
|
70
|
+
return (match && match[1] || '').replace(/\.$/, '') || '';
|
|
71
|
+
} catch (err) {
|
|
72
|
+
debug(`Error getting project description: ${err}`);
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=getProjectDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/getProjectDefaults.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport getGitConfig from '@rexxars/gitconfiglocal'\nimport {getCliToken, subdebug} from '@sanity/cli-core'\nimport {getGitUserInfo} from 'git-user-info'\nimport promiseProps from 'promise-props-recursive'\n\nimport {getCliUser} from '../services/user.js'\n\nconst debug = subdebug('getProjectDefaults')\n\nexport interface ProjectDefaults {\n author: string | undefined\n description: string\n gitRemote: string\n license: string\n projectName: string\n}\n\nexport function getProjectDefaults({\n isPlugin,\n workDir,\n}: {\n isPlugin: boolean\n workDir: string\n}): Promise<ProjectDefaults> {\n const cwd = process.cwd()\n const isSanityRoot = workDir === cwd\n\n return promiseProps({\n license: 'UNLICENSED',\n\n author: getUserInfo(),\n\n // Don't try to use git remote from main Sanity project for plugins\n gitRemote: isPlugin && isSanityRoot ? '' : resolveGitRemote(cwd),\n\n // Don't try to guess plugin name if we're initing from Sanity root\n projectName: isPlugin && isSanityRoot ? '' : path.basename(cwd),\n\n // If we're initing a plugin, don't use description from Sanity readme\n description: getProjectDescription({isPlugin, isSanityRoot, outputDir: cwd}),\n })\n}\n\nasync function resolveGitRemote(cwd: string): Promise<string | undefined> {\n try {\n await fs.stat(path.join(cwd, '.git'))\n const cfg = await getGitConfig(cwd)\n return cfg.remote && cfg.remote.origin && cfg.remote.origin.url\n } catch {\n return undefined\n }\n}\n\nasync function getUserInfo(): Promise<string | undefined> {\n const user = await getGitUserInfo()\n if (!user) {\n return getSanityUserInfo()\n }\n\n if (user.name && user.email) {\n return `${user.name} <${user.email}>`\n }\n\n return undefined\n}\n\nasync function getSanityUserInfo(): Promise<string | undefined> {\n const hasToken = Boolean(getCliToken())\n if (!hasToken) {\n return undefined\n }\n\n try {\n const user = await getCliUser()\n return user ? `${user.name} <${user.email}>` : undefined\n } catch {\n return undefined\n }\n}\n\nasync function getProjectDescription({\n isPlugin,\n isSanityRoot,\n outputDir,\n}: {\n isPlugin: boolean\n isSanityRoot: boolean\n outputDir: string\n}): Promise<string> {\n const tryResolve = isSanityRoot && !isPlugin\n if (!tryResolve) {\n return ''\n }\n\n // Try to grab a project description from a standard GitHub-generated readme\n try {\n const readmePath = path.join(outputDir, 'README.md')\n const readme = await fs.readFile(readmePath, {encoding: 'utf8'})\n const match = readme.match(/^# .*?\\n+(\\w.*?)(?:$|\\n)/)\n return ((match && match[1]) || '').replace(/\\.$/, '') || ''\n } catch (err) {\n debug(`Error getting project description: ${err}`)\n return ''\n }\n}\n"],"names":["fs","path","getGitConfig","getCliToken","subdebug","getGitUserInfo","promiseProps","getCliUser","debug","getProjectDefaults","isPlugin","workDir","cwd","process","isSanityRoot","license","author","getUserInfo","gitRemote","resolveGitRemote","projectName","basename","description","getProjectDescription","outputDir","stat","join","cfg","remote","origin","url","undefined","user","getSanityUserInfo","name","email","hasToken","Boolean","tryResolve","readmePath","readme","readFile","encoding","match","replace","err"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAE5B,OAAOC,kBAAkB,0BAAyB;AAClD,SAAQC,WAAW,EAAEC,QAAQ,QAAO,mBAAkB;AACtD,SAAQC,cAAc,QAAO,gBAAe;AAC5C,OAAOC,kBAAkB,0BAAyB;AAElD,SAAQC,UAAU,QAAO,sBAAqB;AAE9C,MAAMC,QAAQJ,SAAS;AAUvB,OAAO,SAASK,mBAAmB,EACjCC,QAAQ,EACRC,OAAO,EAIR;IACC,MAAMC,MAAMC,QAAQD,GAAG;IACvB,MAAME,eAAeH,YAAYC;IAEjC,OAAON,aAAa;QAClBS,SAAS;QAETC,QAAQC;QAER,mEAAmE;QACnEC,WAAWR,YAAYI,eAAe,KAAKK,iBAAiBP;QAE5D,mEAAmE;QACnEQ,aAAaV,YAAYI,eAAe,KAAKb,KAAKoB,Q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AC,CAAA,AAACA,SAASA,KAAK,CAAC,EAAE,IAAK,EAAC,EAAGC,OAAO,CAAC,OAAO,OAAO;IAC3D,EAAE,OAAOC,KAAK;QACZrC,MAAM,CAAC,mCAAmC,EAAEqC,KAAK;QACjD,OAAO;IACT;AACF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type PackageManager = 'bun' | 'manual' | 'npm' | 'pnpm' | 'yarn';
|
|
2
|
+
export declare const ALLOWED_PACKAGE_MANAGERS: readonly PackageManager[];
|
|
3
|
+
export declare const allowedPackageManagersString: string;
|
|
2
4
|
/**
|
|
3
5
|
* Attempts to resolve the most optimal package manager to use to install/upgrade
|
|
4
6
|
* packages/dependencies at a given path. It does so by looking for package manager
|
|
@@ -7,6 +7,14 @@ import which from 'which';
|
|
|
7
7
|
const EXPERIMENTAL = new Set([
|
|
8
8
|
'bun'
|
|
9
9
|
]);
|
|
10
|
+
export const ALLOWED_PACKAGE_MANAGERS = [
|
|
11
|
+
'npm',
|
|
12
|
+
'yarn',
|
|
13
|
+
'pnpm',
|
|
14
|
+
'bun',
|
|
15
|
+
'manual'
|
|
16
|
+
];
|
|
17
|
+
export const allowedPackageManagersString = ALLOWED_PACKAGE_MANAGERS.join(' | ');
|
|
10
18
|
/**
|
|
11
19
|
* Attempts to resolve the most optimal package manager to use to install/upgrade
|
|
12
20
|
* packages/dependencies at a given path. It does so by looking for package manager
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/util/packageManager/packageManagerChoice.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {isInteractive} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\n// eslint-disable-next-line unicorn/no-named-default\nimport {default as preferredPM} from 'preferred-pm'\nimport which from 'which'\n\nexport type PackageManager = 'bun' | 'manual' | 'npm' | 'pnpm' | 'yarn'\n\nconst EXPERIMENTAL = new Set(['bun'])\n\n/**\n * Attempts to resolve the most optimal package manager to use to install/upgrade\n * packages/dependencies at a given path. It does so by looking for package manager\n * specific lockfiles. If it finds a lockfile belonging to a certain package manager,\n * it prioritizes this one. However, if that package manager is not installed, it will\n * prompt the user for which one they want to use and hint at the most optimal one\n * not being installed.\n *\n * Note that this function also takes local npm binary paths into account - for instance,\n * `yarn` can be installed as a dependency of the project instead of globally, and it\n * will use that is available.\n *\n * The user can also select 'manual' to skip the process and run their preferred package\n * manager manually. Commands using this function must take this `manual` choice into\n * account and act accordingly if chosen.\n *\n * @param workDir - The working directory where a lockfile is most likely to be present\n * @param options - Pass `interactive: false` to fall back to npm if most optimal is\n * not available, instead of prompting\n * @returns Object of `chosen` and, if a lockfile is found, the `mostOptimal` choice\n */\nexport async function getPackageManagerChoice(\n workDir: string,\n options: {interactive: boolean},\n): Promise<{chosen: PackageManager; mostOptimal?: PackageManager}> {\n const rootDir = workDir || process.cwd()\n const preferred = (await preferredPM(rootDir))?.name\n\n if (preferred && (await hasCommand(preferred, rootDir))) {\n // There is an optimal/preferred package manager, and the user has it installed!\n return {chosen: preferred, mostOptimal: preferred}\n }\n\n const mostLikelyPM = await getMostLikelyInstalledPackageManager(rootDir)\n const interactive =\n typeof options.interactive === 'boolean' ? options.interactive : isInteractive()\n if (!interactive) {\n // We can't ask the user for their preference, so fall back to either the one that is being run\n // or whatever is installed on the system (npm being the preferred choice).\n // Note that the most optimal choice is already picked above if available.\n return {chosen: mostLikelyPM || (await getFallback(rootDir)), mostOptimal: preferred}\n }\n\n // We can ask the user for their preference, hurray!\n const messageSuffix = preferred ? ` (preferred is ${preferred}, but is not installed)` : ''\n const installed = await getAvailablePackageManagers(rootDir)\n const chosen = await select<PackageManager>({\n choices: installed.map((pm) => ({\n name: EXPERIMENTAL.has(pm) ? `${pm} (experimental)` : pm,\n value: pm,\n })),\n default: preferred || mostLikelyPM,\n message: `Package manager to use for installing dependencies?${messageSuffix}`,\n })\n\n return {chosen, mostOptimal: preferred}\n}\n\nasync function getFallback(cwd: string): Promise<PackageManager> {\n if (await hasNpmInstalled(cwd)) {\n return 'npm'\n }\n\n if (await hasYarnInstalled(cwd)) {\n return 'yarn'\n }\n\n if (await hasPnpmInstalled(cwd)) {\n return 'pnpm'\n }\n\n if (await hasBunInstalled(cwd)) {\n return 'bun'\n }\n\n return 'manual'\n}\n\nasync function getAvailablePackageManagers(cwd: string): Promise<PackageManager[]> {\n const [npm, yarn, pnpm, bun] = await Promise.all([\n hasNpmInstalled(cwd),\n hasYarnInstalled(cwd),\n hasPnpmInstalled(cwd),\n hasBunInstalled(cwd),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm', bun && 'bun', 'manual']\n return choices.filter((pm): pm is PackageManager => pm !== false)\n}\n\nfunction hasNpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('npm', cwd)\n}\n\nfunction hasYarnInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('yarn', cwd)\n}\n\nfunction hasPnpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('pnpm', cwd)\n}\n\nfunction hasBunInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('bun', cwd)\n}\n\nfunction getNpmRunPath(cwd: string): string {\n let previous\n let cwdPath = path.resolve(cwd)\n const result: string[] = []\n\n while (previous !== cwdPath) {\n result.push(path.join(cwdPath, 'node_modules', '.bin'))\n previous = cwdPath\n cwdPath = path.resolve(cwdPath, '..')\n }\n\n result.push(path.resolve(cwd, process.execPath, '..'))\n\n const pathEnv = process.env[getPathEnvVarKey()]\n return [...result, pathEnv].join(path.delimiter)\n}\n\nexport function getPartialEnvWithNpmPath(cwd: string): NodeJS.ProcessEnv {\n const key = getPathEnvVarKey()\n return {[key]: getNpmRunPath(cwd)}\n}\n\nfunction getPathEnvVarKey(): string {\n if (process.platform !== 'win32') {\n return 'PATH'\n }\n\n return (\n Object.keys(process.env)\n .toReversed()\n .find((key) => key.toUpperCase() === 'PATH') || 'Path'\n )\n}\n\nfunction getCommandPath(cmd: string, cwd?: string): Promise<string | null> {\n const options = cwd ? {path: getNpmRunPath(cwd)} : undefined\n return which(cmd, options).catch(() => null)\n}\n\nfunction hasCommand(cmd: string, cwd?: string): Promise<boolean> {\n return getCommandPath(cmd, cwd).then((cmdPath) => cmdPath !== null)\n}\n\nasync function getMostLikelyInstalledPackageManager(\n rootDir: string,\n): Promise<PackageManager | undefined> {\n const installed = await getAvailablePackageManagers(rootDir)\n const running = getRunningPackageManager()\n return running && installed.includes(running) ? running : undefined\n}\n\nfunction getRunningPackageManager(): PackageManager | undefined {\n // Yes, the env var is lowercase - it is set by the package managers themselves\n const agent = process.env.npm_config_user_agent || ''\n\n if (agent.includes('yarn')) {\n return 'yarn'\n }\n\n if (agent.includes('pnpm')) {\n return 'pnpm'\n }\n\n if (agent.includes('bun')) {\n return 'bun'\n }\n\n // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here\n // Theoretically not needed since we check for yarn/pnpm above, but in case other\n // package managers do the same thing, we'll (hopefully) catch them here.\n if (/^npm\\/\\d/.test(agent)) {\n return 'npm'\n }\n\n return undefined\n}\n"],"names":["path","isInteractive","select","default","preferredPM","which","EXPERIMENTAL","Set","getPackageManagerChoice","workDir","options","rootDir","process","cwd","preferred","name","hasCommand","chosen","mostOptimal","mostLikelyPM","getMostLikelyInstalledPackageManager","interactive","getFallback","messageSuffix","installed","getAvailablePackageManagers","choices","map","pm","has","value","message","hasNpmInstalled","hasYarnInstalled","hasPnpmInstalled","hasBunInstalled","npm","yarn","pnpm","bun","Promise","all","filter","getNpmRunPath","previous","cwdPath","resolve","result","push","join","execPath","pathEnv","env","getPathEnvVarKey","delimiter","getPartialEnvWithNpmPath","key","platform","Object","keys","toReversed","find","toUpperCase","getCommandPath","cmd","undefined","catch","then","cmdPath","running","getRunningPackageManager","includes","agent","npm_config_user_agent","test"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,MAAM,QAAO,sBAAqB;AAC1C,oDAAoD;AACpD,SAAQC,WAAWC,WAAW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QAAC,CAACG,IAAI,EAAEb,cAAc9B;IAAI;AACnC;AAEA,SAASwC;IACP,IAAIzC,QAAQ6C,QAAQ,KAAK,SAAS;QAChC,OAAO;IACT;IAEA,OACEC,OAAOC,IAAI,CAAC/C,QAAQwC,GAAG,EACpBQ,UAAU,GACVC,IAAI,CAAC,CAACL,MAAQA,IAAIM,WAAW,OAAO,WAAW;AAEtD;AAEA,SAASC,eAAeC,GAAW,EAAEnD,GAAY;IAC/C,MAAMH,UAAUG,MAAM;QAACb,MAAM2C,cAAc9B;IAAI,IAAIoD;IACnD,OAAO5D,MAAM2D,KAAKtD,SAASwD,KAAK,CAAC,IAAM;AACzC;AAEA,SAASlD,WAAWgD,GAAW,EAAEnD,GAAY;IAC3C,OAAOkD,eAAeC,KAAKnD,KAAKsD,IAAI,CAAC,CAACC,UAAYA,YAAY;AAChE;AAEA,eAAehD,qCACbT,OAAe;IAEf,MAAMa,YAAY,MAAMC,4BAA4Bd;IACpD,MAAM0D,UAAUC;IAChB,OAAOD,WAAW7C,UAAU+C,QAAQ,CAACF,WAAWA,UAAUJ;AAC5D;AAEA,SAASK;IACP,+EAA+E;IAC/E,MAAME,QAAQ5D,QAAQwC,GAAG,CAACqB,qBAAqB,IAAI;IAEnD,IAAID,MAAMD,QAAQ,CAAC,SAAS;QAC1B,OAAO;IACT;IAEA,IAAIC,MAAMD,QAAQ,CAAC,SAAS;QAC1B,OAAO;IACT;IAEA,IAAIC,MAAMD,QAAQ,CAAC,QAAQ;QACzB,OAAO;IACT;IAEA,kFAAkF;IAClF,iFAAiF;IACjF,yEAAyE;IACzE,IAAI,WAAWG,IAAI,CAACF,QAAQ;QAC1B,OAAO;IACT;IAEA,OAAOP;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/util/packageManager/packageManagerChoice.ts"],"sourcesContent":["import path from 'node:path'\n\nimport {isInteractive} from '@sanity/cli-core'\nimport {select} from '@sanity/cli-core/ux'\n// eslint-disable-next-line unicorn/no-named-default\nimport {default as preferredPM} from 'preferred-pm'\nimport which from 'which'\n\nexport type PackageManager = 'bun' | 'manual' | 'npm' | 'pnpm' | 'yarn'\n\nconst EXPERIMENTAL = new Set(['bun'])\n\nexport const ALLOWED_PACKAGE_MANAGERS: readonly PackageManager[] = [\n 'npm',\n 'yarn',\n 'pnpm',\n 'bun',\n 'manual',\n] as const\n\nexport const allowedPackageManagersString = ALLOWED_PACKAGE_MANAGERS.join(' | ')\n\n/**\n * Attempts to resolve the most optimal package manager to use to install/upgrade\n * packages/dependencies at a given path. It does so by looking for package manager\n * specific lockfiles. If it finds a lockfile belonging to a certain package manager,\n * it prioritizes this one. However, if that package manager is not installed, it will\n * prompt the user for which one they want to use and hint at the most optimal one\n * not being installed.\n *\n * Note that this function also takes local npm binary paths into account - for instance,\n * `yarn` can be installed as a dependency of the project instead of globally, and it\n * will use that is available.\n *\n * The user can also select 'manual' to skip the process and run their preferred package\n * manager manually. Commands using this function must take this `manual` choice into\n * account and act accordingly if chosen.\n *\n * @param workDir - The working directory where a lockfile is most likely to be present\n * @param options - Pass `interactive: false` to fall back to npm if most optimal is\n * not available, instead of prompting\n * @returns Object of `chosen` and, if a lockfile is found, the `mostOptimal` choice\n */\nexport async function getPackageManagerChoice(\n workDir: string,\n options: {interactive: boolean},\n): Promise<{chosen: PackageManager; mostOptimal?: PackageManager}> {\n const rootDir = workDir || process.cwd()\n const preferred = (await preferredPM(rootDir))?.name\n\n if (preferred && (await hasCommand(preferred, rootDir))) {\n // There is an optimal/preferred package manager, and the user has it installed!\n return {chosen: preferred, mostOptimal: preferred}\n }\n\n const mostLikelyPM = await getMostLikelyInstalledPackageManager(rootDir)\n const interactive =\n typeof options.interactive === 'boolean' ? options.interactive : isInteractive()\n if (!interactive) {\n // We can't ask the user for their preference, so fall back to either the one that is being run\n // or whatever is installed on the system (npm being the preferred choice).\n // Note that the most optimal choice is already picked above if available.\n return {chosen: mostLikelyPM || (await getFallback(rootDir)), mostOptimal: preferred}\n }\n\n // We can ask the user for their preference, hurray!\n const messageSuffix = preferred ? ` (preferred is ${preferred}, but is not installed)` : ''\n const installed = await getAvailablePackageManagers(rootDir)\n const chosen = await select<PackageManager>({\n choices: installed.map((pm) => ({\n name: EXPERIMENTAL.has(pm) ? `${pm} (experimental)` : pm,\n value: pm,\n })),\n default: preferred || mostLikelyPM,\n message: `Package manager to use for installing dependencies?${messageSuffix}`,\n })\n\n return {chosen, mostOptimal: preferred}\n}\n\nasync function getFallback(cwd: string): Promise<PackageManager> {\n if (await hasNpmInstalled(cwd)) {\n return 'npm'\n }\n\n if (await hasYarnInstalled(cwd)) {\n return 'yarn'\n }\n\n if (await hasPnpmInstalled(cwd)) {\n return 'pnpm'\n }\n\n if (await hasBunInstalled(cwd)) {\n return 'bun'\n }\n\n return 'manual'\n}\n\nasync function getAvailablePackageManagers(cwd: string): Promise<PackageManager[]> {\n const [npm, yarn, pnpm, bun] = await Promise.all([\n hasNpmInstalled(cwd),\n hasYarnInstalled(cwd),\n hasPnpmInstalled(cwd),\n hasBunInstalled(cwd),\n ])\n\n const choices = [npm && 'npm', yarn && 'yarn', pnpm && 'pnpm', bun && 'bun', 'manual']\n return choices.filter((pm): pm is PackageManager => pm !== false)\n}\n\nfunction hasNpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('npm', cwd)\n}\n\nfunction hasYarnInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('yarn', cwd)\n}\n\nfunction hasPnpmInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('pnpm', cwd)\n}\n\nfunction hasBunInstalled(cwd?: string): Promise<boolean> {\n return hasCommand('bun', cwd)\n}\n\nfunction getNpmRunPath(cwd: string): string {\n let previous\n let cwdPath = path.resolve(cwd)\n const result: string[] = []\n\n while (previous !== cwdPath) {\n result.push(path.join(cwdPath, 'node_modules', '.bin'))\n previous = cwdPath\n cwdPath = path.resolve(cwdPath, '..')\n }\n\n result.push(path.resolve(cwd, process.execPath, '..'))\n\n const pathEnv = process.env[getPathEnvVarKey()]\n return [...result, pathEnv].join(path.delimiter)\n}\n\nexport function getPartialEnvWithNpmPath(cwd: string): NodeJS.ProcessEnv {\n const key = getPathEnvVarKey()\n return {[key]: getNpmRunPath(cwd)}\n}\n\nfunction getPathEnvVarKey(): string {\n if (process.platform !== 'win32') {\n return 'PATH'\n }\n\n return (\n Object.keys(process.env)\n .toReversed()\n .find((key) => key.toUpperCase() === 'PATH') || 'Path'\n )\n}\n\nfunction getCommandPath(cmd: string, cwd?: string): Promise<string | null> {\n const options = cwd ? {path: getNpmRunPath(cwd)} : undefined\n return which(cmd, options).catch(() => null)\n}\n\nfunction hasCommand(cmd: string, cwd?: string): Promise<boolean> {\n return getCommandPath(cmd, cwd).then((cmdPath) => cmdPath !== null)\n}\n\nasync function getMostLikelyInstalledPackageManager(\n rootDir: string,\n): Promise<PackageManager | undefined> {\n const installed = await getAvailablePackageManagers(rootDir)\n const running = getRunningPackageManager()\n return running && installed.includes(running) ? running : undefined\n}\n\nfunction getRunningPackageManager(): PackageManager | undefined {\n // Yes, the env var is lowercase - it is set by the package managers themselves\n const agent = process.env.npm_config_user_agent || ''\n\n if (agent.includes('yarn')) {\n return 'yarn'\n }\n\n if (agent.includes('pnpm')) {\n return 'pnpm'\n }\n\n if (agent.includes('bun')) {\n return 'bun'\n }\n\n // Both yarn and pnpm does a `npm/?` thing, thus the slightly different match here\n // Theoretically not needed since we check for yarn/pnpm above, but in case other\n // package managers do the same thing, we'll (hopefully) catch them here.\n if (/^npm\\/\\d/.test(agent)) {\n return 'npm'\n }\n\n return undefined\n}\n"],"names":["path","isInteractive","select","default","preferredPM","which","EXPERIMENTAL","Set","ALLOWED_PACKAGE_MANAGERS","allowedPackageManagersString","join","getPackageManagerChoice","workDir","options","rootDir","process","cwd","preferred","name","hasCommand","chosen","mostOptimal","mostLikelyPM","getMostLikelyInstalledPackageManager","interactive","getFallback","messageSuffix","installed","getAvailablePackageManagers","choices","map","pm","has","value","message","hasNpmInstalled","hasYarnInstalled","hasPnpmInstalled","hasBunInstalled","npm","yarn","pnpm","bun","Promise","all","filter","getNpmRunPath","previous","cwdPath","resolve","result","push","execPath","pathEnv","env","getPathEnvVarKey","delimiter","getPartialEnvWithNpmPath","key","platform","Object","keys","toReversed","find","toUpperCase","getCommandPath","cmd","undefined","catch","then","cmdPath","running","getRunningPackageManager","includes","agent","npm_config_user_agent","test"],"mappings":"AAAA,OAAOA,UAAU,YAAW;AAE5B,SAAQC,aAAa,QAAO,mBAAkB;AAC9C,SAAQC,MAAM,QAAO,sBAAqB;AAC1C,oDAAoD;AACpD,SAAQC,WAAWC,WAAW,QAAO,eAAc;AACnD,OAAOC,WAAW,QAAO;AAIzB,MAAMC,eAAe,IAAIC,IAAI;IAAC;CAAM;AAEpC,OAAO,MAAMC,2BAAsD;IACjE;IACA;IACA;IACA;IACA;CACD,CAAS;AAEV,OAAO,MAAMC,+BAA+BD,yBAAyBE,IAAI,CAAC,OAAM;AAEhF;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,eAAeC,wBACpBC,OAAe,EACfC,OAA+B;IAE/B,MAAMC,UAAUF,WAAWG,QAAQC,GAAG;IACtC,MAAMC,YAAa,CAAA,MAAMb,YAAYU,QAAO,GAAII;IAEhD,IAAID,aAAc,MAAME,WAAWF,WAAWH,UAAW;QACvD,gFAAgF;QAChF,OAAO;YAACM,QAAQH;YAAWI,aAAaJ;QAAS;IACnD;IAEA,MAAMK,eAAe,MAAMC,qCAAqCT;IAChE,MAAMU,cACJ,OAAOX,QAAQW,WAAW,KAAK,YAAYX,QAAQW,WAAW,GAAGvB;IACnE,IAAI,CAACuB,aAAa;QAChB,+FAA+F;QAC/F,2EAA2E;QAC3E,0EAA0E;QAC1E,OAAO;YAACJ,QAAQE,gBAAiB,MAAMG,YAAYX;YAAWO,aAAaJ;QAAS;IACtF;IAEA,oDAAoD;IACpD,MAAMS,gBAAgBT,YAAY,CAAC,eAAe,EAAEA,UAAU,uBAAuB,CAAC,GAAG;IACzF,MAAMU,YAAY,MAAMC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CAACqB,qBAAqB,IAAI;IAEnD,IAAID,MAAMD,QAAQ,CAAC,SAAS;QAC1B,OAAO;IACT;IAEA,IAAIC,MAAMD,QAAQ,CAAC,SAAS;QAC1B,OAAO;IACT;IAEA,IAAIC,MAAMD,QAAQ,CAAC,QAAQ;QACzB,OAAO;IACT;IAEA,kFAAkF;IAClF,iFAAiF;IACjF,yEAAyE;IACzE,IAAI,WAAWG,IAAI,CAACF,QAAQ;QAC1B,OAAO;IACT;IAEA,OAAOP;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
export async function readdirRecursive(dir) {
|
|
4
|
+
let content = [];
|
|
5
|
+
const currentPath = path.resolve(dir);
|
|
6
|
+
const dirContent = (await fs.readdir(currentPath)).map((item)=>path.join(currentPath, item));
|
|
7
|
+
for (const subPath of dirContent){
|
|
8
|
+
const stat = await fs.stat(subPath);
|
|
9
|
+
const isDir = stat.isDirectory();
|
|
10
|
+
content.push({
|
|
11
|
+
isDir,
|
|
12
|
+
path: subPath
|
|
13
|
+
});
|
|
14
|
+
if (isDir) {
|
|
15
|
+
content = [
|
|
16
|
+
...content,
|
|
17
|
+
...await readdirRecursive(subPath)
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return content;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=readdirRecursive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/readdirRecursive.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport path from 'node:path'\n\nexport interface ReaddirItem {\n isDir: boolean\n path: string\n}\n\nexport async function readdirRecursive(dir: string): Promise<ReaddirItem[]> {\n let content: ReaddirItem[] = []\n\n const currentPath = path.resolve(dir)\n const dirContent = (await fs.readdir(currentPath)).map((item) => path.join(currentPath, item))\n\n for (const subPath of dirContent) {\n const stat = await fs.stat(subPath)\n const isDir = stat.isDirectory()\n content.push({isDir, path: subPath})\n\n if (isDir) {\n content = [...content, ...(await readdirRecursive(subPath))]\n }\n }\n\n return content\n}\n"],"names":["fs","path","readdirRecursive","dir","content","currentPath","resolve","dirContent","readdir","map","item","join","subPath","stat","isDir","isDirectory","push"],"mappings":"AAAA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAO5B,OAAO,eAAeC,iBAAiBC,GAAW;IAChD,IAAIC,UAAyB,EAAE;IAE/B,MAAMC,cAAcJ,KAAKK,OAAO,CAACH;IACjC,MAAMI,aAAa,AAAC,CAAA,MAAMP,GAAGQ,OAAO,CAACH,YAAW,EAAGI,GAAG,CAAC,CAACC,OAAST,KAAKU,IAAI,CAACN,aAAaK;IAExF,KAAK,MAAME,WAAWL,WAAY;QAChC,MAAMM,OAAO,MAAMb,GAAGa,IAAI,CAACD;QAC3B,MAAME,QAAQD,KAAKE,WAAW;QAC9BX,QAAQY,IAAI,CAAC;YAACF;YAAOb,MAAMW;QAAO;QAElC,IAAIE,OAAO;YACTV,UAAU;mBAAIA;mBAAa,MAAMF,iBAAiBU;aAAU;QAC9D;IACF;IAEA,OAAOR;AACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve the latest versions of given packages within their defined ranges
|
|
3
|
+
*
|
|
4
|
+
* @param pkgs - `{packageName: rangeOrTag}`
|
|
5
|
+
* @returns Object of resolved version numbers
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveLatestVersions(pkgs: Record<string, string>): Promise<Record<string, string>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import latestVersion from 'get-latest-version';
|
|
2
|
+
import promiseProps from 'promise-props-recursive';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the latest versions of given packages within their defined ranges
|
|
5
|
+
*
|
|
6
|
+
* @param pkgs - `{packageName: rangeOrTag}`
|
|
7
|
+
* @returns Object of resolved version numbers
|
|
8
|
+
*/ export function resolveLatestVersions(pkgs) {
|
|
9
|
+
const lookups = {};
|
|
10
|
+
for (const [packageName, range] of Object.entries(pkgs)){
|
|
11
|
+
lookups[packageName] = range === 'latest' ? latestVersion(packageName, {
|
|
12
|
+
range
|
|
13
|
+
}).then(caretify) : range;
|
|
14
|
+
}
|
|
15
|
+
return promiseProps(lookups);
|
|
16
|
+
}
|
|
17
|
+
function caretify(version) {
|
|
18
|
+
return version ? `^${version}` : 'latest';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=resolveLatestVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/resolveLatestVersions.ts"],"sourcesContent":["import latestVersion from 'get-latest-version'\nimport promiseProps from 'promise-props-recursive'\n\n/**\n * Resolve the latest versions of given packages within their defined ranges\n *\n * @param pkgs - `{packageName: rangeOrTag}`\n * @returns Object of resolved version numbers\n */\nexport function resolveLatestVersions(\n pkgs: Record<string, string>,\n): Promise<Record<string, string>> {\n const lookups: Record<string, Promise<string> | string> = {}\n for (const [packageName, range] of Object.entries(pkgs)) {\n lookups[packageName] =\n range === 'latest' ? latestVersion(packageName, {range}).then(caretify) : range\n }\n\n return promiseProps(lookups)\n}\n\nfunction caretify(version: string | undefined) {\n return version ? `^${version}` : 'latest'\n}\n"],"names":["latestVersion","promiseProps","resolveLatestVersions","pkgs","lookups","packageName","range","Object","entries","then","caretify","version"],"mappings":"AAAA,OAAOA,mBAAmB,qBAAoB;AAC9C,OAAOC,kBAAkB,0BAAyB;AAElD;;;;;CAKC,GACD,OAAO,SAASC,sBACdC,IAA4B;IAE5B,MAAMC,UAAoD,CAAC;IAC3D,KAAK,MAAM,CAACC,aAAaC,MAAM,IAAIC,OAAOC,OAAO,CAACL,MAAO;QACvDC,OAAO,CAACC,YAAY,GAClBC,UAAU,WAAWN,cAAcK,aAAa;YAACC;QAAK,GAAGG,IAAI,CAACC,YAAYJ;IAC9E;IAEA,OAAOL,aAAaG;AACtB;AAEA,SAASM,SAASC,OAA2B;IAC3C,OAAOA,UAAU,CAAC,CAAC,EAAEA,SAAS,GAAG;AACnC"}
|