@strapi/generate-new
Advanced tools
Comparing version 0.0.0-experimental.996ba09add3e0d8e7794dde5ddc0306f8a9e42cd to 0.0.0-experimental.99d739783fc4b2410325163af5eb9cf0a6865d47
import type { Scope } from './types'; | ||
declare const _default: (scope: Scope) => Promise<void>; | ||
export default _default; | ||
//# sourceMappingURL=create-cli-db-project.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = require("lodash"); | ||
const usage_1 = require("./utils/usage"); | ||
const db_configs_1 = __importDefault(require("./utils/db-configs")); | ||
const db_client_dependencies_1 = __importDefault(require("./utils/db-client-dependencies")); | ||
const db_client_name_1 = __importDefault(require("./utils/db-client-name")); | ||
const create_project_1 = __importDefault(require("./create-project")); | ||
exports.default = async (scope) => { | ||
console.log('Creating a project from the database CLI arguments.'); | ||
await (0, usage_1.trackUsage)({ event: 'didChooseCustomDatabase', scope }); | ||
const { client } = scope.database ?? {}; | ||
if (!client) { | ||
throw new Error('Missing client'); | ||
const _ = require("lodash"); | ||
const usage = require("./utils/usage.js"); | ||
const dbConfigs = require("./utils/db-configs.js"); | ||
const dbClientDependencies = require("./utils/db-client-dependencies.js"); | ||
const dbClientName = require("./utils/db-client-name.js"); | ||
const createProject = require("./create-project.js"); | ||
const createCLIDatabaseProject = async (scope) => { | ||
console.log("Creating a project from the database CLI arguments."); | ||
await usage.trackUsage({ event: "didChooseCustomDatabase", scope }); | ||
const { client } = scope.database ?? {}; | ||
if (!client) { | ||
throw new Error("Missing client"); | ||
} | ||
const configuration = { | ||
client: dbClientName({ client }), | ||
connection: _.merge( | ||
{}, | ||
dbConfigs[client] || {}, | ||
scope.database | ||
), | ||
dependencies: { | ||
...dbClientDependencies({ scope, client }), | ||
...scope.additionalsDependencies | ||
} | ||
const configuration = { | ||
client: (0, db_client_name_1.default)({ client }), | ||
connection: (0, lodash_1.merge)({}, db_configs_1.default[client] || {}, scope.database), | ||
dependencies: (0, db_client_dependencies_1.default)({ scope, client }), | ||
}; | ||
return (0, create_project_1.default)(scope, configuration); | ||
}; | ||
return createProject(scope, configuration); | ||
}; | ||
//# sourceMappingURL=create-cli-db-project.js.map | ||
module.exports = createCLIDatabaseProject; | ||
//# sourceMappingURL=create-cli-db-project.js.map |
import type { Scope } from './types'; | ||
declare const _default: (scope: Scope) => Promise<void>; | ||
export default _default; | ||
//# sourceMappingURL=create-customized-project.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const inquirer_1 = __importDefault(require("inquirer")); | ||
const lodash_1 = require("lodash"); | ||
const usage_1 = require("./utils/usage"); | ||
const db_configs_1 = __importDefault(require("./utils/db-configs")); | ||
const db_client_dependencies_1 = __importDefault(require("./utils/db-client-dependencies")); | ||
const db_questions_1 = __importDefault(require("./utils/db-questions")); | ||
const create_project_1 = __importDefault(require("./create-project")); | ||
const inquirer = require("inquirer"); | ||
const _ = require("lodash"); | ||
const usage = require("./utils/usage.js"); | ||
const dbConfigs = require("./utils/db-configs.js"); | ||
const dbClientDependencies = require("./utils/db-client-dependencies.js"); | ||
const dbQuestions = require("./utils/db-questions.js"); | ||
const createProject = require("./create-project.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const inquirer__default = /* @__PURE__ */ _interopDefault(inquirer); | ||
const LANGUAGES = { | ||
javascript: 'JavaScript', | ||
typescript: 'TypeScript', | ||
javascript: "JavaScript", | ||
typescript: "TypeScript" | ||
}; | ||
exports.default = async (scope) => { | ||
if (!scope.useTypescript) { | ||
const language = await askAboutLanguages(); | ||
scope.useTypescript = language === LANGUAGES.typescript; | ||
} | ||
await (0, usage_1.trackUsage)({ event: 'didChooseCustomDatabase', scope }); | ||
const configuration = await askDbInfosAndTest(scope).catch((error) => { | ||
return (0, usage_1.trackUsage)({ event: 'didNotConnectDatabase', scope, error }).then(() => { | ||
throw error; | ||
}); | ||
const createCustomizedProject = async (scope) => { | ||
if (!scope.useTypescript) { | ||
const language = await askAboutLanguages(); | ||
scope.useTypescript = language === LANGUAGES.typescript; | ||
} | ||
await usage.trackUsage({ event: "didChooseCustomDatabase", scope }); | ||
const configuration = await askDbInfosAndTest(scope).catch((error) => { | ||
return usage.trackUsage({ event: "didNotConnectDatabase", scope, error }).then(() => { | ||
throw error; | ||
}); | ||
console.log(); | ||
console.log('Creating a project with custom database options.'); | ||
await (0, usage_1.trackUsage)({ event: 'didConnectDatabase', scope }); | ||
return (0, create_project_1.default)(scope, configuration); | ||
}); | ||
console.log(); | ||
console.log("Creating a project with custom database options."); | ||
await usage.trackUsage({ event: "didConnectDatabase", scope }); | ||
return createProject(scope, configuration); | ||
}; | ||
async function askDbInfosAndTest(scope) { | ||
const { client, connection } = await askDatabaseInfos(scope); | ||
return { | ||
client, | ||
connection, | ||
dependencies: (0, db_client_dependencies_1.default)({ client }), | ||
}; | ||
const { client, connection } = await askDatabaseInfos(scope); | ||
return { | ||
client, | ||
connection, | ||
dependencies: { | ||
...dbClientDependencies({ client }), | ||
...scope.additionalsDependencies | ||
} | ||
}; | ||
} | ||
async function askDatabaseInfos(scope) { | ||
const { client } = await inquirer_1.default.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'client', | ||
message: 'Choose your default database client', | ||
choices: ['sqlite', 'postgres', 'mysql'], | ||
default: 'sqlite', | ||
}, | ||
]); | ||
const questions = db_questions_1.default[client].map((q) => q({ scope, client })); | ||
if (!questions) { | ||
return { client }; | ||
const { client } = await inquirer__default.default.prompt([ | ||
{ | ||
type: "list", | ||
name: "client", | ||
message: "Choose your default database client", | ||
choices: ["sqlite", "postgres", "mysql"], | ||
default: "sqlite" | ||
} | ||
const responses = await inquirer_1.default.prompt(questions); | ||
const connection = (0, lodash_1.merge)({}, db_configs_1.default[client] || {}, { | ||
client, | ||
connection: responses, | ||
}); | ||
return { | ||
client, | ||
connection, | ||
}; | ||
]); | ||
const questions = dbQuestions[client].map((q) => q({ scope, client })); | ||
if (!questions) { | ||
return { client }; | ||
} | ||
const responses = await inquirer__default.default.prompt(questions); | ||
const connection = _.merge({}, dbConfigs[client] || {}, { | ||
client, | ||
connection: responses | ||
}); | ||
return { | ||
client, | ||
connection | ||
}; | ||
} | ||
async function askAboutLanguages() { | ||
const { language } = await inquirer_1.default.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'language', | ||
message: 'Choose your preferred language', | ||
choices: Object.values(LANGUAGES), | ||
default: LANGUAGES.javascript, | ||
}, | ||
]); | ||
return language; | ||
const { language } = await inquirer__default.default.prompt([ | ||
{ | ||
type: "list", | ||
name: "language", | ||
message: "Choose your preferred language", | ||
choices: Object.values(LANGUAGES), | ||
default: LANGUAGES.javascript | ||
} | ||
]); | ||
return language; | ||
} | ||
//# sourceMappingURL=create-customized-project.js.map | ||
module.exports = createCustomizedProject; | ||
//# sourceMappingURL=create-customized-project.js.map |
import { Configuration, Scope } from './types'; | ||
export default function createProject(scope: Scope, { client, connection, dependencies }: Configuration): Promise<void>; | ||
//# sourceMappingURL=create-project.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const path_1 = require("path"); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const execa_1 = __importDefault(require("execa")); | ||
const ora_1 = __importDefault(require("ora")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const stop_process_1 = __importDefault(require("./utils/stop-process")); | ||
const usage_1 = require("./utils/usage"); | ||
const merge_template_js_1 = __importDefault(require("./utils/merge-template.js")); | ||
const git_1 = __importDefault(require("./utils/git")); | ||
const package_json_1 = __importDefault(require("./resources/json/common/package.json")); | ||
const database_1 = require("./resources/templates/database"); | ||
const env_1 = __importDefault(require("./resources/templates/env")); | ||
const types_1 = require("./types"); | ||
const path = require("path"); | ||
const fse = require("fs-extra"); | ||
const chalk = require("chalk"); | ||
const execa = require("execa"); | ||
const ora = require("ora"); | ||
const _ = require("lodash"); | ||
const stopProcess = require("./utils/stop-process.js"); | ||
const usage = require("./utils/usage.js"); | ||
const mergeTemplate = require("./utils/merge-template.js"); | ||
const git = require("./utils/git.js"); | ||
const package_json = require("./resources/json/common/package.json.js"); | ||
const jsconfig_json = require("./resources/json/js/jsconfig.json.js"); | ||
const tsconfigAdmin_json = require("./resources/json/ts/tsconfig-admin.json.js"); | ||
const tsconfigServer_json = require("./resources/json/ts/tsconfig-server.json.js"); | ||
const database = require("./resources/templates/database.js"); | ||
const env = require("./resources/templates/env.js"); | ||
const types = require("./types.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const fse__default = /* @__PURE__ */ _interopDefault(fse); | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
const execa__default = /* @__PURE__ */ _interopDefault(execa); | ||
const ora__default = /* @__PURE__ */ _interopDefault(ora); | ||
const ___default = /* @__PURE__ */ _interopDefault(_); | ||
async function createProject(scope, { client, connection, dependencies }) { | ||
console.log(`Creating a new Strapi application at ${chalk_1.default.green(scope.rootPath)}.`); | ||
console.log('Creating files.'); | ||
const { rootPath, useTypescript } = scope; | ||
const resources = (0, path_1.join)(__dirname, 'resources'); | ||
const language = useTypescript ? 'ts' : 'js'; | ||
try { | ||
// copy files | ||
await fs_extra_1.default.copy((0, path_1.join)(resources, 'files', language), rootPath); | ||
// copy dot files | ||
await fs_extra_1.default.writeFile((0, path_1.join)(rootPath, '.env'), (0, env_1.default)()); | ||
const copyDotFilesFromSubDirectory = (subDirectory) => { | ||
const files = fs_extra_1.default.readdirSync((0, path_1.join)(resources, 'dot-files', subDirectory)); | ||
return Promise.all(files.map((file) => { | ||
const src = (0, path_1.join)(resources, 'dot-files', subDirectory, file); | ||
const dest = (0, path_1.join)(rootPath, `.${file}`); | ||
return fs_extra_1.default.copy(src, dest); | ||
})); | ||
}; | ||
// Copy common dot files | ||
copyDotFilesFromSubDirectory('common'); | ||
// Copy JS dot files | ||
// For now we only support javascript and typescript, so if we're not using | ||
// typescript, then we can assume we're using javascript. We'll need to change | ||
// this behavior when we'll abstract the supported languages even more. | ||
if (!useTypescript) { | ||
copyDotFilesFromSubDirectory('js'); | ||
console.log(`Creating a new Strapi application at ${chalk__default.default.green(scope.rootPath)}.`); | ||
console.log("Creating files."); | ||
const { rootPath, useTypescript } = scope; | ||
const resources = path.join(__dirname, "resources"); | ||
const language = useTypescript ? "ts" : "js"; | ||
try { | ||
await fse__default.default.copy(path.join(resources, "files", language), rootPath); | ||
await fse__default.default.writeFile(path.join(rootPath, ".env"), env()); | ||
const copyDotFilesFromSubDirectory = (subDirectory) => { | ||
const files = fse__default.default.readdirSync(path.join(resources, "dot-files", subDirectory)); | ||
return Promise.all( | ||
files.map((file) => { | ||
const src = path.join(resources, "dot-files", subDirectory, file); | ||
const dest = path.join(rootPath, `.${file}`); | ||
return fse__default.default.copy(src, dest); | ||
}) | ||
); | ||
}; | ||
copyDotFilesFromSubDirectory("common"); | ||
if (!useTypescript) { | ||
copyDotFilesFromSubDirectory("js"); | ||
} | ||
await usage.trackUsage({ event: "didCopyProjectFiles", scope }); | ||
await fse__default.default.writeJSON( | ||
path.join(rootPath, "package.json"), | ||
package_json({ | ||
strapiDependencies: scope.strapiDependencies, | ||
additionalsDependencies: dependencies, | ||
strapiVersion: scope.strapiVersion, | ||
projectName: ___default.default.kebabCase(scope.name), | ||
uuid: scope.uuid, | ||
packageJsonStrapi: scope.packageJsonStrapi | ||
}), | ||
{ | ||
spaces: 2 | ||
} | ||
); | ||
await usage.trackUsage({ event: "didWritePackageJSON", scope }); | ||
if (useTypescript) { | ||
const filesMap = { | ||
"tsconfig-admin.json.js": "src/admin", | ||
"tsconfig-server.json.js": "." | ||
}; | ||
for (const [fileName, path$1] of Object.entries(filesMap)) { | ||
const destPath = path.join(rootPath, path$1, "tsconfig.json"); | ||
if (fileName === "tsconfig-admin.json.js") { | ||
await fse__default.default.writeJSON(destPath, tsconfigAdmin_json(), { spaces: 2 }); | ||
} | ||
await (0, usage_1.trackUsage)({ event: 'didCopyProjectFiles', scope }); | ||
// copy templates | ||
await fs_extra_1.default.writeJSON((0, path_1.join)(rootPath, 'package.json'), (0, package_json_1.default)({ | ||
strapiDependencies: scope.strapiDependencies, | ||
additionalsDependencies: dependencies, | ||
strapiVersion: scope.strapiVersion, | ||
projectName: lodash_1.default.kebabCase(scope.name), | ||
uuid: scope.uuid, | ||
packageJsonStrapi: scope.packageJsonStrapi, | ||
}), { | ||
spaces: 2, | ||
}); | ||
await (0, usage_1.trackUsage)({ event: 'didWritePackageJSON', scope }); | ||
if (useTypescript) { | ||
const tsJSONDir = (0, path_1.join)(__dirname, 'resources/json/ts'); | ||
const filesMap = { | ||
'tsconfig-admin.json.js': 'src/admin', | ||
'tsconfig-server.json.js': '.', | ||
}; | ||
for (const [fileName, path] of Object.entries(filesMap)) { | ||
const srcPath = (0, path_1.join)(tsJSONDir, fileName); | ||
const destPath = (0, path_1.join)(rootPath, path, 'tsconfig.json'); | ||
const json = require(srcPath).default(); | ||
await fs_extra_1.default.writeJSON(destPath, json, { spaces: 2 }); | ||
} | ||
if (fileName === "tsconfig-server.json.js") { | ||
await fse__default.default.writeJSON(destPath, tsconfigServer_json(), { spaces: 2 }); | ||
} | ||
else { | ||
const jsJSONDir = (0, path_1.join)(__dirname, 'resources/json/js'); | ||
const filesMap = { 'jsconfig.json.js': '.' }; | ||
for (const [fileName, path] of Object.entries(filesMap)) { | ||
const srcPath = (0, path_1.join)(jsJSONDir, fileName); | ||
const destPath = (0, path_1.join)(rootPath, path, 'jsconfig.json'); | ||
const json = require(srcPath).default(); | ||
await fs_extra_1.default.writeJSON(destPath, json, { spaces: 2 }); | ||
} | ||
} | ||
// ensure node_modules is created | ||
await fs_extra_1.default.ensureDir((0, path_1.join)(rootPath, 'node_modules')); | ||
// create config/database | ||
await fs_extra_1.default.appendFile((0, path_1.join)(rootPath, '.env'), (0, database_1.generateDbEnvariables)({ client, connection })); | ||
await fs_extra_1.default.writeFile((0, path_1.join)(rootPath, `config/database.${language}`), (0, database_1.createDatabaseConfig)({ useTypescript })); | ||
await (0, usage_1.trackUsage)({ event: 'didCopyConfigurationFiles', scope }); | ||
// merge template files if a template is specified | ||
const hasTemplate = Boolean(scope.template); | ||
if (hasTemplate) { | ||
try { | ||
await (0, merge_template_js_1.default)(scope, rootPath); | ||
} | ||
catch (error) { | ||
if (error instanceof Error) { | ||
throw new Error(`⛔️ Template installation failed: ${error.message}`); | ||
} | ||
throw error; | ||
} | ||
} | ||
} | ||
} else { | ||
const filesMap = { "jsconfig.json.js": "." }; | ||
for (const [, path$1] of Object.entries(filesMap)) { | ||
const destPath = path.join(rootPath, path$1, "jsconfig.json"); | ||
await fse__default.default.writeJSON(destPath, jsconfig_json(), { spaces: 2 }); | ||
} | ||
} | ||
catch (err) { | ||
await fs_extra_1.default.remove(scope.rootPath); | ||
throw err; | ||
} | ||
await (0, usage_1.trackUsage)({ event: 'willInstallProjectDependencies', scope }); | ||
const installPrefix = chalk_1.default.yellow('Installing dependencies:'); | ||
const loader = (0, ora_1.default)(installPrefix).start(); | ||
const logInstall = (chunk = '') => { | ||
loader.text = `${installPrefix} ${chunk.toString().split('\n').join(' ')}`; | ||
}; | ||
try { | ||
if (scope.installDependencies !== false) { | ||
const runner = runInstall(scope); | ||
runner.stdout?.on('data', logInstall); | ||
runner.stderr?.on('data', logInstall); | ||
await runner; | ||
await fse__default.default.ensureDir(path.join(rootPath, "node_modules")); | ||
await fse__default.default.appendFile(path.join(rootPath, ".env"), database.generateDbEnvariables({ client, connection })); | ||
await fse__default.default.writeFile( | ||
path.join(rootPath, `config/database.${language}`), | ||
database.createDatabaseConfig({ useTypescript }) | ||
); | ||
await usage.trackUsage({ event: "didCopyConfigurationFiles", scope }); | ||
const hasTemplate = Boolean(scope.template); | ||
if (hasTemplate) { | ||
try { | ||
await mergeTemplate(scope, rootPath); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
throw new Error(`⛔️ Template installation failed: ${error.message}`); | ||
} | ||
loader.stop(); | ||
console.log(`Dependencies installed ${chalk_1.default.green('successfully')}.`); | ||
await (0, usage_1.trackUsage)({ event: 'didInstallProjectDependencies', scope }); | ||
throw error; | ||
} | ||
} | ||
catch (error) { | ||
const stderr = (0, types_1.isStderrError)(error) ? error.stderr : ''; | ||
loader.stop(); | ||
await (0, usage_1.trackUsage)({ | ||
event: 'didNotInstallProjectDependencies', | ||
scope, | ||
error: stderr.slice(-1024), | ||
}); | ||
console.error(`${chalk_1.default.red('Error')} while installing dependencies:`); | ||
console.error(stderr); | ||
await (0, usage_1.captureStderr)('didNotInstallProjectDependencies', error); | ||
console.log(chalk_1.default.black.bgWhite(' Keep trying!')); | ||
console.log(); | ||
console.log(chalk_1.default.bold('Oh, it seems that you encountered errors while installing dependencies in your project.')); | ||
console.log(`Don't give up, your project was created correctly.`); | ||
console.log(`Fix the issues mentioned in the installation errors and try to run the following command:`); | ||
console.log(); | ||
console.log(`cd ${chalk_1.default.green(rootPath)} && ${chalk_1.default.cyan(scope.useYarn ? 'yarn' : 'npm')} install`); | ||
console.log(); | ||
(0, stop_process_1.default)(); | ||
} catch (err) { | ||
await fse__default.default.remove(scope.rootPath); | ||
throw err; | ||
} | ||
await usage.trackUsage({ event: "willInstallProjectDependencies", scope }); | ||
const installPrefix = chalk__default.default.yellow("Installing dependencies:"); | ||
const loader = ora__default.default(installPrefix).start(); | ||
const logInstall = (chunk = "") => { | ||
loader.text = `${installPrefix} ${chunk.toString().split("\n").join(" ")}`; | ||
}; | ||
try { | ||
if (scope.installDependencies !== false) { | ||
const runner = runInstall(scope); | ||
runner.stdout?.on("data", logInstall); | ||
runner.stderr?.on("data", logInstall); | ||
await runner; | ||
} | ||
await (0, usage_1.trackUsage)({ event: 'didCreateProject', scope }); | ||
// Init git | ||
if (await (0, git_1.default)(rootPath)) { | ||
console.log('Initialized a git repository.'); | ||
console.log(); | ||
} | ||
loader.stop(); | ||
console.log(`Dependencies installed ${chalk__default.default.green("successfully")}.`); | ||
await usage.trackUsage({ event: "didInstallProjectDependencies", scope }); | ||
} catch (error) { | ||
const stderr = types.isStderrError(error) ? error.stderr : ""; | ||
loader.stop(); | ||
await usage.trackUsage({ | ||
event: "didNotInstallProjectDependencies", | ||
scope, | ||
error: stderr.slice(-1024) | ||
}); | ||
console.error(`${chalk__default.default.red("Error")} while installing dependencies:`); | ||
console.error(stderr); | ||
await usage.captureStderr("didNotInstallProjectDependencies", error); | ||
console.log(chalk__default.default.black.bgWhite(" Keep trying!")); | ||
console.log(); | ||
console.log(`Your application was created at ${chalk_1.default.green(rootPath)}.\n`); | ||
const cmd = chalk_1.default.cyan(scope.useYarn ? 'yarn' : 'npm run'); | ||
console.log('Available commands in your project:'); | ||
console.log( | ||
chalk__default.default.bold( | ||
"Oh, it seems that you encountered errors while installing dependencies in your project." | ||
) | ||
); | ||
console.log(`Don't give up, your project was created correctly.`); | ||
console.log( | ||
`Fix the issues mentioned in the installation errors and try to run the following command:` | ||
); | ||
console.log(); | ||
console.log(` ${cmd} develop`); | ||
console.log(' Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart)'); | ||
console.log( | ||
`cd ${chalk__default.default.green(rootPath)} && ${chalk__default.default.cyan(scope.useYarn ? "yarn" : "npm")} install` | ||
); | ||
console.log(); | ||
console.log(` ${cmd} start`); | ||
console.log(' Start Strapi without watch mode.'); | ||
stopProcess(); | ||
} | ||
await usage.trackUsage({ event: "didCreateProject", scope }); | ||
if (await git(rootPath)) { | ||
console.log("Initialized a git repository."); | ||
console.log(); | ||
console.log(` ${cmd} build`); | ||
console.log(' Build Strapi admin panel.'); | ||
console.log(); | ||
console.log(` ${cmd} strapi`); | ||
console.log(` Display all available commands.`); | ||
console.log(); | ||
console.log('You can start by doing:'); | ||
console.log(); | ||
console.log(` ${chalk_1.default.cyan('cd')} ${rootPath}`); | ||
console.log(` ${cmd} develop`); | ||
console.log(); | ||
} | ||
console.log(); | ||
console.log(`Your application was created at ${chalk__default.default.green(rootPath)}. | ||
`); | ||
const cmd = chalk__default.default.cyan(scope.useYarn ? "yarn" : "npm run"); | ||
console.log("Available commands in your project:"); | ||
console.log(); | ||
console.log(` ${cmd} develop`); | ||
console.log( | ||
" Start Strapi in watch mode. (Changes in Strapi project files will trigger a server restart)" | ||
); | ||
console.log(); | ||
console.log(` ${cmd} start`); | ||
console.log(" Start Strapi without watch mode."); | ||
console.log(); | ||
console.log(` ${cmd} build`); | ||
console.log(" Build Strapi admin panel."); | ||
console.log(); | ||
console.log(` ${cmd} deploy`); | ||
console.log(" Deploy Strapi project."); | ||
console.log(); | ||
console.log(` ${cmd} strapi`); | ||
console.log(` Display all available commands.`); | ||
console.log(); | ||
console.log("You can start by doing:"); | ||
console.log(); | ||
console.log(` ${chalk__default.default.cyan("cd")} ${rootPath}`); | ||
console.log(` ${cmd} develop`); | ||
console.log(); | ||
} | ||
exports.default = createProject; | ||
const installArguments = ['install', '--production', '--no-optional']; | ||
const installArguments = ["install", "--production", "--no-optional"]; | ||
function runInstall({ rootPath, useYarn }) { | ||
if (useYarn) { | ||
// Increase timeout for slow internet connections. | ||
installArguments.push('--network-timeout 1000000'); | ||
return (0, execa_1.default)('yarnpkg', installArguments, { | ||
cwd: rootPath, | ||
stdin: 'ignore', | ||
}); | ||
} | ||
return (0, execa_1.default)('npm', installArguments, { cwd: rootPath, stdin: 'ignore' }); | ||
if (useYarn) { | ||
installArguments.push("--network-timeout 1000000"); | ||
return execa__default.default("yarnpkg", installArguments, { | ||
cwd: rootPath, | ||
stdin: "ignore" | ||
}); | ||
} | ||
return execa__default.default("npm", installArguments, { cwd: rootPath, stdin: "ignore" }); | ||
} | ||
//# sourceMappingURL=create-project.js.map | ||
module.exports = createProject; | ||
//# sourceMappingURL=create-project.js.map |
import type { Scope } from './types'; | ||
export default function createQuickStartProject(scope: Scope): Promise<void>; | ||
//# sourceMappingURL=create-quickstart-project.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const execa_1 = __importDefault(require("execa")); | ||
const usage_1 = require("./utils/usage"); | ||
const db_configs_js_1 = __importDefault(require("./utils/db-configs.js")); | ||
const db_client_dependencies_js_1 = __importDefault(require("./utils/db-client-dependencies.js")); | ||
const create_project_1 = __importDefault(require("./create-project")); | ||
const execa = require("execa"); | ||
const usage = require("./utils/usage.js"); | ||
const dbConfigs = require("./utils/db-configs.js"); | ||
const dbClientDependencies = require("./utils/db-client-dependencies.js"); | ||
const createProject = require("./create-project.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const execa__default = /* @__PURE__ */ _interopDefault(execa); | ||
async function createQuickStartProject(scope) { | ||
console.log('Creating a quickstart project.'); | ||
await (0, usage_1.trackUsage)({ event: 'didChooseQuickstart', scope }); | ||
// get default sqlite config | ||
const client = 'sqlite'; | ||
const configuration = { | ||
client, | ||
connection: db_configs_js_1.default[client], | ||
dependencies: (0, db_client_dependencies_js_1.default)({ client }), | ||
}; | ||
await (0, create_project_1.default)(scope, configuration); | ||
if (scope.runQuickstartApp !== true) | ||
return; | ||
console.log(`Running your Strapi application.`); | ||
try { | ||
await (0, usage_1.trackUsage)({ event: 'willStartServer', scope }); | ||
await (0, execa_1.default)('npm', ['run', 'develop'], { | ||
stdio: 'inherit', | ||
cwd: scope.rootPath, | ||
env: { | ||
FORCE_COLOR: '1', | ||
}, | ||
}); | ||
console.log("Creating a quickstart project."); | ||
await usage.trackUsage({ event: "didChooseQuickstart", scope }); | ||
const client = "sqlite"; | ||
const configuration = { | ||
client, | ||
connection: dbConfigs[client], | ||
dependencies: { ...dbClientDependencies({ client }), ...scope.additionalsDependencies } | ||
}; | ||
await createProject(scope, configuration); | ||
if (scope.runQuickstartApp !== true) | ||
return; | ||
console.log(`Running your Strapi application.`); | ||
try { | ||
await usage.trackUsage({ event: "willStartServer", scope }); | ||
await execa__default.default("npm", ["run", "develop"], { | ||
stdio: "inherit", | ||
cwd: scope.rootPath, | ||
env: { | ||
FORCE_COLOR: "1" | ||
} | ||
}); | ||
} catch (error) { | ||
if (typeof error === "string" || error instanceof Error) { | ||
await usage.trackUsage({ | ||
event: "didNotStartServer", | ||
scope, | ||
error | ||
}); | ||
await usage.captureStderr("didNotStartServer", error); | ||
} | ||
catch (error) { | ||
if (typeof error === 'string' || error instanceof Error) { | ||
await (0, usage_1.trackUsage)({ | ||
event: 'didNotStartServer', | ||
scope, | ||
error, | ||
}); | ||
await (0, usage_1.captureStderr)('didNotStartServer', error); | ||
} | ||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
} | ||
exports.default = createQuickStartProject; | ||
//# sourceMappingURL=create-quickstart-project.js.map | ||
module.exports = createQuickStartProject; | ||
//# sourceMappingURL=create-quickstart-project.js.map |
import type { Scope } from './types'; | ||
declare const _default: (scope: Scope) => Promise<void>; | ||
export default _default; | ||
//# sourceMappingURL=generate-new.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const usage = require("./utils/usage.js"); | ||
const checkInstallPath = require("./utils/check-install-path.js"); | ||
const createCliDbProject = require("./create-cli-db-project.js"); | ||
const createCustomizedProject = require("./create-customized-project.js"); | ||
const createQuickstartProject = require("./create-quickstart-project.js"); | ||
const generateNew = async (scope) => { | ||
const hasDatabaseConfig = Boolean(scope.database); | ||
checkInstallPath(scope.rootPath); | ||
await usage.trackUsage({ event: "willCreateProject", scope }); | ||
if (hasDatabaseConfig) { | ||
return createCliDbProject(scope); | ||
} | ||
if (scope.quick === true) { | ||
return createQuickstartProject(scope); | ||
} | ||
return createCustomizedProject(scope); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const usage_1 = require("./utils/usage"); | ||
const check_install_path_1 = __importDefault(require("./utils/check-install-path")); | ||
const create_cli_db_project_1 = __importDefault(require("./create-cli-db-project")); | ||
const create_customized_project_1 = __importDefault(require("./create-customized-project")); | ||
const create_quickstart_project_1 = __importDefault(require("./create-quickstart-project")); | ||
exports.default = async (scope) => { | ||
const hasDatabaseConfig = Boolean(scope.database); | ||
// check rootPath is empty | ||
(0, check_install_path_1.default)(scope.rootPath); | ||
await (0, usage_1.trackUsage)({ event: 'willCreateProject', scope }); | ||
// if database config is provided don't test the connection and create the project directly | ||
if (hasDatabaseConfig) { | ||
return (0, create_cli_db_project_1.default)(scope); | ||
} | ||
// if cli quickstart create project with default sqlite options | ||
if (scope.quick === true) { | ||
return (0, create_quickstart_project_1.default)(scope); | ||
} | ||
// create a project with full list of questions | ||
return (0, create_customized_project_1.default)(scope); | ||
}; | ||
//# sourceMappingURL=generate-new.js.map | ||
module.exports = generateNew; | ||
//# sourceMappingURL=generate-new.js.map |
import type { NewOptions } from './types'; | ||
export { default as checkInstallPath } from './utils/check-install-path'; | ||
export type { NewOptions } from './types'; | ||
export declare const generateNewApp: (projectDirectory: string, options: Partial<NewOptions>) => Promise<void>; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
const node_path = require("node:path"); | ||
const node_fs = require("node:fs"); | ||
const os = require("node:os"); | ||
const readline = require("node:readline"); | ||
const crypto = require("crypto"); | ||
const sentry = require("@sentry/node"); | ||
const hasYarn = require("./utils/has-yarn.js"); | ||
const checkRequirements = require("./utils/check-requirements.js"); | ||
const usage = require("./utils/usage.js"); | ||
const parseDbArguments = require("./utils/parse-db-arguments.js"); | ||
const generateNew = require("./generate-new.js"); | ||
const machineId = require("./utils/machine-id.js"); | ||
const checkInstallPath = require("./utils/check-install-path.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) | ||
return e; | ||
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); | ||
if (e) { | ||
for (const k in e) { | ||
if (k !== "default") { | ||
const d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: () => e[k] | ||
}); | ||
} | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateNewApp = exports.checkInstallPath = void 0; | ||
const node_path_1 = require("node:path"); | ||
const node_fs_1 = require("node:fs"); | ||
const node_os_1 = __importDefault(require("node:os")); | ||
const node_readline_1 = __importDefault(require("node:readline")); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const sentry = __importStar(require("@sentry/node")); | ||
const has_yarn_1 = __importDefault(require("./utils/has-yarn")); | ||
const check_requirements_1 = __importDefault(require("./utils/check-requirements")); | ||
const usage_1 = require("./utils/usage"); | ||
const parse_db_arguments_1 = __importDefault(require("./utils/parse-db-arguments")); | ||
const generate_new_1 = __importDefault(require("./generate-new")); | ||
const machine_id_1 = __importDefault(require("./utils/machine-id")); | ||
var check_install_path_1 = require("./utils/check-install-path"); | ||
Object.defineProperty(exports, "checkInstallPath", { enumerable: true, get: function () { return __importDefault(check_install_path_1).default; } }); | ||
const packageJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.resolve)(__dirname, '../package.json'), 'utf8')); | ||
} | ||
n.default = e; | ||
return Object.freeze(n); | ||
} | ||
const os__default = /* @__PURE__ */ _interopDefault(os); | ||
const readline__default = /* @__PURE__ */ _interopDefault(readline); | ||
const crypto__default = /* @__PURE__ */ _interopDefault(crypto); | ||
const sentry__namespace = /* @__PURE__ */ _interopNamespace(sentry); | ||
const packageJson = JSON.parse(node_fs.readFileSync(node_path.resolve(__dirname, "../package.json"), "utf8")); | ||
const generateNewApp = (projectDirectory, options) => { | ||
sentry.init({ | ||
dsn: 'https://841d2b2c9b4d4b43a4cde92794cb705a@sentry.io/1762059', | ||
}); | ||
(0, check_requirements_1.default)(); | ||
const rootPath = (0, node_path_1.resolve)(projectDirectory); | ||
const tmpPath = (0, node_path_1.join)(node_os_1.default.tmpdir(), `strapi${crypto_1.default.randomBytes(6).toString('hex')}`); | ||
const useNpm = options.useNpm !== undefined; | ||
const scope = { | ||
rootPath, | ||
name: (0, node_path_1.basename)(rootPath), | ||
// disable quickstart run app after creation | ||
runQuickstartApp: options.run !== false, | ||
// use pacakge version as strapiVersion (all packages have the same version); | ||
strapiVersion: packageJson.version, | ||
debug: options.debug !== undefined, | ||
quick: options.quickstart, | ||
template: options.template, | ||
packageJsonStrapi: { | ||
template: options.template, | ||
starter: options.starter, | ||
}, | ||
uuid: (process.env.STRAPI_UUID_PREFIX || '') + crypto_1.default.randomUUID(), | ||
docker: process.env.DOCKER === 'true', | ||
deviceId: (0, machine_id_1.default)(), | ||
tmpPath, | ||
// use yarn if available and --use-npm isn't true | ||
useYarn: !useNpm && (0, has_yarn_1.default)(), | ||
installDependencies: true, | ||
strapiDependencies: [ | ||
'@strapi/strapi', | ||
'@strapi/plugin-users-permissions', | ||
'@strapi/plugin-i18n', | ||
], | ||
additionalsDependencies: {}, | ||
useTypescript: Boolean(options.typescript), | ||
sentry__namespace.init({ | ||
dsn: "https://841d2b2c9b4d4b43a4cde92794cb705a@sentry.io/1762059" | ||
}); | ||
checkRequirements(); | ||
const rootPath = node_path.resolve(projectDirectory); | ||
const tmpPath = node_path.join(os__default.default.tmpdir(), `strapi${crypto__default.default.randomBytes(6).toString("hex")}`); | ||
const useNpm = options.useNpm !== void 0; | ||
const scope = { | ||
rootPath, | ||
name: node_path.basename(rootPath), | ||
// disable quickstart run app after creation | ||
runQuickstartApp: options.run !== false, | ||
// use pacakge version as strapiVersion (all packages have the same version); | ||
strapiVersion: packageJson.version, | ||
debug: options.debug !== void 0, | ||
quick: options.quickstart, | ||
template: options.template, | ||
packageJsonStrapi: { | ||
template: options.template, | ||
starter: options.starter | ||
}, | ||
uuid: (process.env.STRAPI_UUID_PREFIX || "") + crypto__default.default.randomUUID(), | ||
docker: process.env.DOCKER === "true", | ||
deviceId: machineId(), | ||
tmpPath, | ||
// use yarn if available and --use-npm isn't true | ||
useYarn: !useNpm && hasYarn(), | ||
installDependencies: true, | ||
strapiDependencies: [ | ||
"@strapi/strapi", | ||
"@strapi/plugin-users-permissions", | ||
"@strapi/plugin-i18n", | ||
"@strapi/plugin-cloud" | ||
], | ||
additionalsDependencies: { | ||
react: "^18.0.0", | ||
"react-dom": "^18.0.0", | ||
"react-router-dom": "5.3.4", | ||
"styled-components": "5.3.3" | ||
}, | ||
useTypescript: Boolean(options.typescript) | ||
}; | ||
sentry__namespace.configureScope(function configureScope(sentryScope) { | ||
const tags = { | ||
os: os__default.default.type(), | ||
osPlatform: os__default.default.platform(), | ||
osArch: os__default.default.arch(), | ||
osRelease: os__default.default.release(), | ||
version: scope.strapiVersion, | ||
nodeVersion: process.versions.node, | ||
docker: scope.docker | ||
}; | ||
sentry.configureScope(function configureScope(sentryScope) { | ||
const tags = { | ||
os: node_os_1.default.type(), | ||
osPlatform: node_os_1.default.platform(), | ||
osArch: node_os_1.default.arch(), | ||
osRelease: node_os_1.default.release(), | ||
version: scope.strapiVersion, | ||
nodeVersion: process.versions.node, | ||
docker: scope.docker, | ||
}; | ||
Object.keys(tags).forEach((tag) => { | ||
sentryScope.setTag(tag, tags[tag]); | ||
}); | ||
Object.keys(tags).forEach((tag) => { | ||
sentryScope.setTag(tag, tags[tag]); | ||
}); | ||
(0, parse_db_arguments_1.default)({ scope, args: options }); | ||
initCancelCatcher(); | ||
return (0, generate_new_1.default)(scope).catch((error) => { | ||
console.error(error); | ||
return (0, usage_1.captureException)(error).then(() => { | ||
return (0, usage_1.trackError)({ scope, error }).then(() => { | ||
process.exit(1); | ||
}); | ||
}); | ||
}); | ||
parseDbArguments({ scope, args: options }); | ||
initCancelCatcher(); | ||
return generateNew(scope).catch((error) => { | ||
console.error(error); | ||
return usage.captureException(error).then(() => { | ||
return usage.trackError({ scope, error }).then(() => { | ||
process.exit(1); | ||
}); | ||
}); | ||
}); | ||
}; | ||
exports.generateNewApp = generateNewApp; | ||
function initCancelCatcher() { | ||
// Create interface for windows user to let them quit the program. | ||
if (process.platform === 'win32') { | ||
const rl = node_readline_1.default.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
rl.on('SIGINT', function sigint() { | ||
process.emit('SIGINT'); | ||
}); | ||
} | ||
process.on('SIGINT', () => { | ||
process.exit(1); | ||
if (process.platform === "win32") { | ||
const rl = readline__default.default.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
rl.on("SIGINT", function sigint() { | ||
process.emit("SIGINT"); | ||
}); | ||
} | ||
process.on("SIGINT", () => { | ||
process.exit(1); | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map | ||
exports.checkInstallPath = checkInstallPath; | ||
exports.generateNewApp = generateNewApp; | ||
//# sourceMappingURL=index.js.map |
@@ -13,2 +13,6 @@ module.exports = ({ env }) => ({ | ||
}, | ||
flags: { | ||
nps: env.bool('FLAG_NPS', true), | ||
promoteEE: env.bool('FLAG_PROMOTE_EE', true), | ||
}, | ||
}); |
module.exports = [ | ||
'strapi::logger', | ||
'strapi::errors', | ||
@@ -6,3 +7,2 @@ 'strapi::security', | ||
'strapi::poweredBy', | ||
'strapi::logger', | ||
'strapi::query', | ||
@@ -9,0 +9,0 @@ 'strapi::body', |
@@ -39,2 +39,6 @@ # 🚀 Getting started with Strapi | ||
``` | ||
yarn strapi deploy | ||
``` | ||
## 📚 Learn more | ||
@@ -41,0 +45,0 @@ |
@@ -13,2 +13,6 @@ export default ({ env }) => ({ | ||
}, | ||
flags: { | ||
nps: env.bool('FLAG_NPS', true), | ||
promoteEE: env.bool('FLAG_PROMOTE_EE', true), | ||
}, | ||
}); |
export default [ | ||
'strapi::logger', | ||
'strapi::errors', | ||
@@ -6,3 +7,2 @@ 'strapi::security', | ||
'strapi::poweredBy', | ||
'strapi::logger', | ||
'strapi::query', | ||
@@ -9,0 +9,0 @@ 'strapi::body', |
@@ -39,2 +39,6 @@ # 🚀 Getting started with Strapi | ||
``` | ||
yarn strapi deploy | ||
``` | ||
## 📚 Learn more | ||
@@ -41,0 +45,0 @@ |
@@ -6,1 +6,2 @@ declare const _default: { | ||
export default _default; | ||
//# sourceMappingURL=engines.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = { | ||
node: '>=16.0.0 <=20.x.x', | ||
npm: '>=6.0.0', | ||
const engines = { | ||
node: ">=18.0.0 <=20.x.x", | ||
npm: ">=6.0.0" | ||
}; | ||
//# sourceMappingURL=engines.js.map | ||
module.exports = engines; | ||
//# sourceMappingURL=engines.js.map |
@@ -16,2 +16,3 @@ import { Scope } from '../../../types'; | ||
strapi: string; | ||
deploy: string; | ||
}; | ||
@@ -35,1 +36,2 @@ devDependencies: {}; | ||
export default _default; | ||
//# sourceMappingURL=package.json.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const engines = require("./engines.js"); | ||
const packageJSON = (opts) => { | ||
const { | ||
strapiDependencies, | ||
additionalsDependencies, | ||
strapiVersion, | ||
projectName, | ||
uuid, | ||
packageJsonStrapi | ||
} = opts; | ||
return { | ||
name: projectName, | ||
private: true, | ||
version: "0.1.0", | ||
description: "A Strapi application", | ||
scripts: { | ||
develop: "strapi develop", | ||
start: "strapi start", | ||
build: "strapi build", | ||
strapi: "strapi", | ||
deploy: "strapi deploy" | ||
}, | ||
devDependencies: {}, | ||
dependencies: { | ||
...strapiDependencies.reduce((acc, key) => { | ||
acc[key] = strapiVersion; | ||
return acc; | ||
}, {}), | ||
...additionalsDependencies | ||
}, | ||
author: { | ||
name: "A Strapi developer" | ||
}, | ||
strapi: { | ||
uuid, | ||
...packageJsonStrapi | ||
}, | ||
engines, | ||
license: "MIT" | ||
}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const engines_1 = __importDefault(require("./engines")); | ||
exports.default = (opts) => { | ||
const { strapiDependencies, additionalsDependencies, strapiVersion, projectName, uuid, packageJsonStrapi, } = opts; | ||
// Finally, return the JSON. | ||
return { | ||
name: projectName, | ||
private: true, | ||
version: '0.1.0', | ||
description: 'A Strapi application', | ||
scripts: { | ||
develop: 'strapi develop', | ||
start: 'strapi start', | ||
build: 'strapi build', | ||
strapi: 'strapi', | ||
}, | ||
devDependencies: {}, | ||
dependencies: { | ||
...strapiDependencies.reduce((acc, key) => { | ||
acc[key] = strapiVersion; | ||
return acc; | ||
}, {}), | ||
...additionalsDependencies, | ||
}, | ||
author: { | ||
name: 'A Strapi developer', | ||
}, | ||
strapi: { | ||
uuid, | ||
...packageJsonStrapi, | ||
}, | ||
engines: engines_1.default, | ||
license: 'MIT', | ||
}; | ||
}; | ||
//# sourceMappingURL=package.json.js.map | ||
module.exports = packageJSON; | ||
//# sourceMappingURL=package.json.js.map |
declare const _default: () => { | ||
compilerOptions: { | ||
moduleResolution: string; | ||
target: string; | ||
checkJs: boolean; | ||
allowJs: boolean; | ||
}; | ||
}; | ||
export default _default; | ||
//# sourceMappingURL=jsconfig.json.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = () => ({ | ||
compilerOptions: { | ||
checkJs: true, | ||
}, | ||
const jsconfig = () => ({ | ||
compilerOptions: { | ||
moduleResolution: "nodenext", | ||
target: "ES2021", | ||
checkJs: true, | ||
allowJs: true | ||
} | ||
}); | ||
//# sourceMappingURL=jsconfig.json.js.map | ||
module.exports = jsconfig; | ||
//# sourceMappingURL=jsconfig.json.js.map |
@@ -7,1 +7,2 @@ declare const _default: () => { | ||
export default _default; | ||
//# sourceMappingURL=tsconfig-admin.json.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = () => ({ | ||
extends: '@strapi/typescript-utils/tsconfigs/admin', | ||
include: ['../plugins/**/admin/src/**/*', './'], | ||
exclude: ['node_modules/', 'build/', 'dist/', '**/*.test.ts'], | ||
const adminTsconfig = () => ({ | ||
extends: "@strapi/typescript-utils/tsconfigs/admin", | ||
include: ["../plugins/**/admin/src/**/*", "./"], | ||
exclude: ["node_modules/", "build/", "dist/", "**/*.test.ts"] | ||
}); | ||
//# sourceMappingURL=tsconfig-admin.json.js.map | ||
module.exports = adminTsconfig; | ||
//# sourceMappingURL=tsconfig-admin.json.js.map |
@@ -11,1 +11,2 @@ declare const _default: () => { | ||
export default _default; | ||
//# sourceMappingURL=tsconfig-server.json.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = () => ({ | ||
extends: '@strapi/typescript-utils/tsconfigs/server', | ||
compilerOptions: { | ||
outDir: 'dist', | ||
rootDir: '.', | ||
}, | ||
include: [ | ||
// Include root files | ||
'./', | ||
// Include all ts files | ||
'./**/*.ts', | ||
// Include all js files | ||
'./**/*.js', | ||
// Force the JSON files in the src folder to be included | ||
'src/**/*.json', | ||
], | ||
exclude: [ | ||
'node_modules/', | ||
'build/', | ||
'dist/', | ||
'.cache/', | ||
'.tmp/', | ||
// Do not include admin files in the server compilation | ||
'src/admin/', | ||
// Do not include test files | ||
'**/*.test.*', | ||
// Do not include plugins in the server compilation | ||
'src/plugins/**', | ||
], | ||
const serverTsconfig = () => ({ | ||
extends: "@strapi/typescript-utils/tsconfigs/server", | ||
compilerOptions: { | ||
outDir: "dist", | ||
rootDir: "." | ||
}, | ||
include: [ | ||
// Include root files | ||
"./", | ||
// Include all ts files | ||
"./**/*.ts", | ||
// Include all js files | ||
"./**/*.js", | ||
// Force the JSON files in the src folder to be included | ||
"src/**/*.json" | ||
], | ||
exclude: [ | ||
"node_modules/", | ||
"build/", | ||
"dist/", | ||
".cache/", | ||
".tmp/", | ||
// Do not include admin files in the server compilation | ||
"src/admin/", | ||
// Do not include test files | ||
"**/*.test.*", | ||
// Do not include plugins in the server compilation | ||
"src/plugins/**" | ||
] | ||
}); | ||
//# sourceMappingURL=tsconfig-server.json.js.map | ||
module.exports = serverTsconfig; | ||
//# sourceMappingURL=tsconfig-server.json.js.map |
@@ -9,1 +9,2 @@ import type { DatabaseInfo } from '../../types'; | ||
}) => string; | ||
//# sourceMappingURL=database.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateDbEnvariables = exports.createDatabaseConfig = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const _ = require("lodash"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const fs__default = /* @__PURE__ */ _interopDefault(fs); | ||
const path__default = /* @__PURE__ */ _interopDefault(path); | ||
const ___default = /* @__PURE__ */ _interopDefault(_); | ||
const createDatabaseConfig = ({ useTypescript }) => { | ||
const language = useTypescript ? 'ts' : 'js'; | ||
const tmpl = fs_1.default.readFileSync(path_1.default.join(__dirname, 'database-templates', language, `database.template`)); | ||
const compile = lodash_1.default.template(tmpl.toString()); | ||
return compile(); | ||
const language = useTypescript ? "ts" : "js"; | ||
const tmpl = fs__default.default.readFileSync( | ||
path__default.default.join(__dirname, "database-templates", language, `database.template`) | ||
); | ||
const compile = ___default.default.template(tmpl.toString()); | ||
return compile(); | ||
}; | ||
const generateDbEnvariables = ({ | ||
connection, | ||
client | ||
}) => { | ||
const tmpl = fs__default.default.readFileSync(path__default.default.join(__dirname, "database-templates", `${client}.template`)); | ||
const compile = ___default.default.template(tmpl.toString()); | ||
return compile({ | ||
client, | ||
connection: { | ||
...connection.connection, | ||
ssl: connection.connection.ssl || false | ||
} | ||
}); | ||
}; | ||
exports.createDatabaseConfig = createDatabaseConfig; | ||
const generateDbEnvariables = ({ connection, client, }) => { | ||
const tmpl = fs_1.default.readFileSync(path_1.default.join(__dirname, 'database-templates', `${client}.template`)); | ||
const compile = lodash_1.default.template(tmpl.toString()); | ||
return compile({ | ||
client, | ||
connection: { | ||
...connection.connection, | ||
ssl: connection.connection.ssl || false, | ||
}, | ||
}); | ||
}; | ||
exports.generateDbEnvariables = generateDbEnvariables; | ||
//# sourceMappingURL=database.js.map | ||
//# sourceMappingURL=database.js.map |
declare const _default: () => string; | ||
export default _default; | ||
//# sourceMappingURL=env.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const crypto = require("crypto"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const _ = require("lodash"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const crypto__default = /* @__PURE__ */ _interopDefault(crypto); | ||
const fs__default = /* @__PURE__ */ _interopDefault(fs); | ||
const path__default = /* @__PURE__ */ _interopDefault(path); | ||
const ___default = /* @__PURE__ */ _interopDefault(_); | ||
const generateASecret = () => crypto__default.default.randomBytes(16).toString("base64"); | ||
const createEnvFile = () => { | ||
const tmpl = fs__default.default.readFileSync(path__default.default.join(__dirname, "env.template")); | ||
const compile = ___default.default.template(tmpl.toString()); | ||
return compile({ | ||
appKeys: new Array(4).fill(null).map(generateASecret).join(","), | ||
apiTokenSalt: generateASecret(), | ||
transferTokenSalt: generateASecret(), | ||
adminJwtToken: generateASecret() | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const crypto_1 = __importDefault(require("crypto")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const generateASecret = () => crypto_1.default.randomBytes(16).toString('base64'); | ||
exports.default = () => { | ||
const tmpl = fs_1.default.readFileSync(path_1.default.join(__dirname, 'env.template')); | ||
const compile = lodash_1.default.template(tmpl.toString()); | ||
return compile({ | ||
appKeys: new Array(4).fill(null).map(generateASecret).join(','), | ||
apiTokenSalt: generateASecret(), | ||
transferTokenSalt: generateASecret(), | ||
adminJwtToken: generateASecret(), | ||
}); | ||
}; | ||
//# sourceMappingURL=env.js.map | ||
module.exports = createEnvFile; | ||
//# sourceMappingURL=env.js.map |
@@ -70,1 +70,2 @@ export interface Scope { | ||
export declare function isStderrError(error: unknown): error is StderrError; | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isStderrError = void 0; | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
function isStderrError(error) { | ||
return (typeof error === 'object' && | ||
error !== null && | ||
'stderr' in error && | ||
typeof error.stderr === 'string'); | ||
return typeof error === "object" && error !== null && "stderr" in error && typeof error.stderr === "string"; | ||
} | ||
exports.isStderrError = isStderrError; | ||
//# sourceMappingURL=types.js.map | ||
//# sourceMappingURL=types.js.map |
declare const _default: (rootPath: string) => Promise<void>; | ||
export default _default; | ||
//# sourceMappingURL=check-install-path.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const stop_process_1 = __importDefault(require("./stop-process")); | ||
// Checks if the an empty directory exists at rootPath | ||
exports.default = async (rootPath) => { | ||
if (await fs_extra_1.default.pathExists(rootPath)) { | ||
const stat = await fs_extra_1.default.stat(rootPath); | ||
if (!stat.isDirectory()) { | ||
(0, stop_process_1.default)(`⛔️ ${chalk_1.default.green(rootPath)} is not a directory. Make sure to create a Strapi application in an empty directory.`); | ||
} | ||
const files = await fs_extra_1.default.readdir(rootPath); | ||
if (files.length > 1) { | ||
(0, stop_process_1.default)(`⛔️ You can only create a Strapi app in an empty directory.\nMake sure ${chalk_1.default.green(rootPath)} is empty.`); | ||
} | ||
const chalk = require("chalk"); | ||
const fse = require("fs-extra"); | ||
const stopProcess = require("./stop-process.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
const fse__default = /* @__PURE__ */ _interopDefault(fse); | ||
const checkInstallPath = async (rootPath) => { | ||
if (await fse__default.default.pathExists(rootPath)) { | ||
const stat = await fse__default.default.stat(rootPath); | ||
if (!stat.isDirectory()) { | ||
stopProcess( | ||
`⛔️ ${chalk__default.default.green( | ||
rootPath | ||
)} is not a directory. Make sure to create a Strapi application in an empty directory.` | ||
); | ||
} | ||
const files = await fse__default.default.readdir(rootPath); | ||
if (files.length > 1) { | ||
stopProcess( | ||
`⛔️ You can only create a Strapi app in an empty directory. | ||
Make sure ${chalk__default.default.green( | ||
rootPath | ||
)} is empty.` | ||
); | ||
} | ||
} | ||
}; | ||
//# sourceMappingURL=check-install-path.js.map | ||
module.exports = checkInstallPath; | ||
//# sourceMappingURL=check-install-path.js.map |
export default function checkRequirements(): void; | ||
//# sourceMappingURL=check-requirements.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk_1 = require("chalk"); | ||
const semver_1 = __importDefault(require("semver")); | ||
const engines_1 = __importDefault(require("../resources/json/common/engines")); | ||
const chalk = require("chalk"); | ||
const semver = require("semver"); | ||
const engines = require("../resources/json/common/engines.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
const semver__default = /* @__PURE__ */ _interopDefault(semver); | ||
function checkRequirements() { | ||
const currentNodeVersion = process.versions.node; | ||
// error if the node version isn't supported | ||
if (!semver_1.default.satisfies(currentNodeVersion, engines_1.default.node)) { | ||
console.error((0, chalk_1.red)(`You are running ${(0, chalk_1.bold)(`Node.js ${currentNodeVersion}`)}`)); | ||
console.error(`Strapi requires ${(0, chalk_1.bold)((0, chalk_1.green)(`Node.js ${engines_1.default.node}`))}`); | ||
console.error('Please make sure to use the right version of Node.'); | ||
process.exit(1); | ||
} | ||
// warn if not using a LTS version | ||
else if (semver_1.default.major(currentNodeVersion) % 2 !== 0) { | ||
console.warn((0, chalk_1.yellow)(`You are running ${(0, chalk_1.bold)(`Node.js ${currentNodeVersion}`)}`)); | ||
console.warn(`Strapi only supports ${(0, chalk_1.bold)((0, chalk_1.green)('LTS versions of Node.js'))}, other versions may not be compatible.`); | ||
} | ||
const currentNodeVersion = process.versions.node; | ||
if (!semver__default.default.satisfies(currentNodeVersion, engines.node)) { | ||
console.error(chalk__default.default.red(`You are running ${chalk__default.default.bold(`Node.js ${currentNodeVersion}`)}`)); | ||
console.error(`Strapi requires ${chalk__default.default.bold(chalk__default.default.green(`Node.js ${engines.node}`))}`); | ||
console.error("Please make sure to use the right version of Node."); | ||
process.exit(1); | ||
} else if (semver__default.default.major(currentNodeVersion) % 2 !== 0) { | ||
console.warn(chalk__default.default.yellow(`You are running ${chalk__default.default.bold(`Node.js ${currentNodeVersion}`)}`)); | ||
console.warn( | ||
`Strapi only supports ${chalk__default.default.bold( | ||
chalk__default.default.green("LTS versions of Node.js") | ||
)}, other versions may not be compatible.` | ||
); | ||
} | ||
} | ||
exports.default = checkRequirements; | ||
//# sourceMappingURL=check-requirements.js.map | ||
module.exports = checkRequirements; | ||
//# sourceMappingURL=check-requirements.js.map |
@@ -19,1 +19,2 @@ import type { ClientName } from '../types'; | ||
export default _default; | ||
//# sourceMappingURL=db-client-dependencies.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const sqlClientModule = { | ||
mysql: { mysql: '2.18.1' }, | ||
mysql2: { mysql2: '3.6.0' }, | ||
postgres: { pg: '8.8.0' }, | ||
sqlite: { 'better-sqlite3': '8.5.0' }, | ||
'sqlite-legacy': { sqlite3: '5.1.2' }, | ||
mysql: { mysql: "2.18.1" }, | ||
mysql2: { mysql2: "3.10.0" }, | ||
postgres: { pg: "8.8.0" }, | ||
sqlite: { "better-sqlite3": "8.6.0" }, | ||
"sqlite-legacy": { sqlite3: "5.1.2" } | ||
}; | ||
/** | ||
* Client dependencies | ||
*/ | ||
exports.default = ({ client }) => { | ||
if (client in sqlClientModule) { | ||
return { | ||
...sqlClientModule[client], | ||
}; | ||
} | ||
throw new Error(`Invalid client "${client}"`); | ||
const clientDependencies = ({ client }) => { | ||
if (client in sqlClientModule) { | ||
return { | ||
...sqlClientModule[client] | ||
}; | ||
} | ||
throw new Error(`Invalid client "${client}"`); | ||
}; | ||
//# sourceMappingURL=db-client-dependencies.js.map | ||
module.exports = clientDependencies; | ||
//# sourceMappingURL=db-client-dependencies.js.map |
@@ -8,1 +8,2 @@ /** | ||
export default _default; | ||
//# sourceMappingURL=db-client-name.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Client | ||
*/ | ||
exports.default = ({ client }) => { | ||
switch (client) { | ||
case 'sqlite-legacy': | ||
return 'sqlite'; | ||
default: | ||
return client; | ||
} | ||
const getClientName = ({ client }) => { | ||
switch (client) { | ||
case "sqlite-legacy": | ||
return "sqlite"; | ||
default: | ||
return client; | ||
} | ||
}; | ||
//# sourceMappingURL=db-client-name.js.map | ||
module.exports = getClientName; | ||
//# sourceMappingURL=db-client-name.js.map |
@@ -15,1 +15,2 @@ /** | ||
export default _default; | ||
//# sourceMappingURL=db-configs.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Default db infos | ||
*/ | ||
exports.default = { | ||
sqlite: { | ||
connection: { | ||
filename: '.tmp/data.db', | ||
}, | ||
useNullAsDefault: true, | ||
const defaultConfigs = { | ||
sqlite: { | ||
connection: { | ||
filename: ".tmp/data.db" | ||
}, | ||
postgres: {}, | ||
mysql: {}, | ||
useNullAsDefault: true | ||
}, | ||
postgres: {}, | ||
mysql: {} | ||
}; | ||
//# sourceMappingURL=db-configs.js.map | ||
module.exports = defaultConfigs; | ||
//# sourceMappingURL=db-configs.js.map |
@@ -15,1 +15,2 @@ import type { Question } from 'inquirer'; | ||
export default _default; | ||
//# sourceMappingURL=db-questions.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DEFAULT_PORTS = { | ||
postgres: 5432, | ||
mysql: 3306, | ||
sqlite: undefined, | ||
postgres: 5432, | ||
mysql: 3306, | ||
sqlite: void 0 | ||
}; | ||
const database = ({ scope }) => ({ | ||
type: 'input', | ||
name: 'database', | ||
message: 'Database name:', | ||
default: scope.name, | ||
validate(value) { | ||
if (value.includes('.')) { | ||
return `The database name can't contain a "."`; | ||
} | ||
return true; | ||
}, | ||
type: "input", | ||
name: "database", | ||
message: "Database name:", | ||
default: scope.name, | ||
validate(value) { | ||
if (value.includes(".")) { | ||
return `The database name can't contain a "."`; | ||
} | ||
return true; | ||
} | ||
}); | ||
const host = () => ({ | ||
type: 'input', | ||
name: 'host', | ||
message: 'Host:', | ||
default: '127.0.0.1', | ||
type: "input", | ||
name: "host", | ||
message: "Host:", | ||
default: "127.0.0.1" | ||
}); | ||
const port = ({ client }) => ({ | ||
type: 'input', | ||
name: 'port', | ||
message: 'Port:', | ||
default: DEFAULT_PORTS[client], | ||
type: "input", | ||
name: "port", | ||
message: "Port:", | ||
default: DEFAULT_PORTS[client] | ||
}); | ||
const username = () => ({ | ||
type: 'input', | ||
name: 'username', | ||
message: 'Username:', | ||
type: "input", | ||
name: "username", | ||
message: "Username:" | ||
}); | ||
const password = () => ({ | ||
type: 'password', | ||
name: 'password', | ||
message: 'Password:', | ||
mask: '*', | ||
type: "password", | ||
name: "password", | ||
message: "Password:", | ||
mask: "*" | ||
}); | ||
const ssl = () => ({ | ||
type: 'confirm', | ||
name: 'ssl', | ||
message: 'Enable SSL connection:', | ||
default: false, | ||
type: "confirm", | ||
name: "ssl", | ||
message: "Enable SSL connection:", | ||
default: false | ||
}); | ||
const filename = () => ({ | ||
type: 'input', | ||
name: 'filename', | ||
message: 'Filename:', | ||
default: '.tmp/data.db', | ||
type: "input", | ||
name: "filename", | ||
message: "Filename:", | ||
default: ".tmp/data.db" | ||
}); | ||
exports.default = { | ||
sqlite: [filename], | ||
postgres: [database, host, port, username, password, ssl], | ||
mysql: [database, host, port, username, password, ssl], | ||
const dbQuestions = { | ||
sqlite: [filename], | ||
postgres: [database, host, port, username, password, ssl], | ||
mysql: [database, host, port, username, password, ssl] | ||
}; | ||
//# sourceMappingURL=db-questions.js.map | ||
module.exports = dbQuestions; | ||
//# sourceMappingURL=db-questions.js.map |
import type { PackageInfo } from '../types'; | ||
export declare function getTemplatePackageInfo(template: string): Promise<PackageInfo>; | ||
export declare function downloadNpmTemplate({ name, version }: PackageInfo, parentDir: string): Promise<string>; | ||
//# sourceMappingURL=fetch-npm-template.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.downloadNpmTemplate = exports.getTemplatePackageInfo = void 0; | ||
const path_1 = __importDefault(require("path")); | ||
const execa_1 = __importDefault(require("execa")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
// Gets the package version on npm. Will fail if the package does not exist | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
const path = require("path"); | ||
const execa = require("execa"); | ||
const chalk = require("chalk"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const path__default = /* @__PURE__ */ _interopDefault(path); | ||
const execa__default = /* @__PURE__ */ _interopDefault(execa); | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
async function getPackageInfo(packageName) { | ||
const { stdout } = await (0, execa_1.default)('npm', ['view', packageName, 'name', 'version', '--silent']); | ||
// Use regex to parse name and version from CLI result | ||
const match = stdout.match(/(?<=')(.*?)(?=')/gm); | ||
if (!match) { | ||
throw new Error('Could not match'); | ||
} | ||
const [name, version] = match; | ||
return { name, version }; | ||
const { stdout } = await execa__default.default("npm", ["view", packageName, "name", "version", "--silent"]); | ||
const match = stdout.match(/(?<=')(.*?)(?=')/gm); | ||
if (!match) { | ||
throw new Error("Could not match"); | ||
} | ||
const [name, version] = match; | ||
return { name, version }; | ||
} | ||
async function getTemplatePackageInfo(template) { | ||
// Check if template is a shorthand | ||
try { | ||
const longhand = `@strapi/template-${template}`; | ||
const packageInfo = await getPackageInfo(longhand); | ||
// Hasn't crashed so it is indeed a shorthand | ||
return packageInfo; | ||
} | ||
catch (error) { | ||
// Ignore error, we now know it's not a shorthand | ||
} | ||
// Fetch version of the non-shorthand package | ||
try { | ||
return await getPackageInfo(template); | ||
} | ||
catch (error) { | ||
throw new Error(`Could not find package ${chalk_1.default.yellow(template)} on npm`); | ||
} | ||
try { | ||
const longhand = `@strapi/template-${template}`; | ||
const packageInfo = await getPackageInfo(longhand); | ||
return packageInfo; | ||
} catch (error) { | ||
} | ||
try { | ||
return await getPackageInfo(template); | ||
} catch (error) { | ||
throw new Error(`Could not find package ${chalk__default.default.yellow(template)} on npm`); | ||
} | ||
} | ||
exports.getTemplatePackageInfo = getTemplatePackageInfo; | ||
async function downloadNpmTemplate({ name, version }, parentDir) { | ||
// Download from npm | ||
await (0, execa_1.default)('npm', ['install', `${name}@${version}`, '--no-save', '--silent'], { | ||
cwd: parentDir, | ||
}); | ||
// Return the path of the actual template | ||
const exactTemplatePath = path_1.default.dirname(require.resolve(`${name}/package.json`, { paths: [parentDir] })); | ||
return exactTemplatePath; | ||
await execa__default.default("npm", ["install", `${name}@${version}`, "--no-save", "--silent"], { | ||
cwd: parentDir | ||
}); | ||
const exactTemplatePath = path__default.default.dirname( | ||
require.resolve(`${name}/package.json`, { paths: [parentDir] }) | ||
); | ||
return exactTemplatePath; | ||
} | ||
exports.downloadNpmTemplate = downloadNpmTemplate; | ||
//# sourceMappingURL=fetch-npm-template.js.map | ||
exports.getTemplatePackageInfo = getTemplatePackageInfo; | ||
//# sourceMappingURL=fetch-npm-template.js.map |
export default function tryGitInit(rootDir: string): Promise<boolean>; | ||
//# sourceMappingURL=git.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const execa_1 = __importDefault(require("execa")); | ||
const execa = require("execa"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const execa__default = /* @__PURE__ */ _interopDefault(execa); | ||
async function isInGitRepository(rootDir) { | ||
try { | ||
await (0, execa_1.default)('git', ['rev-parse', '--is-inside-work-tree'], { stdio: 'ignore', cwd: rootDir }); | ||
return true; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
try { | ||
await execa__default.default("git", ["rev-parse", "--is-inside-work-tree"], { stdio: "ignore", cwd: rootDir }); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
async function isInMercurialRepository(rootDir) { | ||
try { | ||
await (0, execa_1.default)('hg', ['-cwd', '.', 'root'], { stdio: 'ignore', cwd: rootDir }); | ||
return true; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
try { | ||
await execa__default.default("hg", ["-cwd", ".", "root"], { stdio: "ignore", cwd: rootDir }); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
async function tryGitInit(rootDir) { | ||
try { | ||
await (0, execa_1.default)('git', ['--version'], { stdio: 'ignore' }); | ||
if ((await isInGitRepository(rootDir)) || (await isInMercurialRepository(rootDir))) { | ||
return false; | ||
} | ||
await (0, execa_1.default)('git', ['init'], { stdio: 'ignore', cwd: rootDir }); | ||
return true; | ||
try { | ||
await execa__default.default("git", ["--version"], { stdio: "ignore" }); | ||
if (await isInGitRepository(rootDir) || await isInMercurialRepository(rootDir)) { | ||
return false; | ||
} | ||
catch (_) { | ||
return false; | ||
} | ||
await execa__default.default("git", ["init"], { stdio: "ignore", cwd: rootDir }); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
exports.default = tryGitInit; | ||
//# sourceMappingURL=git.js.map | ||
module.exports = tryGitInit; | ||
//# sourceMappingURL=git.js.map |
export default function hasYarn(): boolean; | ||
//# sourceMappingURL=has-yarn.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const execa_1 = __importDefault(require("execa")); | ||
const execa = require("execa"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const execa__default = /* @__PURE__ */ _interopDefault(execa); | ||
function hasYarn() { | ||
try { | ||
const { exitCode } = execa_1.default.commandSync('yarn --version', { shell: true }); | ||
return exitCode === 0; | ||
} | ||
catch (err) { | ||
return false; | ||
} | ||
try { | ||
const { exitCode } = execa__default.default.commandSync("yarn --version", { shell: true }); | ||
return exitCode === 0; | ||
} catch (err) { | ||
return false; | ||
} | ||
} | ||
exports.default = hasYarn; | ||
//# sourceMappingURL=has-yarn.js.map | ||
module.exports = hasYarn; | ||
//# sourceMappingURL=has-yarn.js.map |
declare const _default: () => string; | ||
export default _default; | ||
//# sourceMappingURL=machine-id.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const crypto_1 = require("crypto"); | ||
const node_machine_id_1 = require("node-machine-id"); | ||
exports.default = () => { | ||
try { | ||
const deviceId = (0, node_machine_id_1.machineIdSync)(); | ||
return deviceId; | ||
} | ||
catch (error) { | ||
const deviceId = (0, crypto_1.randomUUID)(); | ||
return deviceId; | ||
} | ||
const crypto = require("crypto"); | ||
const nodeMachineId = require("node-machine-id"); | ||
const machineID = () => { | ||
try { | ||
const deviceId = nodeMachineId.machineIdSync(); | ||
return deviceId; | ||
} catch (error) { | ||
const deviceId = crypto.randomUUID(); | ||
return deviceId; | ||
} | ||
}; | ||
//# sourceMappingURL=machine-id.js.map | ||
module.exports = machineID; | ||
//# sourceMappingURL=machine-id.js.map |
import type { Scope } from '../types'; | ||
export default function mergeTemplate(scope: Scope, rootPath: string): Promise<void>; | ||
//# sourceMappingURL=merge-template.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const os_1 = __importDefault(require("os")); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const fp_1 = __importDefault(require("lodash/fp")); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const fetch_npm_template_1 = require("./fetch-npm-template"); | ||
// Specify all the files and directories a template can have | ||
const allowFile = Symbol('alloFile'); | ||
const allowChildren = Symbol('allowChildren'); | ||
const os = require("os"); | ||
const path = require("path"); | ||
const fse = require("fs-extra"); | ||
const _ = require("lodash/fp"); | ||
const chalk = require("chalk"); | ||
const fetchNpmTemplate = require("./fetch-npm-template.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const os__default = /* @__PURE__ */ _interopDefault(os); | ||
const path__default = /* @__PURE__ */ _interopDefault(path); | ||
const fse__default = /* @__PURE__ */ _interopDefault(fse); | ||
const ___default = /* @__PURE__ */ _interopDefault(_); | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
const allowFile = Symbol("alloFile"); | ||
const allowChildren = Symbol("allowChildren"); | ||
const allowedTemplateContents = { | ||
'README.md': allowFile, | ||
'.env.example': allowFile, | ||
'package.json': allowFile, | ||
src: allowChildren, | ||
data: allowChildren, | ||
database: allowChildren, | ||
public: allowChildren, | ||
scripts: allowChildren, | ||
"README.md": allowFile, | ||
".env.example": allowFile, | ||
"package.json": allowFile, | ||
src: allowChildren, | ||
data: allowChildren, | ||
database: allowChildren, | ||
public: allowChildren, | ||
scripts: allowChildren | ||
}; | ||
// Merge template with new project being created | ||
async function mergeTemplate(scope, rootPath) { | ||
if (!scope.template) { | ||
throw new Error('Missing template'); | ||
} | ||
let templatePath; | ||
let templateParentPath; | ||
let templatePackageInfo; | ||
const isLocalTemplate = ['./', '../', '/'].some((filePrefix) => scope.template?.startsWith(filePrefix)); | ||
if (isLocalTemplate) { | ||
// Template is a local directory | ||
console.log('Installing local template.'); | ||
templatePath = path_1.default.resolve(rootPath, '..', scope.template); | ||
} | ||
else { | ||
// Template should be an npm package. Fetch template info | ||
templatePackageInfo = await (0, fetch_npm_template_1.getTemplatePackageInfo)(scope.template); | ||
console.log(`Installing ${chalk_1.default.yellow(templatePackageInfo.name)} template.`); | ||
// Download template repository to a temporary directory | ||
templateParentPath = await fs_extra_1.default.mkdtemp(path_1.default.join(os_1.default.tmpdir(), 'strapi-')); | ||
templatePath = await (0, fetch_npm_template_1.downloadNpmTemplate)(templatePackageInfo, templateParentPath); | ||
} | ||
// Make sure the downloaded template matches the required format | ||
const templateConfig = await checkTemplateRootStructure(templatePath); | ||
await checkTemplateContentsStructure(path_1.default.resolve(templatePath, 'template')); | ||
// Merge contents of the template in the project | ||
await mergePackageJSON({ rootPath, templateConfig, templatePackageInfo }); | ||
await mergeFilesAndDirectories(rootPath, templatePath); | ||
// Delete the template directory if it was downloaded | ||
if (!isLocalTemplate && templateParentPath) { | ||
await fs_extra_1.default.remove(templateParentPath); | ||
} | ||
if (!scope.template) { | ||
throw new Error("Missing template"); | ||
} | ||
let templatePath; | ||
let templateParentPath; | ||
let templatePackageInfo; | ||
const isLocalTemplate = ["./", "../", "/"].some( | ||
(filePrefix) => scope.template?.startsWith(filePrefix) | ||
); | ||
if (isLocalTemplate) { | ||
console.log("Installing local template."); | ||
templatePath = path__default.default.resolve(rootPath, "..", scope.template); | ||
} else { | ||
templatePackageInfo = await fetchNpmTemplate.getTemplatePackageInfo(scope.template); | ||
console.log(`Installing ${chalk__default.default.yellow(templatePackageInfo.name)} template.`); | ||
templateParentPath = await fse__default.default.mkdtemp(path__default.default.join(os__default.default.tmpdir(), "strapi-")); | ||
templatePath = await fetchNpmTemplate.downloadNpmTemplate(templatePackageInfo, templateParentPath); | ||
} | ||
const templateConfig = await checkTemplateRootStructure(templatePath); | ||
await checkTemplateContentsStructure(path__default.default.resolve(templatePath, "template")); | ||
await mergePackageJSON({ rootPath, templateConfig, templatePackageInfo }); | ||
await mergeFilesAndDirectories(rootPath, templatePath); | ||
if (!isLocalTemplate && templateParentPath) { | ||
await fse__default.default.remove(templateParentPath); | ||
} | ||
} | ||
exports.default = mergeTemplate; | ||
// Make sure the template has the required top-level structure | ||
async function checkTemplateRootStructure(templatePath) { | ||
// Make sure the root of the repo has a template.json file | ||
const templateJsonPath = path_1.default.join(templatePath, 'template.json'); | ||
const templateJsonExists = await fs_extra_1.default.pathExists(templateJsonPath); | ||
if (!templateJsonExists) { | ||
throw new Error(`A template must have a ${chalk_1.default.green('template.json')} root file`); | ||
const templateJsonPath = path__default.default.join(templatePath, "template.json"); | ||
const templateJsonExists = await fse__default.default.pathExists(templateJsonPath); | ||
if (!templateJsonExists) { | ||
throw new Error(`A template must have a ${chalk__default.default.green("template.json")} root file`); | ||
} | ||
const templateJsonStat = await fse__default.default.stat(templateJsonPath); | ||
if (!templateJsonStat.isFile()) { | ||
throw new Error(`A template's ${chalk__default.default.green("template.json")} must be a file`); | ||
} | ||
const templateConfig = require(templateJsonPath); | ||
const templateDirPath = path__default.default.join(templatePath, "template"); | ||
try { | ||
const stat = await fse__default.default.stat(templateDirPath); | ||
if (!stat.isDirectory()) { | ||
throw Error(`A template must have a root ${chalk__default.default.green("template/")} directory`); | ||
} | ||
const templateJsonStat = await fs_extra_1.default.stat(templateJsonPath); | ||
if (!templateJsonStat.isFile()) { | ||
throw new Error(`A template's ${chalk_1.default.green('template.json')} must be a file`); | ||
} catch (error) { | ||
if (error instanceof Error && error.code === "ENOENT") { | ||
throw Error(`A template must have a root ${chalk__default.default.green("template/")} directory`); | ||
} | ||
const templateConfig = require(templateJsonPath); | ||
// Make sure the root of the repo has a template folder | ||
const templateDirPath = path_1.default.join(templatePath, 'template'); | ||
try { | ||
const stat = await fs_extra_1.default.stat(templateDirPath); | ||
if (!stat.isDirectory()) { | ||
throw Error(`A template must have a root ${chalk_1.default.green('template/')} directory`); | ||
throw error; | ||
} | ||
return templateConfig; | ||
} | ||
async function checkTemplateContentsStructure(templateContentsPath) { | ||
const checkPathContents = async (pathToCheck, parents) => { | ||
const contents = await fse__default.default.readdir(pathToCheck); | ||
for (const item of contents) { | ||
const nextParents = [...parents, item]; | ||
const matchingTreeValue = ___default.default.get(nextParents, allowedTemplateContents); | ||
const itemPath = path__default.default.resolve(pathToCheck, item); | ||
const isDirectory = (await fse__default.default.stat(itemPath)).isDirectory(); | ||
if (matchingTreeValue === void 0) { | ||
throw Error( | ||
`Illegal template structure, unknown path ${chalk__default.default.green(nextParents.join("/"))}` | ||
); | ||
} | ||
if (matchingTreeValue === allowFile) { | ||
if (!isDirectory) { | ||
return; | ||
} | ||
} | ||
catch (error) { | ||
if (error instanceof Error && error.code === 'ENOENT') { | ||
throw Error(`A template must have a root ${chalk_1.default.green('template/')} directory`); | ||
throw Error( | ||
`Illegal template structure, expected a file and got a directory at ${chalk__default.default.green( | ||
nextParents.join("/") | ||
)}` | ||
); | ||
} | ||
if (isDirectory) { | ||
if (matchingTreeValue === allowChildren) { | ||
return; | ||
} | ||
throw error; | ||
await checkPathContents(itemPath, nextParents); | ||
} else { | ||
throw Error( | ||
`Illegal template structure, unknown file ${chalk__default.default.green(nextParents.join("/"))}` | ||
); | ||
} | ||
} | ||
return templateConfig; | ||
}; | ||
await checkPathContents(templateContentsPath, []); | ||
} | ||
// Traverse template tree to make sure each file and folder is allowed | ||
async function checkTemplateContentsStructure(templateContentsPath) { | ||
// Recursively check if each item in a directory is allowed | ||
const checkPathContents = async (pathToCheck, parents) => { | ||
const contents = await fs_extra_1.default.readdir(pathToCheck); | ||
for (const item of contents) { | ||
const nextParents = [...parents, item]; | ||
const matchingTreeValue = fp_1.default.get(nextParents, allowedTemplateContents); | ||
// Treat files and directories separately | ||
const itemPath = path_1.default.resolve(pathToCheck, item); | ||
const isDirectory = (await fs_extra_1.default.stat(itemPath)).isDirectory(); | ||
if (matchingTreeValue === undefined) { | ||
// Unknown paths are forbidden | ||
throw Error(`Illegal template structure, unknown path ${chalk_1.default.green(nextParents.join('/'))}`); | ||
} | ||
if (matchingTreeValue === allowFile) { | ||
if (!isDirectory) { | ||
// All good, the file is allowed | ||
return; | ||
} | ||
throw Error(`Illegal template structure, expected a file and got a directory at ${chalk_1.default.green(nextParents.join('/'))}`); | ||
} | ||
if (isDirectory) { | ||
if (matchingTreeValue === allowChildren) { | ||
// All children are allowed | ||
return; | ||
} | ||
// Check if the contents of the directory are allowed | ||
await checkPathContents(itemPath, nextParents); | ||
} | ||
else { | ||
throw Error(`Illegal template structure, unknown file ${chalk_1.default.green(nextParents.join('/'))}`); | ||
} | ||
} | ||
}; | ||
await checkPathContents(templateContentsPath, []); | ||
async function mergePackageJSON({ | ||
rootPath, | ||
templateConfig, | ||
templatePackageInfo | ||
}) { | ||
const packageJSON = require(path__default.default.resolve(rootPath, "package.json")); | ||
if (!templateConfig.package) { | ||
return; | ||
} | ||
if (___default.default.has("strapi.uuid", templateConfig.package)) { | ||
throw Error("A template cannot overwrite the Strapi UUID"); | ||
} | ||
const mergedConfig = ___default.default.merge(templateConfig.package, packageJSON); | ||
if (templatePackageInfo?.name) { | ||
___default.default.set("strapi.template", templatePackageInfo.name, mergedConfig); | ||
} | ||
const packageJSONPath = path__default.default.join(rootPath, "package.json"); | ||
await fse__default.default.writeJSON(packageJSONPath, mergedConfig, { spaces: 2 }); | ||
} | ||
// Merge the template's template.json into the Strapi project's package.json | ||
async function mergePackageJSON({ rootPath, templateConfig, templatePackageInfo, }) { | ||
// Import the package.json as an object | ||
const packageJSON = require(path_1.default.resolve(rootPath, 'package.json')); | ||
if (!templateConfig.package) { | ||
// Nothing to overwrite | ||
return; | ||
} | ||
// Make sure the template.json doesn't overwrite the UUID | ||
if (fp_1.default.has('strapi.uuid', templateConfig.package)) { | ||
throw Error('A template cannot overwrite the Strapi UUID'); | ||
} | ||
// Use lodash to deeply merge them | ||
const mergedConfig = fp_1.default.merge(templateConfig.package, packageJSON); | ||
// Add template info to package.json | ||
if (templatePackageInfo?.name) { | ||
fp_1.default.set('strapi.template', templatePackageInfo.name, mergedConfig); | ||
} | ||
// Save the merged config as the new package.json | ||
const packageJSONPath = path_1.default.join(rootPath, 'package.json'); | ||
await fs_extra_1.default.writeJSON(packageJSONPath, mergedConfig, { spaces: 2 }); | ||
} | ||
// Merge all allowed files and directories | ||
async function mergeFilesAndDirectories(rootPath, templatePath) { | ||
const templateDir = path_1.default.join(templatePath, 'template'); | ||
await fs_extra_1.default.copy(templateDir, rootPath, { overwrite: true, recursive: true }); | ||
const templateDir = path__default.default.join(templatePath, "template"); | ||
await fse__default.default.copy(templateDir, rootPath, { overwrite: true, recursive: true }); | ||
} | ||
//# sourceMappingURL=merge-template.js.map | ||
module.exports = mergeTemplate; | ||
//# sourceMappingURL=merge-template.js.map |
@@ -8,1 +8,2 @@ import type { Scope, NewOptions } from '../types'; | ||
export {}; | ||
//# sourceMappingURL=parse-db-arguments.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const stop_process_1 = __importDefault(require("./stop-process")); | ||
const DB_ARGS = ['dbclient', 'dbhost', 'dbport', 'dbname', 'dbusername', 'dbpassword']; | ||
const VALID_CLIENTS = ['sqlite', 'mysql', 'postgres']; | ||
const chalk = require("chalk"); | ||
const stopProcess = require("./stop-process.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const chalk__default = /* @__PURE__ */ _interopDefault(chalk); | ||
const DB_ARGS = ["dbclient", "dbhost", "dbport", "dbname", "dbusername", "dbpassword"]; | ||
const VALID_CLIENTS = ["sqlite", "mysql", "postgres"]; | ||
function parseDatabaseArguments({ scope, args }) { | ||
const argKeys = Object.keys(args); | ||
const matchingArgs = DB_ARGS.filter((key) => argKeys.includes(key)); | ||
const missingArgs = DB_ARGS.filter((key) => !argKeys.includes(key)); | ||
if (matchingArgs.length === 0) | ||
return; | ||
if (matchingArgs.length !== DB_ARGS.length && args.dbclient !== 'sqlite') { | ||
return (0, stop_process_1.default)(`Required database arguments are missing: ${missingArgs.join(', ')}.`); | ||
const argKeys = Object.keys(args); | ||
const matchingArgs = DB_ARGS.filter((key) => argKeys.includes(key)); | ||
const missingArgs = DB_ARGS.filter((key) => !argKeys.includes(key)); | ||
if (matchingArgs.length === 0) | ||
return; | ||
if (matchingArgs.length !== DB_ARGS.length && args.dbclient !== "sqlite") { | ||
return stopProcess(`Required database arguments are missing: ${missingArgs.join(", ")}.`); | ||
} | ||
if (!args.dbclient || !VALID_CLIENTS.includes(args.dbclient)) { | ||
return stopProcess( | ||
`Invalid client ${chalk__default.default.yellow(args.dbclient)}. Possible choices: ${VALID_CLIENTS.join( | ||
", " | ||
)}.` | ||
); | ||
} | ||
scope.dbforce = args.dbforce !== void 0; | ||
const database = { | ||
client: args.dbclient, | ||
connection: { | ||
host: args.dbhost, | ||
port: args.dbport, | ||
database: args.dbname, | ||
username: args.dbusername, | ||
password: args.dbpassword, | ||
filename: args.dbfile | ||
} | ||
if (!args.dbclient || !VALID_CLIENTS.includes(args.dbclient)) { | ||
return (0, stop_process_1.default)(`Invalid client ${chalk_1.default.yellow(args.dbclient)}. Possible choices: ${VALID_CLIENTS.join(', ')}.`); | ||
} | ||
scope.dbforce = args.dbforce !== undefined; | ||
const database = { | ||
client: args.dbclient, | ||
connection: { | ||
host: args.dbhost, | ||
port: args.dbport, | ||
database: args.dbname, | ||
username: args.dbusername, | ||
password: args.dbpassword, | ||
filename: args.dbfile, | ||
}, | ||
}; | ||
if (args.dbssl !== undefined) { | ||
database.connection.ssl = args.dbssl === 'true'; | ||
} | ||
scope.database = database; | ||
}; | ||
if (args.dbssl !== void 0) { | ||
database.connection.ssl = args.dbssl === "true"; | ||
} | ||
scope.database = database; | ||
} | ||
exports.default = parseDatabaseArguments; | ||
//# sourceMappingURL=parse-db-arguments.js.map | ||
module.exports = parseDatabaseArguments; | ||
//# sourceMappingURL=parse-db-arguments.js.map |
export default function stopProcess(message?: string): never; | ||
//# sourceMappingURL=stop-process.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function stopProcess(message) { | ||
if (message) { | ||
console.error(message); | ||
} | ||
process.exit(1); | ||
if (message) { | ||
console.error(message); | ||
} | ||
process.exit(1); | ||
} | ||
exports.default = stopProcess; | ||
//# sourceMappingURL=stop-process.js.map | ||
module.exports = stopProcess; | ||
//# sourceMappingURL=stop-process.js.map |
@@ -15,1 +15,2 @@ import { Scope, StderrError } from '../types'; | ||
export {}; | ||
//# sourceMappingURL=usage.d.ts.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.trackUsage = exports.trackError = exports.captureStderr = exports.captureException = void 0; | ||
const os_1 = __importDefault(require("os")); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const node_1 = __importStar(require("@sentry/node")); | ||
const types_1 = require("../types"); | ||
// Add properties from the package.json strapi key in the metadata | ||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); | ||
const os = require("os"); | ||
const _ = require("lodash"); | ||
const fetch = require("node-fetch"); | ||
const sentry = require("@sentry/node"); | ||
const types = require("../types.js"); | ||
const _interopDefault = (e) => e && e.__esModule ? e : { default: e }; | ||
const os__default = /* @__PURE__ */ _interopDefault(os); | ||
const ___default = /* @__PURE__ */ _interopDefault(_); | ||
const fetch__default = /* @__PURE__ */ _interopDefault(fetch); | ||
const sentry__default = /* @__PURE__ */ _interopDefault(sentry); | ||
function addPackageJsonStrapiMetadata(metadata, scope) { | ||
const { packageJsonStrapi = {} } = scope; | ||
return lodash_1.default.defaults(metadata, packageJsonStrapi); | ||
const { packageJsonStrapi = {} } = scope; | ||
return ___default.default.defaults(metadata, packageJsonStrapi); | ||
} | ||
async function captureException(error) { | ||
try { | ||
node_1.default.captureException(error); | ||
await node_1.default.flush(); | ||
} | ||
catch (err) { | ||
/** ignore errors */ | ||
return Promise.resolve(); | ||
} | ||
try { | ||
sentry__default.default.captureException(error); | ||
await sentry__default.default.flush(); | ||
} catch (err) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
exports.captureException = captureException; | ||
async function captureError(message) { | ||
try { | ||
node_1.default.captureMessage(message, node_1.Severity.Error); | ||
await node_1.default.flush(); | ||
} | ||
catch (err) { | ||
/** ignore errors */ | ||
return Promise.resolve(); | ||
} | ||
try { | ||
sentry__default.default.captureMessage(message, sentry.Severity.Error); | ||
await sentry__default.default.flush(); | ||
} catch (err) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
function captureStderr(name, error) { | ||
if ((0, types_1.isStderrError)(error) && error.stderr.trim() !== '') { | ||
error.stderr | ||
.trim() | ||
.split('\n') | ||
.forEach((line) => { | ||
node_1.default.addBreadcrumb({ | ||
category: 'stderr', | ||
message: line, | ||
level: node_1.Severity.Error, | ||
}); | ||
}); | ||
} | ||
return captureError(name); | ||
if (types.isStderrError(error) && error.stderr.trim() !== "") { | ||
error.stderr.trim().split("\n").forEach((line) => { | ||
sentry__default.default.addBreadcrumb({ | ||
category: "stderr", | ||
message: line, | ||
level: sentry.Severity.Error | ||
}); | ||
}); | ||
} | ||
return captureError(name); | ||
} | ||
exports.captureStderr = captureStderr; | ||
const getProperties = (scope, error) => { | ||
const eventProperties = { | ||
error: typeof error === 'string' ? error : error && error.message, | ||
}; | ||
const userProperties = { | ||
os: os_1.default.type(), | ||
osPlatform: os_1.default.platform(), | ||
osArch: os_1.default.arch(), | ||
osRelease: os_1.default.release(), | ||
nodeVersion: process.versions.node, | ||
}; | ||
const groupProperties = { | ||
version: scope.strapiVersion, | ||
docker: scope.docker, | ||
useYarn: scope.useYarn, | ||
useTypescriptOnServer: scope.useTypescript, | ||
useTypescriptOnAdmin: scope.useTypescript, | ||
isHostedOnStrapiCloud: process.env.STRAPI_HOSTING === 'strapi.cloud', | ||
noRun: (scope.runQuickstartApp !== true).toString(), | ||
projectId: scope.uuid, | ||
}; | ||
return { | ||
eventProperties, | ||
userProperties, | ||
groupProperties: addPackageJsonStrapiMetadata(groupProperties, scope), | ||
}; | ||
const eventProperties = { | ||
error: typeof error === "string" ? error : error && error.message | ||
}; | ||
const userProperties = { | ||
os: os__default.default.type(), | ||
osPlatform: os__default.default.platform(), | ||
osArch: os__default.default.arch(), | ||
osRelease: os__default.default.release(), | ||
nodeVersion: process.versions.node | ||
}; | ||
const groupProperties = { | ||
version: scope.strapiVersion, | ||
docker: scope.docker, | ||
useYarn: scope.useYarn, | ||
useTypescriptOnServer: scope.useTypescript, | ||
useTypescriptOnAdmin: scope.useTypescript, | ||
isHostedOnStrapiCloud: process.env.STRAPI_HOSTING === "strapi.cloud", | ||
noRun: (scope.runQuickstartApp !== true).toString(), | ||
projectId: scope.uuid | ||
}; | ||
return { | ||
eventProperties, | ||
userProperties, | ||
groupProperties: addPackageJsonStrapiMetadata(groupProperties, scope) | ||
}; | ||
}; | ||
function trackEvent(event, payload) { | ||
if (process.env.NODE_ENV === 'test') { | ||
return; | ||
} | ||
try { | ||
return (0, node_fetch_1.default)('https://analytics.strapi.io/api/v2/track', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
event, | ||
...payload, | ||
}), | ||
timeout: 1000, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'X-Strapi-Event': event, | ||
}, | ||
}).catch(() => { }); | ||
} | ||
catch (err) { | ||
/** ignore errors */ | ||
return Promise.resolve(); | ||
} | ||
if (process.env.NODE_ENV === "test") { | ||
return; | ||
} | ||
try { | ||
return fetch__default.default("https://analytics.strapi.io/api/v2/track", { | ||
method: "POST", | ||
body: JSON.stringify({ | ||
event, | ||
...payload | ||
}), | ||
timeout: 1e3, | ||
headers: { | ||
"Content-Type": "application/json", | ||
"X-Strapi-Event": event | ||
} | ||
}).catch(() => { | ||
}); | ||
} catch (err) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
async function trackError({ scope, error }) { | ||
const properties = getProperties(scope, error); | ||
try { | ||
return await trackEvent('didNotCreateProject', { | ||
deviceId: scope.deviceId, | ||
...properties, | ||
}); | ||
} | ||
catch (err) { | ||
/** ignore errors */ | ||
return Promise.resolve(); | ||
} | ||
const properties = getProperties(scope, error); | ||
try { | ||
return await trackEvent("didNotCreateProject", { | ||
deviceId: scope.deviceId, | ||
...properties | ||
}); | ||
} catch (err) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
async function trackUsage({ | ||
event, | ||
scope, | ||
error | ||
}) { | ||
const properties = getProperties(scope, error); | ||
try { | ||
return await trackEvent(event, { | ||
deviceId: scope.deviceId, | ||
...properties | ||
}); | ||
} catch (err) { | ||
return Promise.resolve(); | ||
} | ||
} | ||
exports.captureException = captureException; | ||
exports.captureStderr = captureStderr; | ||
exports.trackError = trackError; | ||
async function trackUsage({ event, scope, error, }) { | ||
const properties = getProperties(scope, error); | ||
try { | ||
return await trackEvent(event, { | ||
deviceId: scope.deviceId, | ||
...properties, | ||
}); | ||
} | ||
catch (err) { | ||
/** ignore errors */ | ||
return Promise.resolve(); | ||
} | ||
} | ||
exports.trackUsage = trackUsage; | ||
//# sourceMappingURL=usage.js.map | ||
//# sourceMappingURL=usage.js.map |
{ | ||
"name": "@strapi/generate-new", | ||
"version": "0.0.0-experimental.996ba09add3e0d8e7794dde5ddc0306f8a9e42cd", | ||
"version": "0.0.0-experimental.99d739783fc4b2410325163af5eb9cf0a6865d47", | ||
"description": "Generate a new Strapi application.", | ||
@@ -32,2 +32,4 @@ "keywords": [ | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"source": "./src/index.ts", | ||
"types": "./dist/index.d.ts", | ||
@@ -38,9 +40,8 @@ "files": [ | ||
"scripts": { | ||
"build": "run -T tsc && run copy-files", | ||
"build:ts": "run build", | ||
"watch": "run -T tsc -w --preserveWatchOutput", | ||
"build": "pack-up build && run copy-files", | ||
"clean": "run -T rimraf ./dist", | ||
"prepublishOnly": "yarn clean && yarn build", | ||
"copy-files": "copyfiles -u 1 -a 'src/resources/files/**/*' 'src/resources/dot-files/**/*' 'src/resources/**/*.template' dist", | ||
"lint": "run -T eslint ." | ||
"lint": "run -T eslint .", | ||
"test:ts": "run -T tsc --noEmit", | ||
"watch": "pack-up watch" | ||
}, | ||
@@ -54,16 +55,17 @@ "dependencies": { | ||
"lodash": "4.17.21", | ||
"node-fetch": "2.6.9", | ||
"node-fetch": "2.7.0", | ||
"node-machine-id": "^1.1.10", | ||
"ora": "^5.4.1", | ||
"semver": "7.5.4", | ||
"tar": "6.1.13" | ||
"tar": "6.2.1" | ||
}, | ||
"devDependencies": { | ||
"@strapi/pack-up": "4.23.0", | ||
"copyfiles": "2.4.1" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0 <=20.x.x", | ||
"node": ">=18.0.0 <=20.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"devDependencies": { | ||
"copyfiles": "2.4.1" | ||
}, | ||
"gitHead": "996ba09add3e0d8e7794dde5ddc0306f8a9e42cd" | ||
"gitHead": "99d739783fc4b2410325163af5eb9cf0a6865d47" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
256638
213
2771
2
1
80
24
3
+ Addedminipass@5.0.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addedtar@6.2.1(transitive)
- Removedminipass@4.2.8(transitive)
- Removednode-fetch@2.6.9(transitive)
- Removedtar@6.1.13(transitive)
Updatednode-fetch@2.7.0
Updatedtar@6.2.1