-
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
Showing
8 changed files
with
54 additions
and
94 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
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
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
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,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); |
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