Skip to content

Commit

Permalink
chore: 添加 scripts 到 lint 规则中
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Dec 1, 2023
1 parent 455653f commit 70b6ab4
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 214 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"release": "plop --plopfile scripts/release.cjs",
"auto:remove": "plop --plopfile scripts/remove.cjs",
"auto:create": "plop --plopfile scripts/create.cjs",
"lint:fix": "eslint --fix --ext .ts,.js,.jsx,.vue .",
"build:debug": "cross-env NODE_ENV=debug vite build",
"deps:fresh": "plop --plopfile scripts/deps-fresh.cjs"
"deps:fresh": "plop --plopfile scripts/deps-fresh.cjs",
"lint:fix": "eslint --fix --ext .ts,.js,.jsx,.vue,.cjs ."
},
"engines": {
"node": ">=18.18.2"
Expand Down
132 changes: 66 additions & 66 deletions scripts/create.cjs
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
const { existsSync } = require("fs");
const { existsSync } = require('fs')

const { showDir, showExt, moduleTypes } = require("./shared/base.cjs");
const { showDir, showExt, moduleTypes } = require('./shared/base.cjs')

/**
* 自动创建
* @param {import('plop').NodePlopAPI} plop
*/
function create(plop) {
let exist = null;
let modulePath = null;
let exist = null
let modulePath = null

plop.setGenerator("controller", {
description: "自动创建",
prompts: [
{
name: "type",
type: "list",
default: "component",
message: "您希望生成哪种类型的模块?",
choices: moduleTypes,
},
{
name: "isMarkdown",
type: "confirm",
message: "是否 markdown 类型?",
default: false,
// 如果是 page 类型需要询问是否为 markdown 类型
when({ type }) {
return type === "page";
},
},
{
name: "name",
type: "input",
message({ type }) {
return `请输入 ${type} 的命名`;
},
},
{
name: "shouldReset",
type: "confirm",
default: false,
message({ type }) {
return `目标 ${type} 已存在,是否重置?`;
},
// 确认模块是否已存在,是则询问是否重置
when({ type, name, isMarkdown }) {
const dir = showDir(type);
const ext = showExt(type, isMarkdown);
modulePath = `src/${dir}/${name}.${ext}`;
exist = existsSync(modulePath);
if (exist) {
return true;
}
},
},
],
actions(answer) {
const { type, shouldReset } = answer;
if (exist && !shouldReset) {
throw new Error(`${type} 创建失败`);
}
return [
{
type: "add",
force: true,
path: `../${modulePath}`,
templateFile: `./template/${type}.hbs`,
},
];
},
});
plop.setGenerator('controller', {
description: '自动创建',
prompts: [
{
name: 'type',
type: 'list',
default: 'component',
message: '您希望生成哪种类型的模块?',
choices: moduleTypes,
},
{
name: 'isMarkdown',
type: 'confirm',
message: '是否 markdown 类型?',
default: false,
// 如果是 page 类型需要询问是否为 markdown 类型
when({ type }) {
return type === 'page'
},
},
{
name: 'name',
type: 'input',
message({ type }) {
return `请输入 ${type} 的命名`
},
},
{
name: 'shouldReset',
type: 'confirm',
default: false,
message({ type }) {
return `目标 ${type} 已存在,是否重置?`
},
// 确认模块是否已存在,是则询问是否重置
when({ type, name, isMarkdown }) {
const dir = showDir(type)
const ext = showExt(type, isMarkdown)
modulePath = `src/${dir}/${name}.${ext}`
exist = existsSync(modulePath)
if (exist) {
return true
}
},
},
],
actions(answer) {
const { type, shouldReset } = answer
if (exist && !shouldReset) {
throw new Error(`${type} 创建失败`)
}
return [
{
type: 'add',
force: true,
path: `../${modulePath}`,
templateFile: `./template/${type}.hbs`,
},
]
},
})
}

module.exports = create;
module.exports = create
54 changes: 27 additions & 27 deletions scripts/deps-fresh.cjs
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const { execSync } = require("child_process");
const { execSync } = require('child_process')

/**
* 自动更新依赖
* @param {import('plop').NodePlopAPI} plop
*/
function depsFresh(plop) {
plop.setGenerator("controller", {
description: "自动更新依赖",
prompts: [
{
name: "type",
type: "list",
default: "patch",
message: "你希望发布一个什么版本?",
choices: ["patch", "minor", "major"],
},
{
name: "shouldWrite",
type: "confirm",
default: false,
message: "是否直接更新?",
},
],
actions(answer) {
const { type, shouldWrite } = answer;
plop.setGenerator('controller', {
description: '自动更新依赖',
prompts: [
{
name: 'type',
type: 'list',
default: 'patch',
message: '你希望发布一个什么版本?',
choices: ['patch', 'minor', 'major'],
},
{
name: 'shouldWrite',
type: 'confirm',
default: false,
message: '是否直接更新?',
},
],
actions(answer) {
const { type, shouldWrite } = answer

execSync(`npx taze ${type} ${shouldWrite ? "-w" : ""}`, {
stdio: "inherit",
});
return [];
},
});
execSync(`npx taze ${type} ${shouldWrite ? '-w' : ''}`, {
stdio: 'inherit',
})
return []
},
})
}

module.exports = depsFresh;
module.exports = depsFresh
64 changes: 32 additions & 32 deletions scripts/release.cjs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
const { execSync } = require("child_process");
const { execSync } = require('child_process')

/**
* 自动发版
* @param {import('plop').NodePlopAPI} plop
*/
function release(plop) {
plop.setGenerator("controller", {
description: "自动发版",
prompts: [
{
name: "type",
type: "list",
default: "patch",
message: "你希望发布一个什么版本?",
choices: [
"patch",
"minor",
"major",
"prepatch",
"premajor",
"preminor",
"prerelease",
],
},
],
actions(answer) {
const { type } = answer;
execSync(
`npx changelogen --${type} --release && git push --follow-tags`,
{
stdio: "inherit",
},
);
return [];
},
});
plop.setGenerator('controller', {
description: '自动发版',
prompts: [
{
name: 'type',
type: 'list',
default: 'patch',
message: '你希望发布一个什么版本?',
choices: [
'patch',
'minor',
'major',
'prepatch',
'premajor',
'preminor',
'prerelease',
],
},
],
actions(answer) {
const { type } = answer
execSync(
`npx changelogen --${type} --release && git push --follow-tags`,
{
stdio: 'inherit',
},
)
return []
},
})
}

module.exports = release;
module.exports = release

0 comments on commit 70b6ab4

Please sign in to comment.