Skip to content

Commit 75ee748

Browse files
committed
chore: cosmetic changes
1 parent 3c66889 commit 75ee748

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"prepublishOnly": "npm run clean && npm run build",
1111
"readme": "doctoc -p README.md",
1212
"release": "release-it",
13-
"test": "npm run tsup && vitest --run",
13+
"test": "npm run build && vitest --run",
1414
"toc": "doctoc README.md",
1515
"tsup": "tsup src/index.ts src/cli.ts -d lib"
1616
},

src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ ${chalk.yellow(
4040

4141
create('create-create-app', {
4242
templateRoot,
43+
caveat,
4344
promptForTemplate: true,
45+
4446
modifyName: (name) => (name.startsWith('create-') ? name : `create-${name}`),
47+
4548
after: async ({ installNpmPackage }: AfterHookOptions) => {
4649
console.log('Installing the latest version of create-create-app');
4750
await installNpmPackage('create-create-app');
4851
},
49-
caveat,
5052
});

src/index.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface AfterHookOptions {
5050
command: string,
5151
options?: CommonOptions<string>
5252
) => ExecaChildProcess<string>;
53-
installNpmPackage: (packageName: string) => Promise<void>;
53+
installNpmPackage: (packageName: string, isDev?: boolean) => Promise<void>;
5454
}
5555

5656
export enum NodePM {
@@ -89,40 +89,39 @@ async function getYargsOptions(
8989
interactive: { default: true },
9090
description: {
9191
type: 'input',
92-
describe: 'description',
92+
describe: 'Description',
9393
default: 'description',
9494
prompt: 'if-no-arg',
9595
},
9696
author: {
9797
type: 'input',
98-
describe: 'author name',
98+
describe: 'Author name',
9999
default: gitUser.name,
100100
prompt: 'if-no-arg',
101101
},
102102
email: {
103103
type: 'input',
104-
describe: 'author email',
104+
describe: 'Author email',
105105
default: gitUser.email,
106106
prompt: 'if-no-arg',
107107
},
108108
template: {
109109
type: 'list',
110-
describe: 'template',
110+
describe: 'Template',
111111
default: 'default',
112112
prompt: askForTemplate ? 'if-no-arg' : 'never',
113113
choices: availableTemplates,
114114
},
115115
license: {
116116
type: 'list',
117-
describe: 'license',
117+
describe: 'License',
118118
choices: [...availableLicenses(), 'UNLICENSED'],
119119
default: promptForLicense ? 'MIT' : 'UNLICENSED',
120120
prompt: promptForLicense ? 'if-no-arg' : 'never',
121121
},
122122
'node-pm': {
123123
type: 'list',
124-
describe:
125-
'select package manager to use for installing packages from npm',
124+
describe: 'package manager to use for installing packages from npm',
126125
choices: ['npm', 'yarn', 'pnpm'],
127126
default: undefined, // undefined by default, we'll try to guess pm manager later
128127
prompt: promptForNodePM ? 'if-no-arg' : 'never',
@@ -225,10 +224,19 @@ export async function create(appName: string, options: Options) {
225224
// do not generate LICENSE
226225
}
227226

227+
const run = (command: string, options: CommonOptions<string> = {}) => {
228+
const args = command.split(' ');
229+
return execa(args[0], args.slice(1), {
230+
stdio: 'inherit',
231+
cwd: packageDir,
232+
...options,
233+
});
234+
};
235+
228236
// init git
229-
const skipGit = args['skip-git'];
230237

231238
// init git if option skipGitInit or arg --skip-git are not set
239+
const skipGit = args['skip-git'];
232240
if (!(options.skipGitInit || skipGit)) {
233241
try {
234242
console.log('\nInitializing a git repository');
@@ -239,17 +247,11 @@ export async function create(appName: string, options: Options) {
239247
}
240248
}
241249

242-
const run = (command: string, options: CommonOptions<string> = {}) => {
243-
const args = command.split(' ');
244-
return execa(args[0], args.slice(1), {
245-
stdio: 'inherit',
246-
cwd: packageDir,
247-
...options,
248-
});
249-
};
250-
251250
// run Node.js related tasks (only if `package.json` does exist in the template root)
252-
let installNpmPackage = async (packageName: string): Promise<void> => {};
251+
let installNpmPackage = async (
252+
pkg: string,
253+
isDev?: boolean
254+
): Promise<void> => {};
253255

254256
if (exists('package.json', packageDir)) {
255257
const nodePMArg = args['node-pm'];
@@ -267,16 +269,14 @@ export async function create(appName: string, options: Options) {
267269
pkg: string | string[],
268270
isDev: boolean = false
269271
): Promise<void> => {
270-
await addDeps({
271-
rootDir: packageDir,
272-
deps: Array.isArray(pkg) ? pkg : [pkg],
272+
await addDeps(packageDir, Array.isArray(pkg) ? pkg : [pkg], {
273273
isDev,
274274
pm: packageManager,
275275
});
276276
};
277277
}
278278

279-
const afterHookOptions = {
279+
const afterHookOptions: AfterHookOptions = {
280280
name,
281281
packageDir,
282282
template,

src/npm.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NodePM, printCommand, CLIError } from '.';
1+
import { CLIError, NodePM, printCommand } from '.';
22
import { spawnPromise } from './fs';
33

44
function getPm(name: string) {
@@ -11,7 +11,7 @@ function getPm(name: string) {
1111

1212
case 'npm':
1313
return NodePM.Npm;
14-
14+
1515
default:
1616
return NodePM.Npm;
1717
}
@@ -23,17 +23,17 @@ function getPm(name: string) {
2323
// https://github.com/zkochan/packages/tree/main/which-pm-runs
2424
export function whichPm(defaultPm?: string) {
2525
// if there's a default pm (passed by argv), use it
26-
if(defaultPm) {
26+
if (defaultPm) {
2727
return getPm(defaultPm);
2828
}
2929

3030
if (!process.env.npm_config_user_agent) {
3131
return NodePM.Npm;
3232
}
3333

34-
const pmSpec = process.env.npm_config_user_agent.split(' ')[0]
35-
const separatorPos = pmSpec.lastIndexOf('/')
36-
const name = pmSpec.substring(0, separatorPos)
34+
const pmSpec = process.env.npm_config_user_agent.split(' ')[0];
35+
const separatorPos = pmSpec.lastIndexOf('/');
36+
const name = pmSpec.substring(0, separatorPos);
3737

3838
return getPm(name);
3939
}
@@ -72,17 +72,17 @@ export async function installDeps(rootDir: string, pm: NodePM) {
7272
}
7373
}
7474

75-
export async function addDeps({
76-
rootDir,
77-
deps,
78-
isDev = false,
79-
pm,
80-
}: {
81-
rootDir: string;
82-
deps: string[];
83-
isDev?: boolean;
84-
pm: NodePM;
85-
}) {
75+
export async function addDeps(
76+
rootDir: string,
77+
deps: string[],
78+
{
79+
isDev = false,
80+
pm,
81+
}: {
82+
isDev?: boolean;
83+
pm: NodePM;
84+
}
85+
) {
8686
let command: string;
8787
let args: string[];
8888

0 commit comments

Comments
 (0)