Comparing version 4.9.3 to 4.10.0
@@ -9,2 +9,3 @@ "use strict"; | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const node_fs_1 = require("node:fs"); | ||
const promises_1 = require("node:fs/promises"); | ||
@@ -50,13 +51,2 @@ const node_path_1 = require("node:path"); | ||
} | ||
async function clone(repo, location) { | ||
try { | ||
await (0, generator_1.exec)(`git clone https://github.com/oclif/${repo}.git "${location}" --depth=1`); | ||
} | ||
catch (error) { | ||
const err = error instanceof Error | ||
? new core_1.Errors.CLIError(error) | ||
: new core_1.Errors.CLIError('An error occurred while cloning the template repo'); | ||
throw err; | ||
} | ||
} | ||
const FLAGGABLE_PROMPTS = { | ||
@@ -142,2 +132,5 @@ author: { | ||
this.log(`Generating ${this.args.name} in ${chalk_1.default.green(location)}`); | ||
if ((0, node_fs_1.existsSync)(location)) { | ||
throw new core_1.Errors.CLIError(`The directory ${location} already exists.`); | ||
} | ||
const moduleType = await this.getFlagOrPrompt({ | ||
@@ -148,7 +141,2 @@ defaultValue: 'ESM', | ||
}); | ||
const template = moduleType === 'ESM' ? 'hello-world-esm' : 'hello-world'; | ||
await clone(template, location); | ||
await (0, promises_1.rm)((0, node_path_1.join)(location, '.git'), { force: true, recursive: true }); | ||
// We just cloned the template repo so we're sure it has a package.json | ||
const packageJSON = (await (0, generator_1.readPJSON)(location)); | ||
const githubUser = await fetchGithubUser(); | ||
@@ -158,3 +146,3 @@ const name = await this.getFlagOrPrompt({ defaultValue: this.args.name, name: 'name', type: 'input' }); | ||
const description = await this.getFlagOrPrompt({ | ||
defaultValue: packageJSON.description, | ||
defaultValue: 'A new CLI generated with oclif', | ||
name: 'description', | ||
@@ -164,3 +152,3 @@ type: 'input', | ||
const author = await this.getFlagOrPrompt({ | ||
defaultValue: determineDefaultAuthor(githubUser, packageJSON.author), | ||
defaultValue: determineDefaultAuthor(githubUser, 'Your Name Here'), | ||
name: 'author', | ||
@@ -170,3 +158,3 @@ type: 'input', | ||
const license = await this.getFlagOrPrompt({ | ||
defaultValue: packageJSON.license, | ||
defaultValue: 'MIT', | ||
name: 'license', | ||
@@ -176,3 +164,3 @@ type: 'input', | ||
const owner = await this.getFlagOrPrompt({ | ||
defaultValue: githubUser?.login ?? location.split(node_path_1.sep).at(-2) ?? packageJSON.author, | ||
defaultValue: githubUser?.login ?? location.split(node_path_1.sep).at(-2) ?? 'Your Name Here', | ||
name: 'owner', | ||
@@ -182,3 +170,3 @@ type: 'input', | ||
const repository = await this.getFlagOrPrompt({ | ||
defaultValue: (name ?? packageJSON.repository ?? packageJSON.name).split('/').at(-1) ?? name, | ||
defaultValue: name.split('/').at(-1) ?? name, | ||
name: 'repository', | ||
@@ -192,55 +180,50 @@ type: 'input', | ||
}); | ||
const updatedPackageJSON = { | ||
...packageJSON, | ||
author, | ||
bin: { [bin]: './bin/run.js' }, | ||
bugs: `https://github.com/${owner}/${repository}/issues`, | ||
description, | ||
homepage: `https://github.com/${owner}/${repository}`, | ||
license, | ||
name, | ||
oclif: { | ||
...packageJSON.oclif, | ||
bin, | ||
dirname: bin, | ||
}, | ||
repository: `${owner}/${repository}`, | ||
version: '0.0.0', | ||
}; | ||
if (packageManager !== 'yarn') { | ||
const scripts = (updatedPackageJSON.scripts || {}); | ||
updatedPackageJSON.scripts = Object.fromEntries(Object.entries(scripts).map(([k, v]) => [k, v.replace('yarn', `${packageManager} run`)])); | ||
const [sharedFiles, moduleSpecificFiles] = await Promise.all(['shared', moduleType.toLowerCase()].map((f) => (0, node_path_1.join)(this.templatesDir, 'cli', f)).map(findEjsFiles(location))); | ||
await Promise.all([...sharedFiles, ...moduleSpecificFiles].map(async (file) => { | ||
switch (file.name) { | ||
case 'package.json.ejs': { | ||
const data = { | ||
author, | ||
bin, | ||
description, | ||
license, | ||
moduleType, | ||
name, | ||
owner, | ||
pkgManagerScript: packageManager === 'yarn' ? 'yarn' : `${packageManager} run`, | ||
repository, | ||
}; | ||
await this.template(file.src, file.destination, data); | ||
break; | ||
} | ||
case '.gitignore.ejs': { | ||
await this.template(file.src, file.destination, { packageManager }); | ||
break; | ||
} | ||
case 'README.md.ejs': { | ||
await this.template(file.src, file.destination, { description, name, repository }); | ||
break; | ||
} | ||
case 'onPushToMain.yml.ejs': | ||
case 'onRelease.yml.ejs': | ||
case 'test.yml.ejs': { | ||
await this.template(file.src, file.destination, { | ||
exec: packageManager === 'yarn' ? packageManager : `${packageManager} exec`, | ||
install: packageManager === 'yarn' ? packageManager : `${packageManager} install`, | ||
packageManager, | ||
run: packageManager === 'yarn' ? packageManager : `${packageManager} run`, | ||
}); | ||
break; | ||
} | ||
default: { | ||
await this.template(file.src, file.destination); | ||
} | ||
} | ||
})); | ||
if (process.platform !== 'win32') { | ||
await Promise.all([ | ||
(0, generator_1.exec)(`chmod +x ${(0, node_path_1.join)(location, 'bin', 'run.js')}`), | ||
(0, generator_1.exec)(`chmod +x ${(0, node_path_1.join)(location, 'bin', 'dev.js')}`), | ||
]); | ||
} | ||
const { default: sortPackageJson } = await import('sort-package-json'); | ||
await (0, promises_1.writeFile)((0, node_path_1.join)(location, 'package.json'), JSON.stringify(sortPackageJson(updatedPackageJSON), null, 2)); | ||
await (0, promises_1.rm)((0, node_path_1.join)(location, 'LICENSE')); | ||
await (0, promises_1.rm)((0, node_path_1.join)(location, '.github', 'workflows', 'automerge.yml')); | ||
const existing = (await (0, promises_1.readFile)((0, node_path_1.join)(location, '.gitignore'), 'utf8')).split('\n'); | ||
const updated = (0, util_1.uniq)((0, util_1.compact)([ | ||
'*-debug.log', | ||
'*-error.log', | ||
'node_modules', | ||
'/tmp', | ||
'/dist', | ||
'/lib', | ||
...(packageManager === 'yarn' | ||
? [ | ||
'/package-lock.json', | ||
'.pnp.*', | ||
'.yarn/*', | ||
'!.yarn/patches', | ||
'!.yarn/plugins', | ||
'!.yarn/releases', | ||
'!.yarn/sdks', | ||
'!.yarn/versions', | ||
] | ||
: ['/yarn.lock']), | ||
...existing, | ||
])) | ||
.sort() | ||
.join('\n') + '\n'; | ||
await (0, promises_1.writeFile)((0, node_path_1.join)(location, '.gitignore'), updated); | ||
if (packageManager !== 'yarn') { | ||
await (0, promises_1.rm)((0, node_path_1.join)(location, 'yarn.lock')); | ||
} | ||
await (0, generator_1.exec)(`${packageManager} install`, { cwd: location, silent: false }); | ||
@@ -261,1 +244,8 @@ await (0, generator_1.exec)(`${packageManager} run build`, { cwd: location, silent: false }); | ||
exports.default = Generate; | ||
const findEjsFiles = (location) => async (dir) => (await (0, promises_1.readdir)(dir, { recursive: true, withFileTypes: true })) | ||
.filter((f) => f.isFile() && f.name.endsWith('.ejs')) | ||
.map((f) => ({ | ||
destination: (0, node_path_1.join)(f.path.replace(dir, location), f.name.replace('.ejs', '')), | ||
name: f.name, | ||
src: (0, node_path_1.join)(f.path, f.name), | ||
})); |
@@ -117,8 +117,8 @@ "use strict"; | ||
this.log(`Using package manager ${chalk_1.default.green(packageManager)}`); | ||
const templateOptions = { moduleType }; | ||
const projectBinPath = (0, node_path_1.join)(location, 'bin'); | ||
await this.template((0, node_path_1.join)(this.templatesDir, 'src', 'init', 'dev.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.cmd'), templateOptions); | ||
await this.template((0, node_path_1.join)(this.templatesDir, 'src', 'init', 'dev.js.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.js'), templateOptions); | ||
await this.template((0, node_path_1.join)(this.templatesDir, 'src', 'init', 'run.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'run.cmd'), templateOptions); | ||
await this.template((0, node_path_1.join)(this.templatesDir, 'src', 'init', 'run.js.ejs'), (0, node_path_1.join)(projectBinPath, 'run.js'), templateOptions); | ||
const templateBinPath = (0, node_path_1.join)(this.templatesDir, 'cli', moduleType.toLowerCase(), 'bin'); | ||
await this.template((0, node_path_1.join)(templateBinPath, 'dev.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.cmd')); | ||
await this.template((0, node_path_1.join)(templateBinPath, 'dev.js.ejs'), (0, node_path_1.join)(projectBinPath, 'dev.js')); | ||
await this.template((0, node_path_1.join)(templateBinPath, 'run.cmd.ejs'), (0, node_path_1.join)(projectBinPath, 'run.cmd')); | ||
await this.template((0, node_path_1.join)(templateBinPath, 'run.js.ejs'), (0, node_path_1.join)(projectBinPath, 'run.js')); | ||
if (process.platform !== 'win32') { | ||
@@ -125,0 +125,0 @@ await (0, generator_1.exec)(`chmod +x "${(0, node_path_1.join)(projectBinPath, 'run.js')}"`); |
@@ -1077,3 +1077,3 @@ { | ||
}, | ||
"version": "4.9.3" | ||
"version": "4.10.0" | ||
} |
{ | ||
"name": "oclif", | ||
"description": "oclif: create your own CLI", | ||
"version": "4.9.3", | ||
"version": "4.10.0", | ||
"author": "Salesforce", | ||
@@ -58,3 +58,3 @@ "bin": { | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-perfectionist": "^2.6.0", | ||
"eslint-plugin-perfectionist": "^2.10.0", | ||
"husky": "^9", | ||
@@ -61,0 +61,0 @@ "lint-staged": "^15", |
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
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
254162
102
5289