-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2db84e
commit 554b315
Showing
8 changed files
with
204 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
- 项目下载变更为从github仓库拉取 | ||
- 优化打包 |
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,24 +1,24 @@ | ||
{ | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.0", | ||
"description": "慕易安的脚手架", | ||
"author": "muyianking", | ||
"license": "ISC", | ||
"keywords": [ | ||
"cli", | ||
"vue", | ||
"rsbuild" | ||
], | ||
"bin": { | ||
"mu": "./bin/index.js" | ||
}, | ||
"dependencies": { | ||
"copy-dir": "^1.3.0", | ||
"fs-extra": "^11.2.0", | ||
"inquirer": "8.2.5", | ||
"mustache": "^4.2.0", | ||
"ora": "^8.1.1", | ||
"yargs": "^17.7.2" | ||
} | ||
} | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.1", | ||
"description": "慕易安的脚手架", | ||
"author": "muyianking", | ||
"license": "ISC", | ||
"keywords": [ | ||
"cli", | ||
"vue", | ||
"rsbuild" | ||
], | ||
"bin": { | ||
"mu": "./bin/index.js" | ||
}, | ||
"dependencies": { | ||
"copy-dir": "^1.3.0", | ||
"fs-extra": "^11.2.0", | ||
"inquirer": "8.2.5", | ||
"mustache": "^4.2.0", | ||
"ora": "^8.1.1", | ||
"yargs": "^17.7.2" | ||
} | ||
} |
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,42 +1,43 @@ | ||
{ | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.0", | ||
"private": false, | ||
"scripts": { | ||
"update-dep": "npm-check-updates && ncu -u && pnpm i", | ||
"commit": "git add . && git cz", | ||
"lint": "git add . && lint-staged", | ||
"husky-lint": "git add . && lint-staged", | ||
"prepare": "husky", | ||
"log": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"publish": "node ./script/publish.js" | ||
}, | ||
"dependencies": { | ||
"download-git-repo": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^3.8.0", | ||
"@commitlint/cli": "^19.5.0", | ||
"@commitlint/config-conventional": "^19.5.0", | ||
"@eslint/eslintrc": "^3.1.0", | ||
"cz-git": "^1.10.1", | ||
"eslint": "^9.13.0", | ||
"eslint-plugin-format": "^0.1.2", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10" | ||
}, | ||
"resolutions": { | ||
"bin-wrapper": "npm:bin-wrapper-china" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-git" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts,vue}": [ | ||
"eslint --fix" | ||
] | ||
} | ||
} | ||
"name": "@muyianking/cli", | ||
"type": "module", | ||
"version": "0.2.1", | ||
"private": false, | ||
"scripts": { | ||
"update-dep": "npm-check-updates && ncu -u && pnpm i", | ||
"commit": "git add . && git cz", | ||
"lint": "git add . && lint-staged", | ||
"husky-lint": "git add . && lint-staged", | ||
"prepare": "husky", | ||
"log": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"publish": "node ./script/publish.js" | ||
}, | ||
"dependencies": { | ||
"download-git-repo": "^3.0.2", | ||
"fs-extra": "^11.2.0" | ||
}, | ||
"devDependencies": { | ||
"@antfu/eslint-config": "^3.8.0", | ||
"@commitlint/cli": "^19.5.0", | ||
"@commitlint/config-conventional": "^19.5.0", | ||
"@eslint/eslintrc": "^3.1.0", | ||
"cz-git": "^1.10.1", | ||
"eslint": "^9.13.0", | ||
"eslint-plugin-format": "^0.1.2", | ||
"husky": "^9.1.6", | ||
"lint-staged": "^15.2.10" | ||
}, | ||
"resolutions": { | ||
"bin-wrapper": "npm:bin-wrapper-china" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "node_modules/cz-git" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts,vue}": [ | ||
"eslint --fix" | ||
] | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,55 +1,74 @@ | ||
import child_process from 'node:child_process' | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import process from 'node:process' | ||
import fsExtra from 'fs-extra' | ||
import { copy } from './utils/file.js' | ||
import getObjectFromJson from './utils/getObjectFromJson.js' | ||
import { exec, getParams } from './utils/tools.js' | ||
|
||
const __dirname = fileURLToPath(import.meta.url) | ||
const root = process.cwd() | ||
|
||
// 读取版本 | ||
function getVersion() { | ||
const package_path = path.resolve(__dirname, `../../cli/package.json`) | ||
// 先从控制台读取 | ||
const { v } = getParams() | ||
if (v) { | ||
return { | ||
version: v, | ||
from: 'cmd', | ||
} | ||
} | ||
|
||
// 没有再从package.json读取 | ||
const package_path = `${root}/package.json` | ||
const _config = getObjectFromJson(package_path) | ||
return _config.version | ||
return { | ||
version: _config.version, | ||
from: 'package', | ||
} | ||
} | ||
|
||
function publish() { | ||
// 将README.md拷贝到包中 | ||
fs.copyFile('./README.md', '../cli/cli/README.md', () => { | ||
|
||
}) | ||
|
||
// 修改package.json版本号 | ||
const _path = `../../package.json` | ||
const package_path = path.resolve(__dirname, _path) | ||
/** | ||
* 覆写版本号 | ||
* @param {string} package_path 重写的package.json路径 | ||
* @param {string} version 版本号 | ||
*/ | ||
function reWriteVersion(package_path, version) { | ||
const _config = getObjectFromJson(package_path) | ||
_config.version = getVersion() | ||
|
||
_config.version = version | ||
const fileStr = JSON.stringify(_config, '', '\t') | ||
fsExtra.outputFile( | ||
package_path, | ||
fileStr, | ||
'utf-8', | ||
) | ||
} | ||
|
||
// 发布入口 | ||
async function main() { | ||
// 将README.md拷贝到包中 | ||
await copy('./README.md', `${root}/core/README.md`) | ||
|
||
// 修改package.json版本号 | ||
const { version, from } = getVersion() | ||
|
||
// 从命令行读取的版本需要回写package.json | ||
if (from !== 'package') { | ||
reWriteVersion(`${root}/package.json`, version) | ||
} | ||
|
||
// 回写core的package.json | ||
reWriteVersion(`${root}/core/package.json`, version) | ||
|
||
// 生成changelog.md | ||
child_process.exec('pnpm log', (error) => { | ||
if (!error) { | ||
// 成功 | ||
child_process.exec('git add .', () => { | ||
const version = `v${_config.version}` | ||
|
||
child_process.exec(`git commit -m"release: :package: ${version}"`, () => { | ||
child_process.exec(`git push && git tag ${version} && git push origin ${version}`, () => { | ||
console.log('\x1B[32m%s\x1B[0m', 'publish success') | ||
}) | ||
}) | ||
}) | ||
} else { | ||
console.log('生成changelog.md失败', error) | ||
} | ||
}) | ||
await exec('pnpm log') | ||
|
||
const _version = `v${version}` | ||
|
||
// git commit | ||
await exec('git add .') | ||
await exec(`git commit -m"release: :package: ${_version}"`) | ||
|
||
// git提交并生成版本tag | ||
await exec(`git push && git tag ${_version} && git push origin ${_version}`) | ||
} | ||
|
||
publish() | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import fs from 'node:fs' | ||
|
||
export function copy(src, dest) { | ||
return new Promise((resolve, reject) => { | ||
fs.copyFile(src, dest, (e) => { | ||
if (e) { | ||
reject(e) | ||
} else { | ||
resolve('success') | ||
} | ||
}) | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import child_process from 'node:child_process' | ||
import process from 'node:process' | ||
|
||
// 获取参数 | ||
export function getParams() { | ||
const params = {} | ||
process.argv.forEach((item) => { | ||
item = item.split('=') | ||
|
||
if (item.length === 2) { | ||
params[item[0]] = item[1] | ||
} | ||
}) | ||
|
||
return params | ||
} | ||
|
||
/** | ||
* 执行指定命令 | ||
* @param {string} cmd 命令 | ||
* @returns | ||
*/ | ||
export function exec(cmd) { | ||
return new Promise((resolve, reject) => { | ||
child_process.exec(cmd, (error) => { | ||
error ? reject(error) : resolve('success') | ||
}) | ||
}) | ||
} |