md-hopper 1.0.0-alpha.2 → 1.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/types/settings.d.ts +1 -0
- package/dist/_internal/utils/command.d.ts +1 -1
- package/dist/_internal/utils/command.js +4 -1
- package/dist/_internal/utils/log.js +1 -1
- package/dist/_internal/utils/path.d.ts +1 -0
- package/dist/_internal/utils/path.js +1 -0
- package/dist/_internal/utils/settings.js +1 -0
- package/dist/cli/commands/generate/action.js +7 -4
- package/dist/cli/commands/generate/command.js +3 -2
- package/dist/cli/commands/help/command.js +3 -2
- package/package.json +1 -1
|
@@ -14,5 +14,5 @@ export declare class CommandClass<T extends DefaultOptions> {
|
|
|
14
14
|
description(description: string): CommandClass<T>;
|
|
15
15
|
option(...args: any[]): CommandClass<T>;
|
|
16
16
|
requiredOption(...args: any[]): CommandClass<T>;
|
|
17
|
-
action(action: Action): void;
|
|
17
|
+
action(command: string, action: Action): void;
|
|
18
18
|
}
|
|
@@ -42,8 +42,11 @@ export class CommandClass {
|
|
|
42
42
|
this.program = this.program.requiredOption(flags, ...args);
|
|
43
43
|
return this;
|
|
44
44
|
}
|
|
45
|
-
action(action) {
|
|
45
|
+
action(command, action) {
|
|
46
46
|
this.program = this.program.action(async (...args) => {
|
|
47
|
+
if (['help'].includes(command)) {
|
|
48
|
+
return action(this.args, ...args);
|
|
49
|
+
}
|
|
47
50
|
const options = args[0];
|
|
48
51
|
await this.init(options, getSettings(options.input || ''));
|
|
49
52
|
for (const before of this.befores) {
|
|
@@ -6,7 +6,7 @@ export const warn = (...args) => {
|
|
|
6
6
|
console.log(chalk.hex('#FFA500')(...args));
|
|
7
7
|
};
|
|
8
8
|
export const info = (...args) => {
|
|
9
|
-
console.log(chalk.
|
|
9
|
+
console.log(chalk.hex('#77CFF5')(...args));
|
|
10
10
|
};
|
|
11
11
|
export const error = (...args) => {
|
|
12
12
|
console.log(chalk.red(...args));
|
|
@@ -3,7 +3,7 @@ import { join } from 'path';
|
|
|
3
3
|
import { getAllFiles } from '../../../_internal/utils/fs.js';
|
|
4
4
|
import { info, warn, success } from '../../../_internal/utils/log.js';
|
|
5
5
|
import { getParam, getTitle, replace } from '../../../_internal/utils/md.js';
|
|
6
|
-
import { getExecDir } from '../../../_internal/utils/path.js';
|
|
6
|
+
import { getExecDir, getParseDirPath } from '../../../_internal/utils/path.js';
|
|
7
7
|
import { getDir, getDepthType, DEPTH_TYPES } from '../../../_internal/utils/path.js';
|
|
8
8
|
const replacePath = (str) => str.replace(/\/{2,}/, '/');
|
|
9
9
|
const splitComma = (str, alternative) => (str ? str.split(',') : null) || alternative;
|
|
@@ -13,6 +13,7 @@ const mergeConfig = ({ options, settings }) => {
|
|
|
13
13
|
exclude: splitComma(options.exclude, settings.exclude),
|
|
14
14
|
include: splitComma(options.include, settings.include),
|
|
15
15
|
filenames: splitComma(options.filenames, settings.filenames),
|
|
16
|
+
input: getParseDirPath(options.input || '.'),
|
|
16
17
|
output: options.output || settings.output,
|
|
17
18
|
depth: Number(options.depth) || settings.depth,
|
|
18
19
|
};
|
|
@@ -80,17 +81,19 @@ export const action = async (args) => {
|
|
|
80
81
|
info('exec dir path', execDir);
|
|
81
82
|
const config = mergeConfig(args);
|
|
82
83
|
info('settings', JSON.stringify(config, null, 2));
|
|
84
|
+
const targetDir = join(execDir, config.input);
|
|
85
|
+
info('target dir', targetDir);
|
|
83
86
|
const skipHidden = config['skip-hidden'] ? ['**/.*/**/*', '**/.*'] : [];
|
|
84
87
|
const exclude = [
|
|
85
88
|
'**/node_modules/.*/*',
|
|
86
89
|
'**/node_modules/**/*',
|
|
87
90
|
...skipHidden,
|
|
88
|
-
...config.exclude.map(path => replacePath(
|
|
91
|
+
...config.exclude.map(path => replacePath(join(targetDir, path))),
|
|
89
92
|
];
|
|
90
93
|
info('exclude', JSON.stringify(exclude, null, 2));
|
|
91
|
-
const include = config.include.map(path => replacePath(
|
|
94
|
+
const include = config.include.map(path => replacePath(join(targetDir, path)));
|
|
92
95
|
info('include', JSON.stringify(include, null, 2));
|
|
93
|
-
const paths = getAllFiles(
|
|
96
|
+
const paths = getAllFiles(targetDir, {
|
|
94
97
|
include,
|
|
95
98
|
exclude,
|
|
96
99
|
...(config.depth >= 1 ? { depth: config.depth } : {}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CommandClass } from '../../../_internal/utils/command.js';
|
|
2
2
|
import { action } from './action.js';
|
|
3
|
+
const BASE_COMMAND = 'generate';
|
|
3
4
|
const setAliases = (commandClass) => {
|
|
4
5
|
commandClass
|
|
5
6
|
.description('This command is used to exec target file.')
|
|
@@ -10,11 +11,11 @@ const setAliases = (commandClass) => {
|
|
|
10
11
|
.option('-o, --output <filename>', 'output filename. default: README.md (replace)')
|
|
11
12
|
.option('-i, --input <filename>', 'target root filename, default: README.md')
|
|
12
13
|
.option('-D, --depth <filename>', 'depth level more than 0')
|
|
13
|
-
.action(options => {
|
|
14
|
+
.action(BASE_COMMAND, options => {
|
|
14
15
|
return action(options);
|
|
15
16
|
});
|
|
16
17
|
};
|
|
17
|
-
const commands = [
|
|
18
|
+
const commands = [BASE_COMMAND, 'g'];
|
|
18
19
|
export const init = (program) => {
|
|
19
20
|
for (const command of commands) {
|
|
20
21
|
setAliases(new CommandClass(program).command(command));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CommandClass } from '../../../_internal/utils/command.js';
|
|
2
2
|
import { action } from './action.js';
|
|
3
|
+
const BASE_COMMAND = 'help';
|
|
3
4
|
const setAliases = (commandClass) => {
|
|
4
|
-
commandClass.description('This command is used to show help').action(options => {
|
|
5
|
+
commandClass.description('This command is used to show help').action(BASE_COMMAND, options => {
|
|
5
6
|
return action(options);
|
|
6
7
|
});
|
|
7
8
|
};
|
|
8
|
-
const commands = [
|
|
9
|
+
const commands = [BASE_COMMAND, 'h'];
|
|
9
10
|
export const init = (program) => {
|
|
10
11
|
for (const command of commands) {
|
|
11
12
|
setAliases(new CommandClass(program).command(command));
|