From bd88921d02072ac1303cf86dc33359cbf6496803 Mon Sep 17 00:00:00 2001 From: yanhaijing Date: Wed, 1 May 2024 22:31:37 +0800 Subject: [PATCH] fix: fix update miss package.json --- CHANGELOG.md | 4 ++++ CHANGELOG.zh.md | 6 +++++- README.md | 2 +- README.zh-CN.md | 2 +- packages/cli/README.md | 4 ++-- packages/cli/module-js/package.js | 9 ++------- packages/cli/module-ts/package.js | 9 ++------- packages/cli/util/copy.js | 7 +++++++ 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1aedacb..1726a36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## 3.0.5 / 2024-5-1 + +- cli: fix update miss package.json + ## 3.0.4 / 2024-5-1 - cli: fix update error diff --git a/CHANGELOG.zh.md b/CHANGELOG.zh.md index 1881959..9706e94 100644 --- a/CHANGELOG.zh.md +++ b/CHANGELOG.zh.md @@ -1,6 +1,10 @@ # 变更日志 -## 3.0.3 / 2024-5-1 +## 3.0.5 / 2024-5-1 + +- cli: fix update 不更新 package.json + +## 3.0.4 / 2024-5-1 - cli: fix update 时报错 diff --git a/README.md b/README.md index 4672522..386df47 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE) -[![npm](https://img.shields.io/badge/npm-3.0.4-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) +[![npm](https://img.shields.io/badge/npm-3.0.5-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) [![NPM downloads](http://img.shields.io/npm/dm/@js-lib/cli.svg?style=flat-square)](http://www.npmtrends.com/@js-lib/cli) [![Percentage of issues still open](http://isitmaintained.com/badge/open/yanhaijing/jslib-base.svg)](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open') ![example workflow](https://github.com/yanhaijing/jslib-base/actions/workflows/ci.yml/badge.svg) diff --git a/README.zh-CN.md b/README.zh-CN.md index 24f8b4e..0a8703c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE) -[![npm](https://img.shields.io/badge/npm-3.0.4-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) +[![npm](https://img.shields.io/badge/npm-3.0.5-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) [![NPM downloads](http://img.shields.io/npm/dm/@js-lib/cli.svg?style=flat-square)](http://www.npmtrends.com/@js-lib/cli) [![Percentage of issues still open](http://isitmaintained.com/badge/open/yanhaijing/jslib-base.svg)](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open') diff --git a/packages/cli/README.md b/packages/cli/README.md index a1bc394..386df47 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -2,7 +2,7 @@ [![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base) [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yanhaijing/jslib-base/blob/master/LICENSE) -[![npm](https://img.shields.io/badge/npm-3.0.4-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) +[![npm](https://img.shields.io/badge/npm-3.0.5-orange.svg)](https://www.npmjs.com/package/@js-lib/cli) [![NPM downloads](http://img.shields.io/npm/dm/@js-lib/cli.svg?style=flat-square)](http://www.npmtrends.com/@js-lib/cli) [![Percentage of issues still open](http://isitmaintained.com/badge/open/yanhaijing/jslib-base.svg)](http://isitmaintained.com/project/yanhaijing/jslib-base 'Percentage of issues still open') ![example workflow](https://github.com/yanhaijing/jslib-base/actions/workflows/ci.yml/badge.svg) @@ -78,7 +78,7 @@ If you only want to modify the library code generated by the CLI, you can direct After merging, I will migrate the template to the CLI. The template repository is as follows: - [jslib](https://github.com/yanhaijing/jslib) -- [tslit](https://github.com/yanhaijing/tslib) +- [tslib](https://github.com/yanhaijing/tslib) This project uses lerna to manage multiple plugins, common lerna commands are: diff --git a/packages/cli/module-js/package.js b/packages/cli/module-js/package.js index f18e68d..11a1cce 100644 --- a/packages/cli/module-js/package.js +++ b/packages/cli/module-js/package.js @@ -10,7 +10,7 @@ function init(cmdPath, name, option) { ); } -function update(cmdPath, option) { +function update(cmdPath, _option) { console.log('package: update'); // 删除 1.x 版本的无用数据 util.deleteJSONKeys( @@ -31,12 +31,7 @@ function update(cmdPath, option) { exports, types, config, - } = JSON.parse( - util.readTmpl( - path.resolve(__dirname, `./template/package.json.tmpl`), - option, - ), - ); + } = util.readJSON(path.resolve(__dirname, `./template/base/package.json`)); util.mergeObj2JSON( { diff --git a/packages/cli/module-ts/package.js b/packages/cli/module-ts/package.js index f18e68d..11a1cce 100644 --- a/packages/cli/module-ts/package.js +++ b/packages/cli/module-ts/package.js @@ -10,7 +10,7 @@ function init(cmdPath, name, option) { ); } -function update(cmdPath, option) { +function update(cmdPath, _option) { console.log('package: update'); // 删除 1.x 版本的无用数据 util.deleteJSONKeys( @@ -31,12 +31,7 @@ function update(cmdPath, option) { exports, types, config, - } = JSON.parse( - util.readTmpl( - path.resolve(__dirname, `./template/package.json.tmpl`), - option, - ), - ); + } = util.readJSON(path.resolve(__dirname, `./template/base/package.json`)); util.mergeObj2JSON( { diff --git a/packages/cli/util/copy.js b/packages/cli/util/copy.js index 2f5a77f..b0528fb 100644 --- a/packages/cli/util/copy.js +++ b/packages/cli/util/copy.js @@ -71,6 +71,12 @@ function readTmpl(from, data = {}) { return template(text, data); } +function readJSON(from) { + const txt = fs.readFileSync(from, { encoding: 'utf8' }); + const json = JSON.parse(txt); + return json; +} + function copyTmpl(from, to, data = {}, opt = { cover: true }) { // 不覆盖时,检测文件是否存在 if (!opt.cover && fs.existsSync(to)) { @@ -225,6 +231,7 @@ function insertText2File(text, filepath, line = -1) { exports.copyDir = copyDir; exports.copyFile = copyFile; exports.readTmpl = readTmpl; +exports.readJSON = readJSON; exports.copyTmpl = copyTmpl; exports.mergeObj2JSON = mergeObj2JSON; exports.deleteJSONKeys = deleteJSONKeys;