Skip to content

Commit c058758

Browse files
authored
feat: support run generator with version (#381)
* ⬆️ eslint * ✨ store-dir in cmd-run * ✅ cmd-run * 🔥 merge prepack.test * 🚨 fix * ✅ cmd-run test with name@version * 🔥 remove dead fixtures dirs * 📝 changeset * 🚨 fix * 🏷️ (mario) built-use typo * 💚 latest runner * ✅ update related bin-template new version released
1 parent 676b845 commit c058758

File tree

96 files changed

+549
-680
lines changed

Some content is hidden

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

96 files changed

+549
-680
lines changed

.changeset/new-eagles-enjoy.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aiou/neo": minor
3+
---
4+
5+
support run generator with version `neo run generator@version`

.github/workflows/neo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: 'ubuntu-18.04'
11+
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
1414
# pin node version: https://github.com/JiangWeixian/esrua/issues/12

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"cSpell.words": [
33
"Listr",
44
"postgenerate"
5-
]
5+
],
6+
"typescript.tsdk": "node_modules/typescript/lib"
67
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"author": {
1919
"name": "jiangweixian"
2020
},
21-
"main": "index.js",
2221
"files": ["packages/core"],
22+
"main": "index.js",
2323
"scripts": {
2424
"lint": "eslint '**/*.{js,ts,tsx,json}'",
2525
"lint:fix": "eslint . --fix",
@@ -35,7 +35,7 @@
3535
"**/**/*.{js,ts,tsx,vue,json}": ["eslint --fix"]
3636
},
3737
"devDependencies": {
38-
"@aiou/eslint-config": "^0.7.8",
38+
"@aiou/eslint-config": "^0.10.0",
3939
"@changesets/cli": "^2.19.0",
4040
"cz-emoji": "^1.3.1",
4141
"eslint": "^8.12.0",

packages/core/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "3.5.7",
44
"description": "templates cli",
55
"license": "MIT",
6+
"engines": {
7+
"node": ">=12"
8+
},
69
"homepage": "https://github.com/neo-hack/neo#readme",
710
"repository": {
811
"directory": "packages/core",
@@ -12,16 +15,13 @@
1215
"author": {
1316
"name": "JW"
1417
},
15-
"bin": {
16-
"neo": "bin/index.mjs"
17-
},
1818
"files": [
1919
"bin",
2020
"lib",
2121
"assets"
2222
],
23-
"engines": {
24-
"node": ">=12"
23+
"bin": {
24+
"neo": "bin/index.mjs"
2525
},
2626
"scripts": {
2727
"clean": "rimraf lib compiled",
@@ -95,7 +95,7 @@
9595
"terminal-link": "^3.0.0",
9696
"typescript": "4.5.4",
9797
"vitest": "^0.7.7",
98-
"vitest-extra": "^0.0.2",
98+
"vitest-extra": "^0.0.4",
9999
"write-yaml-file": "^4.2.0",
100100
"zen-observable": "^0.8.15"
101101
}

packages/core/rollup.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import commonjs from '@rollup/plugin-commonjs'
21
import alias from '@rollup/plugin-alias'
3-
import { nodeResolve } from '@rollup/plugin-node-resolve'
2+
import commonjs from '@rollup/plugin-commonjs'
43
import json from '@rollup/plugin-json'
4+
import { nodeResolve } from '@rollup/plugin-node-resolve'
55
import { defineConfig } from 'rollup'
66
import size from 'rollup-plugin-size'
7-
import ts from 'rollup-plugin-typescript2'
87
import { terser } from 'rollup-plugin-terser'
8+
import ts from 'rollup-plugin-typescript2'
99

1010
export default defineConfig([
1111
// CommonJS (for Node) and ES module (for bundlers) build.

packages/core/src/cli.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { fileURLToPath } from 'node:url'
2+
13
import { program } from 'commander'
2-
import tl from 'terminal-link'
34
import consola from 'consola'
4-
import { fileURLToPath } from 'url'
5+
import tl from 'terminal-link'
56

67
import { readPkg } from './utils'
7-
import { getBanner } from './utils/show-brand'
8-
import { usage } from './utils/show-usage'
98
import { HOMEPAGE } from './utils/constants'
109
import logger from './utils/logger'
10+
import { getBanner } from './utils/show-brand'
11+
import { usage } from './utils/show-usage'
1112

1213
// polyfill node12 & 14 global variable
1314
global.__filename = fileURLToPath(import.meta.url)
@@ -23,12 +24,12 @@ const cli = program
2324
.addHelpText('beforeAll', () => `${getBanner()}\n`)
2425

2526
const commands = {
26-
create: async () => await import('./commands/create').then((res) => res.create),
27-
list: async () => await import('./commands/list').then((res) => res.list),
28-
add: async () => await import('./commands/add').then((res) => res.add),
29-
run: async () => await import('./commands/run').then((res) => res.run),
30-
prepack: async () => await import('./commands/prepack').then((res) => res.prepack),
31-
whoami: async () => await import('./commands/whoami').then((res) => res.whoami),
27+
create: async () => await import('./commands/create').then(res => res.create),
28+
list: async () => await import('./commands/list').then(res => res.list),
29+
add: async () => await import('./commands/add').then(res => res.add),
30+
run: async () => await import('./commands/run').then(res => res.run),
31+
prepack: async () => await import('./commands/prepack').then(res => res.prepack),
32+
whoami: async () => await import('./commands/whoami').then(res => res.whoami),
3233
}
3334

3435
const handler = (cmdName: string) => {
@@ -80,6 +81,7 @@ cli
8081
)} generator`,
8182
)
8283
.option('-m, --module [modules...]', 'Partial modules of workflow will run')
84+
.option('--store-dir [storeDir]', 'Set store dir')
8385
.action(handler('run'))
8486
.addHelpText('after', usage.run())
8587

@@ -100,7 +102,7 @@ cli
100102
program.parse(process.argv)
101103

102104
consola.wrapConsole()
103-
process.on('unhandledRejection', (err) => consola.error('[unhandledRejection]', err))
104-
process.on('uncaughtException', (err) => consola.error('[uncaughtException]', err))
105-
// @ts-ignore http://nodejs.cn/api/process/process_nodeprecation.html
105+
process.on('unhandledRejection', err => consola.error('[unhandledRejection]', err))
106+
process.on('uncaughtException', err => consola.error('[uncaughtException]', err))
107+
// @ts-expect-error http://nodejs.cn/api/process/process_nodeprecation.html
106108
process.noDeprecation = true

packages/core/src/commands/add.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import logger, { debug } from '../utils/logger'
1+
import Listr from 'listr'
2+
import pc from 'picocolors'
3+
24
import createStore from '../store'
35
import { STORE_PATH } from '../utils/constants'
4-
import { CommonOptions } from '../interface'
6+
import logger, { debug } from '../utils/logger'
57

6-
import Listr from 'listr'
7-
import pc from 'picocolors'
8+
import type { CommonOptions } from '../interface'
89

910
type AddOptions = CommonOptions & {
1011
preset?: boolean

packages/core/src/commands/create.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
import path from 'path'
2-
import inquirer from 'inquirer'
1+
import path from 'node:path'
2+
33
import fsExtra from 'fs-extra'
4+
import gitconfig from 'gitconfig'
5+
import inquirer from 'inquirer'
46
import InquirerSearchList from 'inquirer-search-list'
5-
import type { ListrTask } from 'listr'
6-
import Listr from 'listr'
7-
import type { PackageResponse } from '@pnpm/package-store'
87
import isOffline from 'is-offline-node'
9-
import pc from 'picocolors'
10-
import gitconfig from 'gitconfig'
8+
import Listr from 'listr'
119
import { merge } from 'lodash-es'
10+
import pc from 'picocolors'
1211

13-
import { isMonorepo, isYaml } from '../utils'
14-
import logger, { debug } from '../utils/logger'
15-
import type { AsyncReturnType, CommonOptions, Package } from '../interface'
1612
import createStore from '../store'
17-
import { usage } from '../utils/show-usage'
13+
import { isMonorepo, isYaml } from '../utils'
1814
import { findPrefPackageByPk } from '../utils/find-pref-package'
19-
import { runMario } from '../utils/mario'
2015
import { loadConfig } from '../utils/load-config'
16+
import logger, { debug } from '../utils/logger'
17+
import { runMario } from '../utils/mario'
18+
import { usage } from '../utils/show-usage'
19+
20+
import type { PackageResponse } from '@pnpm/package-store'
21+
import type { ListrTask } from 'listr'
22+
import type {
23+
AsyncReturnType,
24+
CommonOptions,
25+
Package,
26+
} from '../interface'
2127

2228
type CreateOptions = Pick<Package, 'name' | 'pref'> & {
2329
version?: Package['version']

packages/core/src/commands/list/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import pc from 'picocolors'
21
import cols from 'cli-columns'
3-
import { groupBy, countBy } from 'lodash-es'
2+
import { countBy, groupBy } from 'lodash-es'
3+
import pc from 'picocolors'
44

5-
import { ListOptions } from '../../interface'
6-
import logger, { debug } from '../../utils/logger'
75
import createStore from '../../store'
8-
import { listConfigs } from './list-configs'
96
import { colorify } from '../../utils'
7+
import logger, { debug } from '../../utils/logger'
8+
import { listConfigs } from './list-configs'
9+
10+
import type { ListOptions } from '../../interface'
1011

1112
/**
1213
* @description List all templates
@@ -24,7 +25,7 @@ export const list = async (config: string, params: ListOptions) => {
2425
const templates = await store.lockFile.readTemplates({ presetNames: params.preset })
2526
const counters = countBy(templates, 'name')
2627
if (!templates.length) {
27-
logger.log(`No templates...`)
28+
logger.log('No templates...')
2829
return
2930
}
3031
logger.log(`${pc.cyan('Note:')} ${pc.green('cached')}, ${pc.gray('uncached')}\n`)

packages/core/src/commands/list/list-configs.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
/**
22
* @fileoverview select and copy rc file
33
*/
4+
import path from 'node:path'
5+
6+
import cols from 'cli-columns'
7+
import copy from 'clipboardy'
8+
import fs from 'fs-extra'
49
import inquirer from 'inquirer'
510
import InquirerSearchList from 'inquirer-search-list'
6-
import path from 'path'
7-
import tempy from 'tempy'
8-
import fs from 'fs-extra'
9-
import copy from 'clipboardy'
11+
import { groupBy } from 'lodash-es'
1012
import pc from 'picocolors'
11-
import cols from 'cli-columns'
13+
import tempy from 'tempy'
1214

13-
import { AsyncReturnType, ListOptions } from '../../interface'
14-
import type createStore from '../../store'
15-
import logger, { debug } from '../../utils/logger'
1615
import { colorify } from '../../utils'
17-
import { groupBy } from 'lodash-es'
16+
import logger, { debug } from '../../utils/logger'
17+
18+
import type { AsyncReturnType, ListOptions } from '../../interface'
19+
import type createStore from '../../store'
1820

1921
inquirer.registerPrompt('search-list', InquirerSearchList)
2022

@@ -25,7 +27,7 @@ export const listConfigs = async (
2527
// read all config files
2628
const configs = await store.lockFile.readConfigs({ presetNames: params.preset })
2729
if (!configs.length) {
28-
logger.log(` No configs...`)
30+
logger.log(' No configs...')
2931
return
3032
}
3133
if (!params.interactive) {
@@ -49,12 +51,12 @@ export const listConfigs = async (
4951
type: 'search-list',
5052
name: 'config',
5153
message: 'Please select config',
52-
choices: configs.map((c) => ({
54+
choices: configs.map(c => ({
5355
name: c.name,
5456
})),
5557
},
5658
])
57-
const pref = configs.find((choice) => choice.name === answers.config)
59+
const pref = configs.find(choice => choice.name === answers.config)
5860
if (!pref) {
5961
debug.list('config not found in preset')
6062
return

packages/core/src/commands/prepack.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import logger from '../utils/logger'
2-
import { run, RunOptions } from './run'
3-
42
import { usage } from '../utils/show-usage'
3+
import { run } from './run'
4+
5+
import type { RunOptions } from './run'
56

67
export const prepack = async (options: RunOptions) => {
78
logger.log(`Prepack will deprecate in next version, please use: \n ${usage.run()}\n`)

packages/core/src/commands/run.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import Listr from 'listr'
2-
import path from 'path'
1+
import path from 'node:path'
2+
3+
import parseWantedDependency from '@pnpm/parse-wanted-dependency'
34
import fs from 'fs-extra'
5+
import Listr from 'listr'
46

5-
import { debug } from '../utils/logger'
6-
import { usage } from '../utils/show-usage'
77
import createStore from '../store'
8-
import { CommonOptions } from '../interface'
98
import { isYaml } from '../utils'
9+
import { debug } from '../utils/logger'
1010
import { runMario } from '../utils/mario'
11+
import { usage } from '../utils/show-usage'
12+
13+
import type { CommonOptions } from '../interface'
1114

1215
export type RunOptions = CommonOptions & { module?: string[] }
1316

@@ -30,7 +33,8 @@ export const run = async (alias: string, params: RunOptions) => {
3033
{
3134
title: `Download mario generator ${alias}`,
3235
task: async () => {
33-
const response = await store.pm.request({ alias, latest: true })
36+
const result = parseWantedDependency(alias)
37+
const response = await store.pm.request({ alias: result.alias, pref: result.pref })
3438
await store.pm.import(target, await response.files?.())
3539
return true
3640
},

packages/core/src/commands/whoami.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { getBanner, showFooter } from '../utils/show-brand'
2-
import logger from '../utils/logger'
3-
41
import pc from 'picocolors'
52

3+
import logger from '../utils/logger'
4+
import { getBanner, showFooter } from '../utils/show-brand'
5+
66
/**
77
* @description display neo image on terminal
88
*/
99
export const whoami = () => {
10-
;(async () => {
10+
(async () => {
1111
logger.log(`${getBanner()}\n`)
1212
logger.log(pc.blue(' ⎯⎯'))
1313
showFooter()

packages/core/src/interface/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import type { Preset, PresetTemplate } from '@aiou/schema'
12
import type { ResolveResult } from '@pnpm/package-store'
2-
import type { PresetTemplate, Preset } from '@aiou/schema'
33

44
export type { Config } from '@aiou/schema'
55

6-
export type CommonOptions = {
6+
export interface CommonOptions {
77
storeDir?: string
88
}
99

@@ -26,7 +26,7 @@ export interface Package extends PresetTemplate {
2626
_name?: string
2727
}
2828

29-
export type LockFile = {
29+
export interface LockFile {
3030
templates?: Record<string, Package>
3131
presets?: Record<string, Preset>
3232
}
@@ -37,6 +37,6 @@ export type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extend
3737
? R
3838
: any
3939

40-
export type AppConfig = {
40+
export interface AppConfig {
4141
mario: string
4242
}

0 commit comments

Comments
 (0)