Skip to content

Commit

Permalink
fix: fix update miss package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhaijing committed May 1, 2024
1 parent 3e9bef2 commit bd88921
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.zh.md
Original file line number Diff line number Diff line change
@@ -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 时报错

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:

Expand Down
9 changes: 2 additions & 7 deletions packages/cli/module-js/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
{
Expand Down
9 changes: 2 additions & 7 deletions packages/cli/module-ts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
{
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/util/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bd88921

Please sign in to comment.