Skip to content

Commit

Permalink
chore: release is work.
Browse files Browse the repository at this point in the history
  • Loading branch information
radiorz committed Aug 13, 2024
1 parent 4973854 commit 32582ff
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 94 deletions.
1 change: 0 additions & 1 deletion packages/cli-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"devDependencies": {
"@types/lodash": "^4.17.7",
"@types/commander": "^2.12.2",
"@types/node": "^20.3.1",
"ts-node": "^10.9.2",
"tsup": "^8.2.4",
Expand Down
18 changes: 2 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion templates/create-tsup/templates/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"commander": "^12.1.0"
},
"devDependencies": {
"@types/commander": "^2.12.2",
"@types/node": "^20.3.1",
"ts-node": "^10.9.1",
"tsup": "^8.0.2",
Expand Down
2 changes: 1 addition & 1 deletion tools/create-tools/lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { program } from 'commander';
import { Creator, DEFAULT_OPTIONS } from './Creator';
import { echoPackage } from './package';
import { OptionHandler } from '@tikkhun/cli-utils';
import { OptionHandler } from '@tikkhun/cli-core';
echoPackage();
const stringDefaultOptions = OptionHandler.toString(DEFAULT_OPTIONS);
program
Expand Down
4 changes: 2 additions & 2 deletions tools/create-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tikkhun/create",
"version": "0.1.11",
"version": "0.1.12",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -46,7 +46,7 @@
"vitest": "^1.6.0"
},
"dependencies": {
"@tikkhun/cli-utils": "workspace:^",
"@tikkhun/cli-core": "workspace:^",
"@tikkhun/logger": "^1.0.7",
"commander": "^12.1.0",
"ejs": "^3.1.10",
Expand Down
1 change: 0 additions & 1 deletion tools/dir-flat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"pkg": "^5.8.1"
},
"devDependencies": {
"@types/commander": "^2.12.2",
"@types/node": "^20.3.1",
"ts-node": "^10.9.1",
"tsup": "^8.0.2",
Expand Down
117 changes: 47 additions & 70 deletions tools/release-tools/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,52 @@
#!/usr/bin/env node
import { Command, program } from 'commander';
import { Logger } from '@tikkhun/logger';
import { Release, DEFAULT_RELEASE_OPTIONS, ReleaseFileNameOptions } from '../lib/Release';
import { Cli } from '@tikkhun/cli-core';
import { Release, DEFAULT_RELEASE_OPTIONS } from '../lib';
import packageJson from '../package.json';
import { OptionHandler } from '@tikkhun/cli-utils';
import { unflatJson, jsonToList, flatJson } from '@tikkhun/utils-core';
import _ from 'lodash';
const { get } = _;
const { name, version } = packageJson;
Logger.log(`[欢迎使用] ${name}`);
const stringDefaultOptions = OptionHandler.toString(DEFAULT_RELEASE_OPTIONS);
// TODO 暂时不支持function
delete stringDefaultOptions.releaseFileNameOptions.releaseFileNameBuilder;
delete stringDefaultOptions.releaseFileNameOptions.workspace;
program.version(version);
const optionTypes = {
workspace: 'string',
include: 'array',
exclude: 'array',
archiveType: 'string',
archiveOptions: { zlib: { level: 'number' } },
releasePath: 'string',
clean: 'boolean',
//
releaseFileNameOptions: {
projectName: 'string',
withVersion: 'boolean',
withTime: 'boolean',
timePattern: 'string',
versionTag: 'string',
environment: 'string',

const cli = new Cli({
version: packageJson.version,
description: packageJson.description,
defaultOptions: DEFAULT_RELEASE_OPTIONS,
excludeOptions: [
//
'releaseFileNameOptions.releaseFileNameBuilder',
'releaseFileNameOptions.workspace',
],
optionTypes: {
workspace: 'string',
include: 'array',
exclude: 'array',
archiveType: 'string',
archiveOptions: { zlib: { level: 'number' } },
releasePath: 'string',
clean: 'boolean',
releaseFileNameOptions: {
projectName: 'string',
withVersion: 'boolean',
withTime: 'boolean',
timePattern: 'string',
versionTag: 'string',
environment: 'string',
},
},
};
function setOptionsByDefaultAndTitles(
program: Command,
options: Record<string, any>,
optionTitles: Record<string, any>,
): Command {
const optionList = jsonToList({ delimiter: '.', json: options });
const optionTypeMap = flatJson({ delimiter: '.', data: optionTypes });
optionList.forEach(({ key, value }) => {
const type = optionTypeMap[key];
program.option(`--${key} <${type}>`, get(optionTitles, key), value);
});
return program;
}
const optionTitles = {
workspace: '项目根目录',
include: '包含问界',
exclude: '排除文件',
archiveType: '打包类型',
archiveOptions: '打包选项',
clean: '清空旧记录',
releasePath: '释放文件夹',
releaseFileNameOptions: {
projectName: '项目名称',
withVersion: '带有版本',
versionTag: '版本标志',
withTime: '带有时间',
timePattern: '时间格式',
environment: '环境参数',
optionTitles: {
workspace: '项目根目录',
include: '包含问界',
exclude: '排除文件',
archiveType: '打包类型',
archiveOptions: '打包选项',
clean: '清空旧记录',
releasePath: '释放文件夹',
releaseFileNameOptions: {
projectName: '项目名称',
withVersion: '带有版本',
versionTag: '版本标志',
withTime: '带有时间',
timePattern: '时间格式',
environment: '环境参数',
},
},
};
setOptionsByDefaultAndTitles(program, stringDefaultOptions, optionTitles).action(async (options: any) => {
const jsonOptions = unflatJson({
delimiter: '.',
data: options,
});
const typedOptions = OptionHandler.toType(jsonOptions, optionTypes);

const release = new Release(typedOptions);
});
cli.start(async (option) => {
const release = new Release(option);
await release.start();
});
program.parse(process.argv);
4 changes: 2 additions & 2 deletions tools/release-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tikkhun/release",
"version": "0.0.14",
"version": "0.0.15",
"description": "",
"main": "dist/lib/index.js",
"module": "dist/lib/index.mjs",
Expand Down Expand Up @@ -36,7 +36,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@tikkhun/cli-utils": "workspace:^",
"@tikkhun/cli-core": "workspace:^",
"@tikkhun/logger": "workspace:^",
"@tikkhun/utils-core": "workspace:^",
"archiver": "^7.0.1",
Expand Down

0 comments on commit 32582ff

Please sign in to comment.