Skip to content

Commit

Permalink
feat: v3
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhaijing committed May 1, 2024
1 parent 6de5337 commit 4c763e1
Show file tree
Hide file tree
Showing 121 changed files with 33,815 additions and 99 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
问题的具体描述,尽量详细

### 环境
- 系统:mac 10.14.1
- node版本:10.12.1
- npm版本:6.5.1
- 系统:mac 12.7.6
- node版本:18.20.5
- npm版本:10.8.2
- 其他版本信息

### 在线例子
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules
package-lock.json
packages/*/package-lock.json
.DS_Store
.eslintcache
temp
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 变更日志

## 3.0.0 / 2025-1-4

- 架构升级,由 module 升级为 template
- 去除 lang 参数
- 交互文案迁移为英文

## 2.3.4 / 2023-11-19

- fix: 升级 [email protected]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

[![](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-2.3.4-orange.svg)](https://www.npmjs.com/package/@js-lib/cli)
[![npm](https://img.shields.io/badge/npm-3.0.0-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)

English | [简体中文](./README.zh-CN.md)
English | [简体中文](https://github.com/yanhaijing/jslib-base/blob/master/README.zh-CN.md)

The best `JS|TS` third-party library scaffold, quickly setup the basic framework of a new library in 10 seconds.

Expand All @@ -27,7 +27,7 @@ The best `JS|TS` third-party library scaffold, quickly setup the basic framework

## :rocket: User Guide

To create a new project, it is recommended to use Node.js version 16 or higher.
To create a new project, it is recommended to use Node.js version 18 or higher.

```bash
$ npx @js-lib/cli new mylib
Expand Down Expand Up @@ -92,11 +92,11 @@ $ npx lerna publish # Release with tag, upload to git, upload to npm

## Change Log

[CHANGELOG.md](./CHANGELOG.md)
[CHANGELOG.md](https://github.com/yanhaijing/jslib-base/blob/master/CHANGELOG.md)

## TODO

[TODO.md](./TODO.md)
[TODO.md](https://github.com/yanhaijing/jslib-base/blob/master/TODO.md)

## Current Users

Expand Down
4 changes: 2 additions & 2 deletions 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-2.3.4-orange.svg)](https://www.npmjs.com/package/@js-lib/cli)
[![npm](https://img.shields.io/badge/npm-3.0.0-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 All @@ -26,7 +26,7 @@

## :rocket: 使用者指南

新建一个项目,推荐使用 Node.js 16 及以上版本。
新建一个项目,推荐使用 Node.js 18 及以上版本。

```bash
$ npx @js-lib/cli new mylib
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"packages": [
"packages/*"
],
"version": "2.3.4"
"version": "3.0.0-alpha.0"
}
110 changes: 108 additions & 2 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
# `@js-lib/cli`
# [jslib-base](https://github.com/yanhaijing/jslib-base)

The best third party JS|TS library scaffold. [Click for more information](https://github.com/yanhaijing/jslib-base#readme).
[![](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.0-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)

English | [简体中文](https://github.com/yanhaijing/jslib-base/blob/master/README.zh-CN.md)

The best `JS|TS` third-party library scaffold, quickly setup the basic framework of a new library in 10 seconds.

**Libraries based on jslib-base can be shared on the [jsmini](https://github.com/jsmini) platform.**

## :star: Features

- Command-line tool for quick creation and seamless upgrades
- Supports writing source code in ES6+ or TypeScript, and compiles to generate production code
- Auto-injection of third-party dependencies (automatically removes unnecessary code in third-party dependencies through tree shaking)
- Supports multiple environments (native browser, AMD, commonjs, Webpack, Rollup, vite, fis, Node.js, etc.)
- Integrated code style checker (eslint + prettier + husky)
- Integrated unit test environment (mocha)
- Integrated test coverage report (istanbul+nyc)
- Integrated continuous integration tool github action
- Integrated with [jsmini](https://github.com/jsmini)

## :rocket: User Guide

To create a new project, it is recommended to use Node.js version 18 or higher.

```bash
$ npx @js-lib/cli new mylib
# Interactive queries, input project info
$ cd mylib
$ npm i
```

To update the project, just execute the following command in the project root directory.

```bash
$ npx @js-lib/cli update
```

For old projects, you can't directly execute the update command, you can first initialize a config file.

```bash
$ npx @js-lib/cli new -c
```

Directory Overview

```
.
├── demo Usage demo
├── dist Compiled out code
├── doc Project documents
├── src Source code directory
├── test Unit tests
├── CHANGELOG.md Change log
└── TODO.md To-do features
```

Common command scripts

```bash
$ npm run lint
$ npm run test
$ npm run build
$ npm run release
$ npm publish
```

## Contribution Guide

This project uses lerna to manage multiple plugins, common lerna commands are:

```bash
$ npx lerna init # Initialization
$ npx lerna create @js-lib/todo # Create a package
$ npx lerna add yargs --scope=@js-lib/cli # Install dependencies for a package
$ npx lerna list # List all the packages
$ npx lerna bootstrap # Install all dependencies
$ npx lerna link # Create all links
$ npx lerna changed # List the packages to be updated in the next release
$ npx lerna publish # Release with tag, upload to git, upload to npm
```

## Contributors

[contributors](https://github.com/yanhaijing/jslib-base/graphs/contributors)

## Change Log

[CHANGELOG.md](https://github.com/yanhaijing/jslib-base/blob/master/CHANGELOG.md)

## TODO

[TODO.md](https://github.com/yanhaijing/jslib-base/blob/master/TODO.md)

## Current Users

- [jsmini](https://github.com/jsmini)
- [template.js](https://github.com/yanhaijing/template.js)
- [...](https://github.com/yanhaijing/jslib-base/issues/10)

## Relative links

- [Lerna 中文教程详解](https://juejin.im/post/5ced1609e51d455d850d3a6c)
36 changes: 16 additions & 20 deletions packages/cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const yargs = require('yargs');

const log = require('../util/log');

const { runUpdatePrompts, runInitPrompts } = require('./run-prompts');
const { runInitPrompts } = require('./run-prompts');
const { checkProjectExists } = require('../util/file');
const { init } = require('./init');
const { update } = require('./update');
Expand All @@ -15,45 +15,41 @@ log.init();
yargs
.usage('usage: jslib [options]')
.usage('usage: jslib <command> [options]')
.example('jslib new myproject', '新建一个项目 myproject')
.example('jslib new myproject', 'Create a new project myproject')
.alias('h', 'help')
.alias('v', 'version')
.command(
['new', 'n'],
'新建一个项目',
'Create a new project',
function (yargs) {
return yargs
.option('force', {
alias: 'f',
describe: '强制新建',
describe: 'Force create',
})
.option('config', {
alias: 'c',
describe: '仅初始化配置文件',
describe: 'Initialize only the configuration file',
})
.option('npmname', {
alias: 'n',
describe: '仅初始化 npm 项目名称',
describe: 'Initialize the npm package name',
})
.option('umdname', {
alias: 'umd',
describe: '仅初始化打包时umd name',
describe: 'Initialize the UMD name for package',
})
.option('username', {
alias: 'u',
describe: '仅初始化用户名称',
describe: 'Initialize the username',
})
.option('type', {
alias: 't',
describe: '仅初始化 js/ts 选择',
})
.option('lang', {
alias: 'l',
describe: '仅初始化中英文选择',
describe: 'Initialize the js/ts selection',
})
.option('manager', {
alias: 'm',
describe: '选择仓库包管理方式',
describe: 'Select the package management method',
});
},
function (argv) {
Expand All @@ -62,9 +58,11 @@ yargs
});
},
)
.command(['update', 'u'], '更新一个项目', function (_yargs) {
.command(['update', 'u'], 'Update a project', function (_yargs) {
if (!checkProjectExists(process.cwd(), 'jslib.json')) {
console.error('error: 这不是一个jslib库,缺少jslib.json文件');
console.error(
'error: This is not a jslib library, missing jslib.json file',
);
return;
}

Expand All @@ -74,9 +72,7 @@ yargs
}),
);

runUpdatePrompts().then(function (answers) {
update(json, answers);
});
update(json);
})
.demandCommand()
.epilog('copyright 2018-2023').argv;
.epilog('copyright 2018-2025').argv;
17 changes: 12 additions & 5 deletions packages/cli/bin/init.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const config = require('../module/config');
const cli = require('../index.js');
const modulejs = require('../module-js');
const modulets = require('../module-ts');
const pkg = require('../package.json');
const { checkProjectExists } = require('../util/file');

function init(argv, answers) {
const cmdPath = process.cwd();
const { name, npmname, umdname, username, type, lang, manager } =
Object.assign({}, argv, answers);
const { name, npmname, umdname, username, type, manager } = Object.assign(
{},
argv,
answers,
);
const pathname = String(typeof argv._[1] !== 'undefined' ? argv._[1] : name);

const option = {
Expand All @@ -16,7 +20,6 @@ function init(argv, answers) {
umdname: String(umdname),
username: String(username),
type,
lang,
manager,
version: pkg.version,
};
Expand All @@ -40,7 +43,11 @@ function init(argv, answers) {
return;
}

cli.init(cmdPath, option);
if (option.type === 'js') {
modulejs.init(cmdPath, option);
} else if (option.type === 'ts') {
modulets.init(cmdPath, option);
}
}

exports.init = init;
Loading

0 comments on commit 4c763e1

Please sign in to comment.