From 93a79f482f96f69f4f9bca492548654bb6d0894a Mon Sep 17 00:00:00 2001 From: volare <867484528@qq.com> Date: Sun, 4 Dec 2022 15:52:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=9B=B4=E6=8E=A5pake=E6=97=B6?= =?UTF-8?q?=E5=8F=AA=E5=87=BA=E7=8E=B0help=20&=20=E5=8C=85=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 3 +++ bin/cli.ts | 20 +++++++++++++++----- bin/helpers/updater.ts | 7 +++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 bin/helpers/updater.ts diff --git a/.editorconfig b/.editorconfig index 8759d9b..5561adb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,3 +22,6 @@ indent_size = 2 [*.md] trim_trailing_whitespace = false + +[*.ts] +quote_type= "single" diff --git a/bin/cli.ts b/bin/cli.ts index fddffdb..0cf97a6 100644 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -1,16 +1,19 @@ -import { program } from 'commander'; +import { program, createArgument } from 'commander'; +import log from 'loglevel'; import { DEFAULT_PAKE_OPTIONS } from './defaults.js'; import { PakeCliOptions } from './types.js'; import { validateNumberInput, validateUrlInput } from './utils/validate.js'; import handleInputOptions from './options/index.js'; import BuilderFactory from './builders/BuilderFactory.js'; -import log from 'loglevel'; +import { checkUpdateTips } from './helpers/updater.js'; +// @ts-expect-error +import packageJson from '../../package.json'; -program.version('0.0.1').description('A cli application can package a web page to desktop application'); +program.version(packageJson.version).description('A cli application can package a web page to desktop application'); program .showHelpAfterError() - .argument('', 'the web url you want to package', validateUrlInput) + .argument('[url]', 'the web url you want to package', validateUrlInput) .option('--name ', 'application name') .option('--icon ', 'application icon', DEFAULT_PAKE_OPTIONS.icon) .option('--height ', 'window height', validateNumberInput, DEFAULT_PAKE_OPTIONS.height) @@ -20,7 +23,14 @@ program .option('--transparent', 'transparent title bar', DEFAULT_PAKE_OPTIONS.transparent) .option('--debug', 'debug', DEFAULT_PAKE_OPTIONS.transparent) .action(async (url: string, options: PakeCliOptions) => { - log.setDefaultLevel('info') + checkUpdateTips(); + + if (!url) { + // 直接 pake 不需要出现url提示 + program.help(); + } + + log.setDefaultLevel('info'); if (options.debug) { log.setLevel('debug'); } diff --git a/bin/helpers/updater.ts b/bin/helpers/updater.ts new file mode 100644 index 0000000..a0948b7 --- /dev/null +++ b/bin/helpers/updater.ts @@ -0,0 +1,7 @@ +import updateNotifier from 'update-notifier'; +// @ts-expect-error +import packageJson from '../../package.json'; + +export async function checkUpdateTips() { + updateNotifier({ pkg: packageJson }).notify(); +}