Skip to content

Commit 50b7c7c

Browse files
committed
feat: create next plugin
- add next-auto-dynamic - stackblitz-webpack-plugin support pnpm - stackblitz-webpack-plugin throw error when file oversize - fix dumi not support esm - update docs - perf tslint
1 parent 4161b0b commit 50b7c7c

File tree

214 files changed

+3984
-3369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+3984
-3369
lines changed

.dumirc.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ export default defineConfig({
2727
ignored: [
2828
'**/__tests__/**',
2929
'**/__typetests__/**',
30+
'**/__example__/**',
3031
'**/__readme__/**',
31-
'**/build',
32-
'**/dist',
32+
'**/build/**',
33+
'**/dist/**',
34+
'**/.next/**',
3335
'**/src/**',
3436
'**/jest.*',
3537
'**/tsconfig.build.json',
3638
'**/tsconfig.build.tsbuildinfo',
3739
'**/tsconfig.compile.json',
3840
'**/*.map',
41+
'**/.gitignore',
3942
'**/.npmignore',
4043
'**/.DS_Store',
4144
'**/LICENSE.md',

@cli/__template__/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $ pnpm add @template/cli -D
3131
│ │ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/shell-lib%22,%22version%22:%222.5.22%22,%22description%22:%22shell%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/shell-lib%22,%22dependencies%22:%5B%22@jest/types%22,%22chokidar%22,%22command-exists%22,%22lodash%22,%22tslib%22,%22ts-jest%22,%22tsd-lite%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/shell-lib">@dumlj/shell-lib</a>
3232
│ │ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/util-lib%22,%22version%22:%222.5.22%22,%22description%22:%22util%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/util-lib%22,%22dependencies%22:%5B%22fs-extra%22,%22glob%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/util-lib">@dumlj/util-lib</a>
3333
│ │ └─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/mock-lib%22,%22version%22:%222.5.22%22,%22description%22:%22mock%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:true,%22location%22:%22@lib/mock-lib%22,%22dependencies%22:%5B%22memfs%22,%22tslib%22,%22webpack%22,%22@jest/types%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/mock-lib">@dumlj/mock-lib</a><sup><small><i>PRIVATE</i></small></sup>
34-
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22fs-extra%22,%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
34+
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22fs-extra%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
3535
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-pretty%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%B8%8A%E8%89%B2%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-pretty%22,%22dependencies%22:%5B%22chalk%22,%22pretty-error%22,%22tslib%22,%22@jest/types%22,%22@types/chalk%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-pretty">@dumlj/feature-pretty</a>
3636
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/shell-lib%22,%22version%22:%222.5.22%22,%22description%22:%22shell%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/shell-lib%22,%22dependencies%22:%5B%22@jest/types%22,%22chokidar%22,%22command-exists%22,%22lodash%22,%22tslib%22,%22ts-jest%22,%22tsd-lite%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/shell-lib">@dumlj/shell-lib</a>
3737
│ └─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/util-lib%22,%22version%22:%222.5.22%22,%22description%22:%22util%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/util-lib%22,%22dependencies%22:%5B%22fs-extra%22,%22glob%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/util-lib">@dumlj/util-lib</a>

@cli/create-cli/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ $ pnpm add @dumlj/create-cli -D
3131
│ │ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/shell-lib%22,%22version%22:%222.5.22%22,%22description%22:%22shell%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/shell-lib%22,%22dependencies%22:%5B%22@jest/types%22,%22chokidar%22,%22command-exists%22,%22lodash%22,%22tslib%22,%22ts-jest%22,%22tsd-lite%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/shell-lib">@dumlj/shell-lib</a>
3232
│ │ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/util-lib%22,%22version%22:%222.5.22%22,%22description%22:%22util%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/util-lib%22,%22dependencies%22:%5B%22fs-extra%22,%22glob%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/util-lib">@dumlj/util-lib</a>
3333
│ │ └─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/mock-lib%22,%22version%22:%222.5.22%22,%22description%22:%22mock%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:true,%22location%22:%22@lib/mock-lib%22,%22dependencies%22:%5B%22memfs%22,%22tslib%22,%22webpack%22,%22@jest/types%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/mock-lib">@dumlj/mock-lib</a><sup><small><i>PRIVATE</i></small></sup>
34-
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22fs-extra%22,%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
34+
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22fs-extra%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
3535
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-pretty%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%B8%8A%E8%89%B2%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-pretty%22,%22dependencies%22:%5B%22chalk%22,%22pretty-error%22,%22tslib%22,%22@jest/types%22,%22@types/chalk%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-pretty">@dumlj/feature-pretty</a>
3636
│ ├─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/shell-lib%22,%22version%22:%222.5.22%22,%22description%22:%22shell%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/shell-lib%22,%22dependencies%22:%5B%22@jest/types%22,%22chokidar%22,%22command-exists%22,%22lodash%22,%22tslib%22,%22ts-jest%22,%22tsd-lite%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/shell-lib">@dumlj/shell-lib</a>
3737
│ └─── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/util-lib%22,%22version%22:%222.5.22%22,%22description%22:%22util%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/util-lib%22,%22dependencies%22:%5B%22fs-extra%22,%22glob%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/util-lib">@dumlj/util-lib</a>
3838
├── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-cliui%22,%22version%22:%222.5.22%22,%22description%22:%22%7B%7Bdescription%7D%7D%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-cliui%22,%22dependencies%22:%5B%22chalk%22,%22tslib%22,%22@jest/types%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-cliui">@dumlj/feature-cliui</a>
39-
├── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22fs-extra%22,%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
39+
├── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-prepare%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%BB%A3%E7%A0%81%E6%BA%90%E6%96%87%E4%BB%B6%E9%A2%84%E5%A4%84%E7%90%86%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-prepare%22,%22dependencies%22:%5B%22get-tsconfig%22,%22interpret%22,%22rechoir%22,%22tslib%22,%22fs-extra%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22,%22ts-node%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-prepare">@dumlj/feature-prepare</a>
4040
├── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/feature-pretty%22,%22version%22:%222.5.22%22,%22description%22:%22%E4%B8%8A%E8%89%B2%E5%B7%A5%E5%85%B7%22,%22isPrivate%22:false,%22location%22:%22@feature/feature-pretty%22,%22dependencies%22:%5B%22chalk%22,%22pretty-error%22,%22tslib%22,%22@jest/types%22,%22@types/chalk%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@feature/feature-pretty">@dumlj/feature-pretty</a>
4141
├── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/shell-lib%22,%22version%22:%222.5.22%22,%22description%22:%22shell%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/shell-lib%22,%22dependencies%22:%5B%22@jest/types%22,%22chokidar%22,%22command-exists%22,%22lodash%22,%22tslib%22,%22ts-jest%22,%22tsd-lite%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/shell-lib">@dumlj/shell-lib</a>
4242
└── <a is="dumlj-link" data-project="%7B%22name%22:%22@dumlj/util-lib%22,%22version%22:%222.5.22%22,%22description%22:%22util%20%E5%B7%A5%E5%85%B7%E5%BA%93%22,%22isPrivate%22:false,%22location%22:%22@lib/util-lib%22,%22dependencies%22:%5B%22fs-extra%22,%22glob%22,%22tslib%22,%22@jest/types%22,%22memfs%22,%22ts-jest%22%5D,%22workspaceDependencies%22:%5B%5D%7D" href="https://github.com/dumlj/dumlj-build/tree/main/@lib/util-lib">@dumlj/util-lib</a>

@cli/create-cli/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"lodash": "^4.17.21",
3434
"ts-morph": "^19.0.0",
3535
"tslib": "^2.5.0",
36-
"typescript": "^5.2.2"
36+
"typescript": "^5.2.2",
37+
"utility-types": "^3.11.0"
3738
},
3839
"devDependencies": {
3940
"@jest/types": "^29.6.3",

@cli/create-cli/src/actions/create/create.ts

+20-13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Project, IndentationText, QuoteKind } from 'ts-morph'
1414
import { highlight } from 'cardinal'
1515
import { DEFAULT_TEMPLATE_PATTERN, DEFAULT_RC_FILE } from './constants'
1616
import type { TemplateSchema } from './types'
17+
import type { Optional } from 'utility-types'
1718

1819
export type Template = TemplateSchema & { src: string; key: string }
1920

@@ -79,14 +80,14 @@ export class Create {
7980
/** pattern of template name in project */
8081
protected pattern?: string
8182
/** name of config file */
82-
protected rc?: string
83+
protected rc: string
8384
/** override exists project */
8485
protected override?: boolean
8586
/** say yes for all confirm */
8687
protected yes?: boolean
8788

88-
protected rules: Record<string, Validator<FormFieldValues>>
89-
private rootPath: string
89+
protected rules: Record<string, Validator<Optional<FormFieldValues>>>
90+
private rootPath?: string
9091

9192
constructor(options?: CreateOptions) {
9293
this.name = options?.name
@@ -98,7 +99,12 @@ export class Create {
9899
this.yes = options?.yes || false
99100

100101
this.rules = {
101-
name: async (name: string, { template }) => {
102+
name: async (name: string, formFieldValues) => {
103+
const template = formFieldValues?.template
104+
if (!template) {
105+
return 'template is required'
106+
}
107+
102108
const { outputPathResolver } = template
103109
const rootPath = await this.getRootPath()
104110
const folder = path.join(rootPath, outputPathResolver(kebabCase(name)))
@@ -160,11 +166,11 @@ export class Create {
160166
return this.rootPath
161167
}
162168

163-
this.rootPath = await findWorkspaceRootPath()
169+
this.rootPath = (await findWorkspaceRootPath()) || process.cwd()
164170
return this.rootPath
165171
}
166172

167-
public async validate(name: string, value: string, formvalues: FormFieldValues) {
173+
public async validate(name: string, value: string, formvalues: Optional<FormFieldValues>) {
168174
const validate = this.rules[name]
169175
if (typeof validate !== 'function') {
170176
throw new Error(`rule ${name} is not exists`)
@@ -212,7 +218,7 @@ export class Create {
212218
validate: (input, answers) => {
213219
return this.validate('name', input, { ...answers, template })
214220
},
215-
transformer(input) {
221+
transformer: (input) => {
216222
const { nameTransform } = template
217223
if (typeof nameTransform === 'function') {
218224
const { name, same, suffix } = nameTransform(input)
@@ -250,9 +256,9 @@ export class Create {
250256
)
251257
}
252258

253-
public async compile(params?: CompileParams) {
259+
public async compile(params: CompileParams) {
254260
const { name, description, output: dist, template } = params
255-
const { src, pkgTransform, tsTransform } = template
261+
const { src, pkgTransform, tsTransform } = template || {}
256262
const files = await glob('**/*', { cwd: src, nodir: true, ignore: [this.rc], dot: true })
257263
const ignores = await gitDetectIgnore(files)
258264

@@ -305,10 +311,11 @@ export class Create {
305311
}
306312

307313
const outFile = path.join(dist, file)
308-
const { file: output = outFile, code } = (await tranform()) || {}
314+
const { file: output = outFile, code = '' } = (await tranform()) || {}
309315
const operates = [...statsOperates]
316+
310317
while (operates.length) {
311-
const fn = operates.shift()
318+
const fn = operates.shift()!
312319
await fn({ src: srcFile, out: output, code })
313320
}
314321
})
@@ -375,7 +382,7 @@ export class Create {
375382
].filter(Boolean)
376383

377384
while (debugs.length) {
378-
const message = debugs.shift()
385+
const message = debugs.shift()!
379386
await pressAnyToContinue({ message })
380387
/* eslint-disable-next-line no-console */
381388
console.log('')
@@ -415,7 +422,7 @@ export class Create {
415422

416423
await fs.writeFile(out, code)
417424
} catch (error) {
418-
fail(error)
425+
fail(error as Error)
419426
}
420427
})
421428

@cli/create-cli/src/actions/install/husky.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export const husky = async (options: InstallHuskyOptions = {}) => {
6060
})
6161
} else if (Array.isArray(command)) {
6262
const [hook, script] = command
63-
commands[hook].push(script)
63+
const chunks = commands[hook]
64+
Array.isArray(chunks) && chunks.push(script)
6465
}
6566

6667
return commands
@@ -73,7 +74,7 @@ export const husky = async (options: InstallHuskyOptions = {}) => {
7374
}
7475

7576
return commands
76-
}, [])
77+
}, [] as string[])
7778

7879
if (commands.length > 0) {
7980
const scripts = ['husky install'].concat(commands).filter(Boolean).join(' && ')
@@ -98,7 +99,7 @@ export const husky = async (options: InstallHuskyOptions = {}) => {
9899
}
99100
} catch (error) {
100101
fs.removeSync(huskyHooksPath)
101-
fail(error)
102+
fail(error as Error)
102103
return
103104
}
104105

@cli/create-cli/src/commands/create.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const mapOptionsToCommand = registerEnhancer('addOption', () => [
1313

1414
const debugCommand = mapOptionsToCommand(
1515
new Command('debug').summary('debug .templaterc.ts').action((options?: CreateOptions, command?: Command) => {
16+
if (!command?.parent) {
17+
return
18+
}
19+
1620
const parentOptions = command.parent.opts()
1721
const finalOptions = { ...parentOptions, ...options }
1822
return tryAction(debug)(finalOptions)

0 commit comments

Comments
 (0)