-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor(dependencies): 重构 npx 代码逻辑 减少生产环境依赖 big deal
- Loading branch information
Showing
10 changed files
with
179 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/core/questions/creator/packageDevice.ts → .../core/questions/creator/packageManager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import path = require('path') | ||
import { readdir } from 'fs/promises' | ||
import fs = require('fs-extra') | ||
import { prompt, QuestionCollection } from 'inquirer' | ||
import options from '@/shared/options' | ||
// import path = require('path') | ||
// import { readdir } from 'fs/promises' | ||
// import fs = require('fs-extra') | ||
// import { prompt, QuestionCollection } from 'inquirer' | ||
// import options from '@/shared/options' | ||
|
||
async function createQuestion(quesiton) { | ||
const result: QuestionCollection = await prompt([quesiton]) | ||
Object.assign(options, result) | ||
return Promise.resolve() | ||
} | ||
// async function createQuestion(quesiton) { | ||
// const result: QuestionCollection = await prompt([quesiton]) | ||
// Object.assign(options, result) | ||
// return Promise.resolve() | ||
// } | ||
|
||
async function createQuestions(): Promise<void> { | ||
const packages = [] | ||
const dirs = await readdir(options.src) | ||
dirs.forEach((pluginPath) => { | ||
const src = path.resolve(options.src, pluginPath, 'package.json') | ||
packages.push(fs.readJsonSync(src)) | ||
}) | ||
options.allPackages = packages | ||
await createQuestion({ | ||
name: 'plugins', | ||
type: 'checkbox', | ||
message: '选择需要安装的组件', | ||
choices: packages.map((item) => ({ | ||
name: item.description, | ||
value: item.name | ||
})) | ||
}) | ||
} | ||
// async function createQuestions(): Promise<void> { | ||
// const packages = [] | ||
// const dirs = await readdir(options.src) | ||
// dirs.forEach((pluginPath) => { | ||
// const src = path.resolve(options.src, pluginPath, 'package.json') | ||
// packages.push(fs.readJsonSync(src)) | ||
// }) | ||
// options.allPackages = packages | ||
// await createQuestion({ | ||
// name: 'plugins', | ||
// type: 'checkbox', | ||
// message: '选择需要安装的组件', | ||
// choices: packages.map((item) => ({ | ||
// name: item.description, | ||
// value: item.name | ||
// })) | ||
// }) | ||
// } | ||
|
||
export default createQuestions | ||
// export default createQuestions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,96 @@ | ||
import child_process from 'child_process' | ||
import chalk from 'chalk' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import ora, { Color } from 'ora' | ||
import util from 'util' | ||
// import child_process from 'child_process' | ||
// import chalk from 'chalk' | ||
// import path from 'path' | ||
// import fs from 'fs' | ||
// import ora, { Color } from 'ora' | ||
// import util from 'util' | ||
|
||
const execSync = child_process.execSync | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const exec = util.promisify(require('child_process').exec) | ||
// const execSync = child_process.execSync | ||
// // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
// const exec = util.promisify(require('child_process').exec) | ||
|
||
export class DefaultLogger { | ||
private _spinner: ora.Ora | ||
// export class DefaultLogger { | ||
// private _spinner: ora.Ora | ||
|
||
public constructor(startText: string) { | ||
this._spinner = ora(startText).start() | ||
} | ||
// public constructor(startText: string) { | ||
// this._spinner = ora(startText).start() | ||
// } | ||
|
||
public log(text: string, color?: Color): void { | ||
if (color) { | ||
this._spinner.color = color | ||
} | ||
this._spinner.text = text | ||
} | ||
// public log(text: string, color?: Color): void { | ||
// if (color) { | ||
// this._spinner.color = color | ||
// } | ||
// this._spinner.text = text | ||
// } | ||
|
||
public succeed(text: string): void { | ||
this._spinner.succeed(text) | ||
} | ||
// public succeed(text: string): void { | ||
// this._spinner.succeed(text) | ||
// } | ||
|
||
public fail(text: string): void { | ||
this._spinner.fail(text) | ||
} | ||
} | ||
// public fail(text: string): void { | ||
// this._spinner.fail(text) | ||
// } | ||
// } | ||
|
||
export const runSync = (command: string, spinner?: DefaultLogger) => { | ||
try { | ||
return execSync(command, { cwd: process.cwd(), encoding: 'utf8' }) | ||
} catch (error) { | ||
spinner.fail('task fail') | ||
process.exit(1) | ||
} | ||
} | ||
// export const runSync = (command: string, spinner?: DefaultLogger) => { | ||
// try { | ||
// return execSync(command, { cwd: process.cwd(), encoding: 'utf8' }) | ||
// } catch (error) { | ||
// spinner.fail('task fail') | ||
// process.exit(1) | ||
// } | ||
// } | ||
|
||
export const runAsync = async (command: string, spinner?: DefaultLogger) => { | ||
try { | ||
await exec(command, { cwd: process.cwd(), encoding: 'utf8' }) | ||
} catch (error) { | ||
spinner.fail('task fail') | ||
process.exit(1) | ||
} | ||
} | ||
// export const runAsync = async (command: string, spinner?: DefaultLogger) => { | ||
// try { | ||
// await exec(command, { cwd: process.cwd(), encoding: 'utf8' }) | ||
// } catch (error) { | ||
// spinner.fail('task fail') | ||
// process.exit(1) | ||
// } | ||
// } | ||
|
||
export const taskPre = (logInfo: string, type: 'start' | 'end') => { | ||
if (type === 'start') { | ||
return `task start(开始任务): ${logInfo} \r\n` | ||
} else { | ||
return `task end(任务结束): ${logInfo} \r\n` | ||
} | ||
} | ||
// export const taskPre = (logInfo: string, type: 'start' | 'end') => { | ||
// if (type === 'start') { | ||
// return `task start(开始任务): ${logInfo} \r\n` | ||
// } else { | ||
// return `task end(任务结束): ${logInfo} \r\n` | ||
// } | ||
// } | ||
|
||
// 获取项目文件 | ||
export const getProjectPath = (dir = './'): string => { | ||
return path.join(process.cwd(), dir) | ||
} | ||
// // 获取项目文件 | ||
// export const getProjectPath = (dir = './'): string => { | ||
// return path.join(process.cwd(), dir) | ||
// } | ||
|
||
export function compose(middleware) { | ||
const otherOptions = {} | ||
function dispatch(index, otherOptions) { | ||
if (index == middleware.length) return | ||
const currMiddleware = middleware[index] | ||
currMiddleware((addOptions) => { | ||
dispatch(++index, { ...otherOptions, ...addOptions }) | ||
}, otherOptions).catch((error) => { | ||
console.log('💣 发布失败,失败原因:', error) | ||
}) | ||
} | ||
dispatch(0, otherOptions) | ||
} | ||
// export function compose(middleware) { | ||
// const otherOptions = {} | ||
// function dispatch(index, otherOptions) { | ||
// if (index == middleware.length) return | ||
// const currMiddleware = middleware[index] | ||
// currMiddleware((addOptions) => { | ||
// dispatch(++index, { ...otherOptions, ...addOptions }) | ||
// }, otherOptions).catch((error) => { | ||
// console.log('💣 发布失败,失败原因:', error) | ||
// }) | ||
// } | ||
// dispatch(0, otherOptions) | ||
// } | ||
|
||
/** | ||
* 获取当前package.json的版本号 | ||
*/ | ||
export const getOriginPackageJson = (): Record<string, any> => { | ||
const packageJson = JSON.parse( | ||
fs.readFileSync(getProjectPath('package.json'), 'utf-8') | ||
) | ||
return packageJson | ||
} | ||
// /** | ||
// * 获取当前package.json的版本号 | ||
// */ | ||
// export const getOriginPackageJson = (): Record<string, any> => { | ||
// const packageJson = JSON.parse( | ||
// fs.readFileSync(getProjectPath('package.json'), 'utf-8') | ||
// ) | ||
// return packageJson | ||
// } | ||
|
||
/** | ||
* 工具函数,用来捕获并打印错误,返回false | ||
*/ | ||
export const basicCatchError = (err: Error) => { | ||
console.log(`\r\n ${chalk.red(err)}`) | ||
return false | ||
} | ||
// /** | ||
// * 工具函数,用来捕获并打印错误,返回false | ||
// */ | ||
// export const basicCatchError = (err: Error) => { | ||
// console.log(`\r\n ${chalk.red(err)}`) | ||
// return false | ||
// } |
Oops, something went wrong.