Skip to content

Commit 9fe3a6e

Browse files
authored
🐛 normalize package.json after create (#374)
1 parent 760d1ae commit 9fe3a6e

File tree

4 files changed

+657
-379
lines changed

4 files changed

+657
-379
lines changed

.changeset/three-pets-jog.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aiou/neo": patch
3+
---
4+
5+
normalize package.json

package.json

+8-13
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
"name": "jiangweixian"
2020
},
2121
"main": "index.js",
22-
"files": [
23-
"packages/core"
24-
],
22+
"files": ["packages/core"],
2523
"scripts": {
2624
"lint": "eslint '**/*.{js,ts,tsx,json}'",
2725
"lint:fix": "eslint . --fix",
@@ -34,22 +32,24 @@
3432
"test": "pnpm -r vitest:ci"
3533
},
3634
"lint-staged": {
37-
"**/**/*.{js,ts,tsx,vue,json}": [
38-
"eslint --fix"
39-
]
35+
"**/**/*.{js,ts,tsx,vue,json}": ["eslint --fix"]
4036
},
4137
"devDependencies": {
42-
"@aiou/eslint-config": "^0.5.1",
38+
"@aiou/eslint-config": "^0.7.8",
4339
"@changesets/cli": "^2.19.0",
4440
"cz-emoji": "^1.3.1",
4541
"eslint": "^8.12.0",
4642
"fs-extra": "^10.0.0",
4743
"glob": "7.2.0",
4844
"husky": "^8.0.0",
4945
"lint-staged": "^12.1.7",
50-
"prettier": "^2.5.1",
5146
"typescript": "^4.5.4"
5247
},
48+
"pnpm": {
49+
"patchedDependencies": {
50+
51+
}
52+
},
5353
"config": {
5454
"commitizen": {
5555
"path": "node_modules/cz-emoji"
@@ -60,10 +60,5 @@
6060
"neo"
6161
]
6262
}
63-
},
64-
"pnpm": {
65-
"patchedDependencies": {
66-
67-
}
6863
}
6964
}

packages/core/src/commands/create.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import path from 'path'
22
import inquirer from 'inquirer'
33
import fsExtra from 'fs-extra'
44
import InquirerSearchList from 'inquirer-search-list'
5-
import Listr, { ListrTask } from 'listr'
5+
import type { ListrTask } from 'listr'
6+
import Listr from 'listr'
67
import type { PackageResponse } from '@pnpm/package-store'
78
import isOffline from 'is-offline-node'
89
import pc from 'picocolors'
@@ -11,7 +12,7 @@ import { merge } from 'lodash-es'
1112

1213
import { isMonorepo, isYaml } from '../utils'
1314
import logger, { debug } from '../utils/logger'
14-
import { CommonOptions, AsyncReturnType, Package } from '../interface'
15+
import type { AsyncReturnType, CommonOptions, Package } from '../interface'
1516
import createStore from '../store'
1617
import { usage } from '../utils/show-usage'
1718
import { findPrefPackageByPk } from '../utils/find-pref-package'
@@ -61,7 +62,7 @@ const postgenerate = async ({
6162
if (fsExtra.existsSync(path.join(process.cwd(), project, 'package.json'))) {
6263
const pkg = fsExtra.readJSONSync(path.join(process.cwd(), project, 'package.json'))
6364
pkg.readme = undefined
64-
fsExtra.outputJSONSync(path.join(process.cwd(), project, 'package.json'), pkg)
65+
fsExtra.outputJSONSync(path.join(process.cwd(), project, 'package.json'), pkg, { spaces: 2 })
6566
}
6667
// clear up
6768
common.forEach((filename) => {
@@ -122,7 +123,7 @@ const createTask = ({
122123
title: 'Validate template',
123124
task: () => {
124125
if (!project) {
125-
throw new Error(`<project> is required`)
126+
throw new Error('<project> is required')
126127
}
127128
},
128129
},
@@ -156,6 +157,7 @@ const createTask = ({
156157
if (!ctx.templateResponse) {
157158
throw new Error('template not found')
158159
}
160+
159161
return generate({ project, store, templateResponse: ctx.templateResponse })
160162
},
161163
},
@@ -179,10 +181,10 @@ export const create = async (
179181
template: string,
180182
project: string,
181183
options: CommonOptions &
182-
Pick<CreateOptions, 'latest'> & {
183-
preset: string[]
184-
mono?: boolean
185-
},
184+
Pick<CreateOptions, 'latest'> & {
185+
preset: string[]
186+
mono?: boolean
187+
},
186188
) => {
187189
const store = await createStore(options)
188190
const choices = await store.lockFile.readTemplates({ presetNames: options.preset })
@@ -216,7 +218,9 @@ export const create = async (
216218
message: 'Please select template',
217219
choices,
218220
validate(answer: { template: string; project: string }) {
219-
if (!answer) return 'You must choose template.'
221+
if (!answer) {
222+
return 'You must choose template.'
223+
}
220224

221225
return true
222226
},
@@ -226,7 +230,9 @@ export const create = async (
226230
name: 'project',
227231
message: 'Please enter project name',
228232
validate(answer: { template: string; project: string }) {
229-
if (!answer) return 'You must enter project name.'
233+
if (!answer) {
234+
return 'You must enter project name.'
235+
}
230236

231237
return true
232238
},

0 commit comments

Comments
 (0)