node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import type { CLIContext } from '../types';
declare const _default: (ctx: CLIContext) => Promise<any>;
export default _default;
//# sourceMappingURL=action.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/create-project/action.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAgC,MAAM,UAAU,CAAC;8BAyD9C,UAAU;AAArC,wBAyCE"}

View File

@@ -0,0 +1,95 @@
'use strict';
var inquirer = require('inquirer');
var axios = require('axios');
var fp = require('lodash/fp');
var cliApi = require('../services/cli-api.js');
var strapiInfoSave = require('../services/strapi-info-save.js');
var token = require('../services/token.js');
require('chalk');
require('fast-safe-stringify');
require('ora');
require('cli-progress');
var getProjectNameFromPkg = require('./utils/get-project-name-from-pkg.js');
var action$1 = require('../login/action.js');
var projectQuestions_utils = require('./utils/project-questions.utils.js');
async function handleError(ctx, error) {
const { logger } = ctx;
logger.debug(error);
if (error instanceof axios.AxiosError) {
const errorMessage = typeof error.response?.data === 'string' ? error.response.data : null;
switch(error.response?.status){
case 403:
logger.error(errorMessage || 'You do not have permission to create a project. Please contact support for assistance.');
return;
case 400:
logger.error(errorMessage || 'Invalid input. Please check your inputs and try again.');
return;
case 503:
logger.error('Strapi Cloud project creation is currently unavailable. Please try again later.');
return;
default:
if (errorMessage) {
logger.error(errorMessage);
return;
}
break;
}
}
logger.error('We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance.');
}
async function createProject(ctx, cloudApi, projectInput) {
const { logger } = ctx;
const spinner = logger.spinner('Setting up your project...').start();
try {
const { data } = await cloudApi.createProject(projectInput);
await strapiInfoSave.save({
project: data
});
spinner.succeed('Project created successfully!');
return data;
} catch (e) {
spinner.fail('An error occurred while creating the project on Strapi Cloud.');
throw e;
}
}
var action = (async (ctx)=>{
const { logger } = ctx;
const { getValidToken, eraseToken } = await token.tokenServiceFactory(ctx);
const token$1 = await getValidToken(ctx, action$1.promptLogin);
if (!token$1) {
return;
}
const cloudApi = await cliApi.cloudApiFactory(ctx, token$1);
const { data: config } = await cloudApi.config();
const projectName = await getProjectNameFromPkg.getProjectNameFromPackageJson(ctx);
const defaultAnswersMapper = projectQuestions_utils.questionDefaultValuesMapper({
name: projectName,
nodeVersion: projectQuestions_utils.getProjectNodeVersionDefault
});
const questions = defaultAnswersMapper(config.projectCreation.questions);
const defaultValues = {
...config.projectCreation.defaults,
...projectQuestions_utils.getDefaultsFromQuestions(questions)
};
const projectAnswersDefaulted = fp.defaults(defaultValues);
const projectAnswers = await inquirer.prompt(questions);
const projectInput = projectAnswersDefaulted(projectAnswers);
try {
return await createProject(ctx, cloudApi, projectInput);
} catch (e) {
if (e instanceof axios.AxiosError && e.response?.status === 401) {
logger.warn('Oops! Your session has expired. Please log in again to retry.');
await eraseToken();
if (await action$1.promptLogin(ctx)) {
return await createProject(ctx, cloudApi, projectInput);
}
} else {
await handleError(ctx, e);
}
}
});
module.exports = action;
//# sourceMappingURL=action.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,93 @@
import inquirer from 'inquirer';
import { AxiosError } from 'axios';
import { defaults } from 'lodash/fp';
import { cloudApiFactory } from '../services/cli-api.mjs';
import { save } from '../services/strapi-info-save.mjs';
import { tokenServiceFactory } from '../services/token.mjs';
import 'chalk';
import 'fast-safe-stringify';
import 'ora';
import 'cli-progress';
import { getProjectNameFromPackageJson } from './utils/get-project-name-from-pkg.mjs';
import { promptLogin } from '../login/action.mjs';
import { getDefaultsFromQuestions, questionDefaultValuesMapper, getProjectNodeVersionDefault } from './utils/project-questions.utils.mjs';
async function handleError(ctx, error) {
const { logger } = ctx;
logger.debug(error);
if (error instanceof AxiosError) {
const errorMessage = typeof error.response?.data === 'string' ? error.response.data : null;
switch(error.response?.status){
case 403:
logger.error(errorMessage || 'You do not have permission to create a project. Please contact support for assistance.');
return;
case 400:
logger.error(errorMessage || 'Invalid input. Please check your inputs and try again.');
return;
case 503:
logger.error('Strapi Cloud project creation is currently unavailable. Please try again later.');
return;
default:
if (errorMessage) {
logger.error(errorMessage);
return;
}
break;
}
}
logger.error('We encountered an issue while creating your project. Please try again in a moment. If the problem persists, contact support for assistance.');
}
async function createProject(ctx, cloudApi, projectInput) {
const { logger } = ctx;
const spinner = logger.spinner('Setting up your project...').start();
try {
const { data } = await cloudApi.createProject(projectInput);
await save({
project: data
});
spinner.succeed('Project created successfully!');
return data;
} catch (e) {
spinner.fail('An error occurred while creating the project on Strapi Cloud.');
throw e;
}
}
var action = (async (ctx)=>{
const { logger } = ctx;
const { getValidToken, eraseToken } = await tokenServiceFactory(ctx);
const token = await getValidToken(ctx, promptLogin);
if (!token) {
return;
}
const cloudApi = await cloudApiFactory(ctx, token);
const { data: config } = await cloudApi.config();
const projectName = await getProjectNameFromPackageJson(ctx);
const defaultAnswersMapper = questionDefaultValuesMapper({
name: projectName,
nodeVersion: getProjectNodeVersionDefault
});
const questions = defaultAnswersMapper(config.projectCreation.questions);
const defaultValues = {
...config.projectCreation.defaults,
...getDefaultsFromQuestions(questions)
};
const projectAnswersDefaulted = defaults(defaultValues);
const projectAnswers = await inquirer.prompt(questions);
const projectInput = projectAnswersDefaulted(projectAnswers);
try {
return await createProject(ctx, cloudApi, projectInput);
} catch (e) {
if (e instanceof AxiosError && e.response?.status === 401) {
logger.warn('Oops! Your session has expired. Please log in again to retry.');
await eraseToken();
if (await promptLogin(ctx)) {
return await createProject(ctx, cloudApi, projectInput);
}
} else {
await handleError(ctx, e);
}
}
});
export { action as default };
//# sourceMappingURL=action.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,7 @@
import { type StrapiCloudCommand } from '../types';
/**
* `$ create project in Strapi cloud`
*/
declare const command: StrapiCloudCommand;
export default command;
//# sourceMappingURL=command.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/create-project/command.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD;;GAEG;AACH,QAAA,MAAM,OAAO,EAAE,kBAMd,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,14 @@
'use strict';
var commander = require('commander');
var helpers = require('../utils/helpers.js');
var action = require('./action.js');
/**
* `$ create project in Strapi cloud`
*/ const command = ({ ctx })=>{
return commander.createCommand('cloud:create-project').description('Create a Strapi Cloud project').option('-d, --debug', 'Enable debugging mode with verbose logs').option('-s, --silent', "Don't log anything").action(()=>helpers.runAction('cloud:create-project', action)(ctx));
};
module.exports = command;
//# sourceMappingURL=command.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"command.js","sources":["../../src/create-project/command.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport { type StrapiCloudCommand } from '../types';\nimport { runAction } from '../utils/helpers';\nimport action from './action';\n\n/**\n * `$ create project in Strapi cloud`\n */\nconst command: StrapiCloudCommand = ({ ctx }) => {\n return createCommand('cloud:create-project')\n .description('Create a Strapi Cloud project')\n .option('-d, --debug', 'Enable debugging mode with verbose logs')\n .option('-s, --silent', \"Don't log anything\")\n .action(() => runAction('cloud:create-project', action)(ctx));\n};\n\nexport default command;\n"],"names":["command","ctx","createCommand","description","option","action","runAction"],"mappings":";;;;;;AAKA;;AAEC,IACKA,MAAAA,OAAAA,GAA8B,CAAC,EAAEC,GAAG,EAAE,GAAA;AAC1C,IAAA,OAAOC,wBAAc,sBAClBC,CAAAA,CAAAA,WAAW,CAAC,+BACZC,CAAAA,CAAAA,MAAM,CAAC,aAAe,EAAA,yCAAA,CAAA,CACtBA,MAAM,CAAC,gBAAgB,oBACvBC,CAAAA,CAAAA,MAAM,CAAC,IAAMC,iBAAAA,CAAU,wBAAwBD,MAAQJ,CAAAA,CAAAA,GAAAA,CAAAA,CAAAA;AAC5D;;;;"}

View File

@@ -0,0 +1,12 @@
import { createCommand } from 'commander';
import { runAction } from '../utils/helpers.mjs';
import action from './action.mjs';
/**
* `$ create project in Strapi cloud`
*/ const command = ({ ctx })=>{
return createCommand('cloud:create-project').description('Create a Strapi Cloud project').option('-d, --debug', 'Enable debugging mode with verbose logs').option('-s, --silent', "Don't log anything").action(()=>runAction('cloud:create-project', action)(ctx));
};
export { command as default };
//# sourceMappingURL=command.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"command.mjs","sources":["../../src/create-project/command.ts"],"sourcesContent":["import { createCommand } from 'commander';\nimport { type StrapiCloudCommand } from '../types';\nimport { runAction } from '../utils/helpers';\nimport action from './action';\n\n/**\n * `$ create project in Strapi cloud`\n */\nconst command: StrapiCloudCommand = ({ ctx }) => {\n return createCommand('cloud:create-project')\n .description('Create a Strapi Cloud project')\n .option('-d, --debug', 'Enable debugging mode with verbose logs')\n .option('-s, --silent', \"Don't log anything\")\n .action(() => runAction('cloud:create-project', action)(ctx));\n};\n\nexport default command;\n"],"names":["command","ctx","createCommand","description","option","action","runAction"],"mappings":";;;;AAKA;;AAEC,IACKA,MAAAA,OAAAA,GAA8B,CAAC,EAAEC,GAAG,EAAE,GAAA;AAC1C,IAAA,OAAOC,cAAc,sBAClBC,CAAAA,CAAAA,WAAW,CAAC,+BACZC,CAAAA,CAAAA,MAAM,CAAC,aAAe,EAAA,yCAAA,CAAA,CACtBA,MAAM,CAAC,gBAAgB,oBACvBC,CAAAA,CAAAA,MAAM,CAAC,IAAMC,SAAAA,CAAU,wBAAwBD,MAAQJ,CAAAA,CAAAA,GAAAA,CAAAA,CAAAA;AAC5D;;;;"}

View File

@@ -0,0 +1,7 @@
import action from './action';
import command from './command';
import type { StrapiCloudCommandInfo } from '../types';
export { action, command };
declare const _default: StrapiCloudCommandInfo;
export default _default;
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/create-project/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,OAAO,MAAM,WAAW,CAAC;AAChC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;;AAE3B,wBAK4B"}

View File

@@ -0,0 +1,18 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var action = require('./action.js');
var command = require('./command.js');
var createProject = {
name: 'create-project',
description: 'Create a new project',
action,
command
};
exports.action = action;
exports.command = command;
exports.default = createProject;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":["../../src/create-project/index.ts"],"sourcesContent":["import action from './action';\nimport command from './command';\nimport type { StrapiCloudCommandInfo } from '../types';\n\nexport { action, command };\n\nexport default {\n name: 'create-project',\n description: 'Create a new project',\n action,\n command,\n} as StrapiCloudCommandInfo;\n"],"names":["name","description","action","command"],"mappings":";;;;;;;AAMA,oBAAe;IACbA,IAAM,EAAA,gBAAA;IACNC,WAAa,EAAA,sBAAA;AACbC,IAAAA,MAAAA;AACAC,IAAAA;AACF,CAA4B;;;;;;"}

View File

@@ -0,0 +1,12 @@
import action from './action.mjs';
import command from './command.mjs';
var createProject = {
name: 'create-project',
description: 'Create a new project',
action,
command
};
export { action, command, createProject as default };
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":["../../src/create-project/index.ts"],"sourcesContent":["import action from './action';\nimport command from './command';\nimport type { StrapiCloudCommandInfo } from '../types';\n\nexport { action, command };\n\nexport default {\n name: 'create-project',\n description: 'Create a new project',\n action,\n command,\n} as StrapiCloudCommandInfo;\n"],"names":["name","description","action","command"],"mappings":";;;AAMA,oBAAe;IACbA,IAAM,EAAA,gBAAA;IACNC,WAAa,EAAA,sBAAA;AACbC,IAAAA,MAAAA;AACAC,IAAAA;AACF,CAA4B;;;;"}

View File

@@ -0,0 +1,3 @@
import { CLIContext } from '../../types';
export declare function getProjectNameFromPackageJson(ctx: CLIContext): Promise<string>;
//# sourceMappingURL=get-project-name-from-pkg.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"get-project-name-from-pkg.d.ts","sourceRoot":"","sources":["../../../src/create-project/utils/get-project-name-from-pkg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,wBAAsB,6BAA6B,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpF"}

View File

@@ -0,0 +1,15 @@
'use strict';
var pkg = require('../../utils/pkg.js');
async function getProjectNameFromPackageJson(ctx) {
try {
const packageJson = await pkg.loadPkg(ctx);
return packageJson.name || 'my-strapi-project';
} catch (e) {
return 'my-strapi-project';
}
}
exports.getProjectNameFromPackageJson = getProjectNameFromPackageJson;
//# sourceMappingURL=get-project-name-from-pkg.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"get-project-name-from-pkg.js","sources":["../../../src/create-project/utils/get-project-name-from-pkg.ts"],"sourcesContent":["import { CLIContext } from '../../types';\nimport { PackageJson, loadPkg } from '../../utils/pkg';\n\nexport async function getProjectNameFromPackageJson(ctx: CLIContext): Promise<string> {\n try {\n const packageJson = (await loadPkg(ctx)) as PackageJson;\n return packageJson.name || 'my-strapi-project';\n } catch (e) {\n return 'my-strapi-project';\n }\n}\n"],"names":["getProjectNameFromPackageJson","ctx","packageJson","loadPkg","name","e"],"mappings":";;;;AAGO,eAAeA,8BAA8BC,GAAe,EAAA;IACjE,IAAI;QACF,MAAMC,WAAAA,GAAe,MAAMC,WAAQF,CAAAA,GAAAA,CAAAA;QACnC,OAAOC,WAAAA,CAAYE,IAAI,IAAI,mBAAA;AAC7B,KAAA,CAAE,OAAOC,CAAG,EAAA;QACV,OAAO,mBAAA;AACT;AACF;;;;"}

View File

@@ -0,0 +1,13 @@
import { loadPkg } from '../../utils/pkg.mjs';
async function getProjectNameFromPackageJson(ctx) {
try {
const packageJson = await loadPkg(ctx);
return packageJson.name || 'my-strapi-project';
} catch (e) {
return 'my-strapi-project';
}
}
export { getProjectNameFromPackageJson };
//# sourceMappingURL=get-project-name-from-pkg.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"get-project-name-from-pkg.mjs","sources":["../../../src/create-project/utils/get-project-name-from-pkg.ts"],"sourcesContent":["import { CLIContext } from '../../types';\nimport { PackageJson, loadPkg } from '../../utils/pkg';\n\nexport async function getProjectNameFromPackageJson(ctx: CLIContext): Promise<string> {\n try {\n const packageJson = (await loadPkg(ctx)) as PackageJson;\n return packageJson.name || 'my-strapi-project';\n } catch (e) {\n return 'my-strapi-project';\n }\n}\n"],"names":["getProjectNameFromPackageJson","ctx","packageJson","loadPkg","name","e"],"mappings":";;AAGO,eAAeA,8BAA8BC,GAAe,EAAA;IACjE,IAAI;QACF,MAAMC,WAAAA,GAAe,MAAMC,OAAQF,CAAAA,GAAAA,CAAAA;QACnC,OAAOC,WAAAA,CAAYE,IAAI,IAAI,mBAAA;AAC7B,KAAA,CAAE,OAAOC,CAAG,EAAA;QACV,OAAO,mBAAA;AACT;AACF;;;;"}

View File

@@ -0,0 +1,20 @@
import { DistinctQuestion } from 'inquirer';
import type { ProjectAnswers } from '../../types';
/**
* Apply default values to questions based on the provided mapper
* @param questionsMap - A partial object with keys matching the ProjectAnswers keys and values being the default value or a function to get the default value
*/
export declare function questionDefaultValuesMapper(questionsMap: Partial<{
[K in keyof ProjectAnswers]: ((question: DistinctQuestion<ProjectAnswers>) => ProjectAnswers[K]) | ProjectAnswers[K];
}>): (questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>) => ReadonlyArray<DistinctQuestion<ProjectAnswers>>;
/**
* Get default values from questions
* @param questions - An array of questions for project creation
*/
export declare function getDefaultsFromQuestions(questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>): Partial<ProjectAnswers>;
/**
* Get the default node version based on the current node version if it is in the list of choices
* @param question - The question for the node version in project creation
*/
export declare function getProjectNodeVersionDefault(question: DistinctQuestion<ProjectAnswers>): string;
//# sourceMappingURL=project-questions.utils.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"project-questions.utils.d.ts","sourceRoot":"","sources":["../../../src/create-project/utils/project-questions.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,YAAY,EAAE,OAAO,CAAC;KACnB,CAAC,IAAI,MAAM,cAAc,GACtB,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAC,GACnE,cAAc,CAAC,CAAC,CAAC;CACtB,CAAC,eAGW,cAAc,iBAAiB,cAAc,CAAC,CAAC,KACzD,cAAc,iBAAiB,cAAc,CAAC,CAAC,CAyBnD;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,aAAa,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,GACzD,OAAO,CAAC,cAAc,CAAC,CAOzB;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,gBAAgB,CAAC,cAAc,CAAC,GAAG,MAAM,CAW/F"}

View File

@@ -0,0 +1,63 @@
'use strict';
/**
* Apply default values to questions based on the provided mapper
* @param questionsMap - A partial object with keys matching the ProjectAnswers keys and values being the default value or a function to get the default value
*/ function questionDefaultValuesMapper(questionsMap) {
return (questions)=>{
return questions.map((question)=>{
const questionName = question.name;
// If the question is part of the mapper, apply the default value
if (questionName in questionsMap) {
const questionDefault = questionsMap[questionName];
// If the default value is a function, call it with the question and get the default value
if (typeof questionDefault === 'function') {
return {
...question,
default: questionDefault(question)
};
}
// else we consider it as a static value
return {
...question,
default: questionDefault
};
}
// If the question is not part of the mapper, return the question as is
return question;
});
};
}
/**
* Get default values from questions
* @param questions - An array of questions for project creation
*/ function getDefaultsFromQuestions(questions) {
return questions.reduce((acc, question)=>{
if (question.default && question.name) {
return {
...acc,
[question.name]: question.default
};
}
return acc;
}, {});
}
/**
* Get the default node version based on the current node version if it is in the list of choices
* @param question - The question for the node version in project creation
*/ function getProjectNodeVersionDefault(question) {
const currentNodeVersion = process.versions.node.split('.')[0];
// Node Version question is set up as a list, but the type of inquirer is dynamic and the question can change in the future (it comes from API)
if (question.type === 'list' && Array.isArray(question.choices)) {
const choice = question.choices.find((choice)=>choice.value === currentNodeVersion);
if (choice) {
return choice.value;
}
}
return question.default;
}
exports.getDefaultsFromQuestions = getDefaultsFromQuestions;
exports.getProjectNodeVersionDefault = getProjectNodeVersionDefault;
exports.questionDefaultValuesMapper = questionDefaultValuesMapper;
//# sourceMappingURL=project-questions.utils.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"project-questions.utils.js","sources":["../../../src/create-project/utils/project-questions.utils.ts"],"sourcesContent":["import { DistinctQuestion } from 'inquirer';\nimport type { ProjectAnswers } from '../../types';\n\n/**\n * Apply default values to questions based on the provided mapper\n * @param questionsMap - A partial object with keys matching the ProjectAnswers keys and values being the default value or a function to get the default value\n */\nexport function questionDefaultValuesMapper(\n questionsMap: Partial<{\n [K in keyof ProjectAnswers]:\n | ((question: DistinctQuestion<ProjectAnswers>) => ProjectAnswers[K])\n | ProjectAnswers[K];\n }>\n) {\n return (\n questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>\n ): ReadonlyArray<DistinctQuestion<ProjectAnswers>> => {\n return questions.map((question) => {\n const questionName = question.name as keyof ProjectAnswers;\n\n // If the question is part of the mapper, apply the default value\n if (questionName in questionsMap) {\n const questionDefault = questionsMap[questionName];\n\n // If the default value is a function, call it with the question and get the default value\n if (typeof questionDefault === 'function') {\n return {\n ...question,\n default: questionDefault(question),\n };\n }\n // else we consider it as a static value\n return {\n ...question,\n default: questionDefault,\n };\n }\n // If the question is not part of the mapper, return the question as is\n return question;\n });\n };\n}\n\n/**\n * Get default values from questions\n * @param questions - An array of questions for project creation\n */\nexport function getDefaultsFromQuestions(\n questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>\n): Partial<ProjectAnswers> {\n return questions.reduce((acc, question) => {\n if (question.default && question.name) {\n return { ...acc, [question.name]: question.default };\n }\n return acc;\n }, {});\n}\n\n/**\n * Get the default node version based on the current node version if it is in the list of choices\n * @param question - The question for the node version in project creation\n */\nexport function getProjectNodeVersionDefault(question: DistinctQuestion<ProjectAnswers>): string {\n const currentNodeVersion = process.versions.node.split('.')[0];\n\n // Node Version question is set up as a list, but the type of inquirer is dynamic and the question can change in the future (it comes from API)\n if (question.type === 'list' && Array.isArray(question.choices)) {\n const choice = question.choices.find((choice) => choice.value === currentNodeVersion);\n if (choice) {\n return choice.value;\n }\n }\n return question.default;\n}\n"],"names":["questionDefaultValuesMapper","questionsMap","questions","map","question","questionName","name","questionDefault","default","getDefaultsFromQuestions","reduce","acc","getProjectNodeVersionDefault","currentNodeVersion","process","versions","node","split","type","Array","isArray","choices","choice","find","value"],"mappings":";;AAGA;;;IAIO,SAASA,2BAAAA,CACdC,YAIE,EAAA;AAEF,IAAA,OAAO,CACLC,SAAAA,GAAAA;QAEA,OAAOA,SAAAA,CAAUC,GAAG,CAAC,CAACC,QAAAA,GAAAA;YACpB,MAAMC,YAAAA,GAAeD,SAASE,IAAI;;AAGlC,YAAA,IAAID,gBAAgBJ,YAAc,EAAA;gBAChC,MAAMM,eAAAA,GAAkBN,YAAY,CAACI,YAAa,CAAA;;gBAGlD,IAAI,OAAOE,oBAAoB,UAAY,EAAA;oBACzC,OAAO;AACL,wBAAA,GAAGH,QAAQ;AACXI,wBAAAA,OAAAA,EAASD,eAAgBH,CAAAA,QAAAA;AAC3B,qBAAA;AACF;;gBAEA,OAAO;AACL,oBAAA,GAAGA,QAAQ;oBACXI,OAASD,EAAAA;AACX,iBAAA;AACF;;YAEA,OAAOH,QAAAA;AACT,SAAA,CAAA;AACF,KAAA;AACF;AAEA;;;IAIO,SAASK,wBAAAA,CACdP,SAA0D,EAAA;AAE1D,IAAA,OAAOA,SAAUQ,CAAAA,MAAM,CAAC,CAACC,GAAKP,EAAAA,QAAAA,GAAAA;AAC5B,QAAA,IAAIA,QAASI,CAAAA,OAAO,IAAIJ,QAAAA,CAASE,IAAI,EAAE;YACrC,OAAO;AAAE,gBAAA,GAAGK,GAAG;AAAE,gBAAA,CAACP,QAASE,CAAAA,IAAI,GAAGF,SAASI;AAAQ,aAAA;AACrD;QACA,OAAOG,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AACN;AAEA;;;IAIO,SAASC,4BAAAA,CAA6BR,QAA0C,EAAA;IACrF,MAAMS,kBAAAA,GAAqBC,OAAQC,CAAAA,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,GAAI,CAAA,CAAC,CAAE,CAAA;;IAG9D,IAAIb,QAAAA,CAASc,IAAI,KAAK,MAAA,IAAUC,MAAMC,OAAO,CAAChB,QAASiB,CAAAA,OAAO,CAAG,EAAA;QAC/D,MAAMC,MAAAA,GAASlB,QAASiB,CAAAA,OAAO,CAACE,IAAI,CAAC,CAACD,MAAAA,GAAWA,MAAOE,CAAAA,KAAK,KAAKX,kBAAAA,CAAAA;AAClE,QAAA,IAAIS,MAAQ,EAAA;AACV,YAAA,OAAOA,OAAOE,KAAK;AACrB;AACF;AACA,IAAA,OAAOpB,SAASI,OAAO;AACzB;;;;;;"}

View File

@@ -0,0 +1,59 @@
/**
* Apply default values to questions based on the provided mapper
* @param questionsMap - A partial object with keys matching the ProjectAnswers keys and values being the default value or a function to get the default value
*/ function questionDefaultValuesMapper(questionsMap) {
return (questions)=>{
return questions.map((question)=>{
const questionName = question.name;
// If the question is part of the mapper, apply the default value
if (questionName in questionsMap) {
const questionDefault = questionsMap[questionName];
// If the default value is a function, call it with the question and get the default value
if (typeof questionDefault === 'function') {
return {
...question,
default: questionDefault(question)
};
}
// else we consider it as a static value
return {
...question,
default: questionDefault
};
}
// If the question is not part of the mapper, return the question as is
return question;
});
};
}
/**
* Get default values from questions
* @param questions - An array of questions for project creation
*/ function getDefaultsFromQuestions(questions) {
return questions.reduce((acc, question)=>{
if (question.default && question.name) {
return {
...acc,
[question.name]: question.default
};
}
return acc;
}, {});
}
/**
* Get the default node version based on the current node version if it is in the list of choices
* @param question - The question for the node version in project creation
*/ function getProjectNodeVersionDefault(question) {
const currentNodeVersion = process.versions.node.split('.')[0];
// Node Version question is set up as a list, but the type of inquirer is dynamic and the question can change in the future (it comes from API)
if (question.type === 'list' && Array.isArray(question.choices)) {
const choice = question.choices.find((choice)=>choice.value === currentNodeVersion);
if (choice) {
return choice.value;
}
}
return question.default;
}
export { getDefaultsFromQuestions, getProjectNodeVersionDefault, questionDefaultValuesMapper };
//# sourceMappingURL=project-questions.utils.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"project-questions.utils.mjs","sources":["../../../src/create-project/utils/project-questions.utils.ts"],"sourcesContent":["import { DistinctQuestion } from 'inquirer';\nimport type { ProjectAnswers } from '../../types';\n\n/**\n * Apply default values to questions based on the provided mapper\n * @param questionsMap - A partial object with keys matching the ProjectAnswers keys and values being the default value or a function to get the default value\n */\nexport function questionDefaultValuesMapper(\n questionsMap: Partial<{\n [K in keyof ProjectAnswers]:\n | ((question: DistinctQuestion<ProjectAnswers>) => ProjectAnswers[K])\n | ProjectAnswers[K];\n }>\n) {\n return (\n questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>\n ): ReadonlyArray<DistinctQuestion<ProjectAnswers>> => {\n return questions.map((question) => {\n const questionName = question.name as keyof ProjectAnswers;\n\n // If the question is part of the mapper, apply the default value\n if (questionName in questionsMap) {\n const questionDefault = questionsMap[questionName];\n\n // If the default value is a function, call it with the question and get the default value\n if (typeof questionDefault === 'function') {\n return {\n ...question,\n default: questionDefault(question),\n };\n }\n // else we consider it as a static value\n return {\n ...question,\n default: questionDefault,\n };\n }\n // If the question is not part of the mapper, return the question as is\n return question;\n });\n };\n}\n\n/**\n * Get default values from questions\n * @param questions - An array of questions for project creation\n */\nexport function getDefaultsFromQuestions(\n questions: ReadonlyArray<DistinctQuestion<ProjectAnswers>>\n): Partial<ProjectAnswers> {\n return questions.reduce((acc, question) => {\n if (question.default && question.name) {\n return { ...acc, [question.name]: question.default };\n }\n return acc;\n }, {});\n}\n\n/**\n * Get the default node version based on the current node version if it is in the list of choices\n * @param question - The question for the node version in project creation\n */\nexport function getProjectNodeVersionDefault(question: DistinctQuestion<ProjectAnswers>): string {\n const currentNodeVersion = process.versions.node.split('.')[0];\n\n // Node Version question is set up as a list, but the type of inquirer is dynamic and the question can change in the future (it comes from API)\n if (question.type === 'list' && Array.isArray(question.choices)) {\n const choice = question.choices.find((choice) => choice.value === currentNodeVersion);\n if (choice) {\n return choice.value;\n }\n }\n return question.default;\n}\n"],"names":["questionDefaultValuesMapper","questionsMap","questions","map","question","questionName","name","questionDefault","default","getDefaultsFromQuestions","reduce","acc","getProjectNodeVersionDefault","currentNodeVersion","process","versions","node","split","type","Array","isArray","choices","choice","find","value"],"mappings":"AAGA;;;IAIO,SAASA,2BAAAA,CACdC,YAIE,EAAA;AAEF,IAAA,OAAO,CACLC,SAAAA,GAAAA;QAEA,OAAOA,SAAAA,CAAUC,GAAG,CAAC,CAACC,QAAAA,GAAAA;YACpB,MAAMC,YAAAA,GAAeD,SAASE,IAAI;;AAGlC,YAAA,IAAID,gBAAgBJ,YAAc,EAAA;gBAChC,MAAMM,eAAAA,GAAkBN,YAAY,CAACI,YAAa,CAAA;;gBAGlD,IAAI,OAAOE,oBAAoB,UAAY,EAAA;oBACzC,OAAO;AACL,wBAAA,GAAGH,QAAQ;AACXI,wBAAAA,OAAAA,EAASD,eAAgBH,CAAAA,QAAAA;AAC3B,qBAAA;AACF;;gBAEA,OAAO;AACL,oBAAA,GAAGA,QAAQ;oBACXI,OAASD,EAAAA;AACX,iBAAA;AACF;;YAEA,OAAOH,QAAAA;AACT,SAAA,CAAA;AACF,KAAA;AACF;AAEA;;;IAIO,SAASK,wBAAAA,CACdP,SAA0D,EAAA;AAE1D,IAAA,OAAOA,SAAUQ,CAAAA,MAAM,CAAC,CAACC,GAAKP,EAAAA,QAAAA,GAAAA;AAC5B,QAAA,IAAIA,QAASI,CAAAA,OAAO,IAAIJ,QAAAA,CAASE,IAAI,EAAE;YACrC,OAAO;AAAE,gBAAA,GAAGK,GAAG;AAAE,gBAAA,CAACP,QAASE,CAAAA,IAAI,GAAGF,SAASI;AAAQ,aAAA;AACrD;QACA,OAAOG,GAAAA;AACT,KAAA,EAAG,EAAC,CAAA;AACN;AAEA;;;IAIO,SAASC,4BAAAA,CAA6BR,QAA0C,EAAA;IACrF,MAAMS,kBAAAA,GAAqBC,OAAQC,CAAAA,QAAQ,CAACC,IAAI,CAACC,KAAK,CAAC,GAAI,CAAA,CAAC,CAAE,CAAA;;IAG9D,IAAIb,QAAAA,CAASc,IAAI,KAAK,MAAA,IAAUC,MAAMC,OAAO,CAAChB,QAASiB,CAAAA,OAAO,CAAG,EAAA;QAC/D,MAAMC,MAAAA,GAASlB,QAASiB,CAAAA,OAAO,CAACE,IAAI,CAAC,CAACD,MAAAA,GAAWA,MAAOE,CAAAA,KAAK,KAAKX,kBAAAA,CAAAA;AAClE,QAAA,IAAIS,MAAQ,EAAA;AACV,YAAA,OAAOA,OAAOE,KAAK;AACrB;AACF;AACA,IAAA,OAAOpB,SAASI,OAAO;AACzB;;;;"}