Skip to content

Commit 2d4ff12

Browse files
committed
feat: enhance prompt check
1 parent e37b255 commit 2d4ff12

File tree

9 files changed

+878
-92
lines changed

9 files changed

+878
-92
lines changed

.github/workflows/coveralls.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
name: Coveralls
22
on:
3-
pull_request:
4-
branches:
5-
- master
6-
- develop
73
push:
84
branches:
95
- master

.github/workflows/deploy.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# name: Build and Deploy
2+
# on:
3+
# push:
4+
# branches:
5+
# - master
6+
# jobs:
7+
# build-and-deploy:
8+
# runs-on: ubuntu-latest
9+
# steps:
10+
# - name: Checkout
11+
# uses: actions/checkout@master
12+
13+
# - name: Build
14+
# run: |
15+
# npm install
16+
# npm run-script build
17+
# env:
18+
# GAID: ${{ secrets.GAID }}
19+
# GITHUB_CLIENT_ID: ${{ secrets.GITHUB_CLIENT_ID }}
20+
# GITHUB_CLIENT_SECRET: ${{ secrets.GITHUB_CLIENT_SECRET }}
21+
22+
# - name: Deploy
23+
# uses: JamesIves/github-pages-deploy-action@master
24+
# with:
25+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
# BRANCH: gh-pages
27+
# FOLDER: docs/.vuepress/dist

index.d.ts

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ import execa from 'execa';
2121
import yParser from 'yargs-parser';
2222
import yUnParser from 'yargs-unparser';
2323
import debug from 'debug';
24+
import importFresh from 'import-fresh';
25+
import shell from 'shelljs';
26+
import onExit from 'signal-exit';
27+
import hash from 'hash-sum';
28+
import path from 'path';
2429

25-
export function tryRequire( id: string, req?: Object): any | null;
30+
export function tryRequire(id: string, req?: Object): any | null;
2631
export function assert(value: any, message?: string | Error): void;
2732

2833
import * as moduleAlias from './src/moduleAlias';
@@ -33,44 +38,10 @@ import * as prompt from './src/prompt';
3338
import * as smartMerge from './src/smartMerge';
3439
import * as virtualFile from './src/virtualFile';
3540
import * as openBrowser from './src/openBrowser';
36-
import * as env from './src/env';
41+
import * as Env from './src/Env';
3742
import validateSchema from './src/validateSchema';
3843
import loadFile from './src/loadFile';
3944

40-
export {
41-
moduleAlias,
42-
getPadLength,
43-
injectHtml,
44-
loadFile,
45-
smartMerge,
46-
virtualFile,
47-
logger,
48-
prompt,
49-
openBrowser,
50-
env,
51-
};
45+
export { moduleAlias, getPadLength, injectHtml, loadFile, smartMerge, virtualFile, logger, prompt, openBrowser, Env };
5246

53-
export {
54-
assert,
55-
fs,
56-
chalk,
57-
cheerio,
58-
semver,
59-
semverRegex,
60-
_,
61-
ora,
62-
dedent,
63-
globby,
64-
globParent,
65-
isGlob,
66-
npa,
67-
parseGitUrl,
68-
multimatch,
69-
stringifyObject,
70-
LRU,
71-
inquirer,
72-
execa,
73-
yParser,
74-
yUnParser,
75-
debug
76-
}
47+
export { assert, fs, chalk, cheerio, semver, semverRegex, _, ora, dedent, globby, globParent, isGlob, npa, parseGitUrl, multimatch, stringifyObject, LRU, inquirer, execa, yParser, yUnParser, debug, importFresh, shell, onExit, hash, path };

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ const thirdParty = {
5656
yParser: 'yargs-parser',
5757
yUnParser: 'yargs-unparser',
5858
debug: 'debug',
59+
importFresh: 'import-fresh',
60+
shell: 'shelljs',
61+
onExit: 'signal-exit',
62+
hash: 'hash-sum',
63+
path: 'path',
5964
};
6065

6166
Object.keys(thirdParty).forEach(key => {

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "@micro-app/shared-utils",
3-
"version": "0.1.11",
3+
"version": "0.1.15",
44
"description": "[Shared] shared utilities for micro-app.",
55
"main": "index.js",
66
"scripts": {
7+
"prepublishOnly": "npm run test",
78
"lint": "eslint .",
89
"lint:fix": "npm run lint -- --fix",
10+
"commit": "git-cz",
911
"test": "jest"
1012
},
1113
"homepage": "https://github.com/MicroAppJS/shared-utils",
@@ -40,8 +42,9 @@
4042
]
4143
},
4244
"devDependencies": {
43-
"@types/jest": "^24.0.24",
45+
"@types/jest": "^24.0.25",
4446
"babel-eslint": "^10.0.3",
47+
"commitizen": "^2",
4548
"eslint": "^5.16.0",
4649
"eslint-config-2o3t": "^1.1.17",
4750
"husky": "^3.1.0",
@@ -53,15 +56,16 @@
5356
"ajv": "^6.10.2",
5457
"ajv-keywords": "^3.4.1",
5558
"assert": "^2.0.0",
56-
"chalk": "^2.4.2",
59+
"chalk": "^3.0.0",
5760
"cheerio": "^1.0.0-rc.3",
5861
"debug": "^4.1.1",
5962
"dedent": "^0.7.0",
6063
"execa": "^3.4.0",
6164
"fs-extra": "^8.1.0",
6265
"git-url-parse": "^11.1.2",
6366
"glob-parent": "^5.1.0",
64-
"globby": "^10.0.1",
67+
"globby": "^10.0.2",
68+
"hash-sum": "^2.0.0",
6569
"import-fresh": "^3.2.1",
6670
"inquirer": "^7.0.1",
6771
"is-glob": "^4.0.1",
@@ -75,6 +79,8 @@
7579
"parse-json": "^5.0.0",
7680
"semver": "^6.3.0",
7781
"semver-regex": "^3.1.0",
82+
"shelljs": "^0.8.3",
83+
"signal-exit": "^3.0.2",
7884
"stream-to-string": "^1.2.0",
7985
"stringify-object": "^3.3.0",
8086
"try-require": "^1.2.1",

src/logger/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class Logger {
175175
*/
176176
spinner(message) {
177177
const defulatOpts = {
178-
text: message,
178+
text: typeof message === 'string' ? `${message}\n` : '',
179179
color: 'yellow',
180180
prefixText: chalk.bgHex('#EC6D29')(chalk.white(' WAIT ')),
181181
};

src/prompt/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,32 @@ function select(message, { choices, filter, validate } = {}) {
6363
});
6464
}
6565

66+
function check(message, { choices, filter, validate } = {}) {
67+
if (!choices || choices.length <= 0) {
68+
logger.throw('prompt', 'select choices is empty!');
69+
}
70+
71+
npmlog.pause();
72+
73+
return inquirer
74+
.prompt([
75+
createDefaultOptions({
76+
type: 'checkbox',
77+
name: 'check',
78+
message,
79+
choices,
80+
pageSize: choices.length,
81+
filter,
82+
validate,
83+
}),
84+
])
85+
.then(answers => {
86+
npmlog.resume();
87+
88+
return answers.check;
89+
});
90+
}
91+
6692
function input(message, { filter, validate } = {}) {
6793
npmlog.pause();
6894

@@ -86,4 +112,5 @@ function input(message, { filter, validate } = {}) {
86112
exports.confirm = confirm;
87113
exports.select = select;
88114
exports.input = input;
115+
exports.check = check;
89116
exports.createDefaultOptions = createDefaultOptions;

test/prompt.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ const prompt = require('../src/prompt');
44

55
(async () => {
66

7+
const d = await prompt.check('check?', {
8+
choices: [
9+
{ name: 'a' },
10+
{ name: 'b', checked: true },
11+
],
12+
});
13+
console.log(d);
14+
715
const a = await prompt.confirm('confirm?');
816
console.log(a);
917
const b = await prompt.select('select?', {

0 commit comments

Comments
 (0)