md-hopper 1.0.0-alpha.1 → 1.0.0-alpha.2
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/options.d.ts +2 -0
- package/dist/_internal/types/settings.d.ts +1 -0
- package/dist/_internal/utils/fs.d.ts +2 -0
- package/dist/_internal/utils/fs.js +9 -0
- package/dist/_internal/utils/log.d.ts +1 -0
- package/dist/_internal/utils/log.js +3 -0
- package/dist/_internal/utils/path.d.ts +1 -2
- package/dist/_internal/utils/path.js +2 -16
- package/dist/_internal/utils/process.js +4 -1
- package/dist/_internal/utils/settings.js +11 -6
- package/dist/cli/commands/generate/action.js +37 -5
- package/dist/cli/commands/generate/command.js +1 -0
- package/dist/cli/commands/help/action.js +9 -9
- package/package.json +11 -11
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { isJson } from 'my-gadgetry/type-check';
|
|
1
3
|
export { getAllFiles } from 'my-gadgetry/fs';
|
|
4
|
+
export const readJsonFileSync = (path, encode = 'utf-8') => {
|
|
5
|
+
const json = isJson(readFileSync(path, encode));
|
|
6
|
+
if (!json) {
|
|
7
|
+
return {};
|
|
8
|
+
}
|
|
9
|
+
return json;
|
|
10
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const getFullPath: (...path: string[]) => string;
|
|
1
|
+
export declare const getExecDir: () => string;
|
|
3
2
|
export declare const getDir: (path: string) => string;
|
|
4
3
|
export declare const DEPTH_TYPES: {
|
|
5
4
|
ancestor: string;
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { SETTING_FILE_NAME } from './configs.js';
|
|
4
|
-
export const getProjectRootPath = () => {
|
|
5
|
-
let path = process.cwd();
|
|
6
|
-
if (!existsSync(join(path, SETTING_FILE_NAME))) {
|
|
7
|
-
for (const _ in process.cwd().split(/\//g)) {
|
|
8
|
-
path = join(path, '..');
|
|
9
|
-
if (existsSync(join(path, SETTING_FILE_NAME))) {
|
|
10
|
-
break;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return path;
|
|
15
|
-
};
|
|
16
|
-
export const getFullPath = (...path) => join(getProjectRootPath(), ...path);
|
|
1
|
+
import { parse, relative } from 'path';
|
|
2
|
+
export const getExecDir = () => process.cwd();
|
|
17
3
|
export const getDir = (path) => {
|
|
18
4
|
return parse(path).dir;
|
|
19
5
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
1
2
|
import { ENVS } from '../types/process.js';
|
|
2
|
-
import
|
|
3
|
+
import { readJsonFileSync } from './fs.js';
|
|
3
4
|
export * from '../types/process.js';
|
|
5
|
+
const __dirname = import.meta.dirname;
|
|
4
6
|
export const args = process.argv.slice(2);
|
|
5
7
|
export const init = () => {
|
|
8
|
+
const pkg = readJsonFileSync(join(__dirname, '../../..', 'package.json'));
|
|
6
9
|
set(ENVS.PACKAGE_VERSION, pkg.version);
|
|
7
10
|
set(ENVS.IS_DEBUG, bool(process.env.DEBUG) || args.includes('--debug'));
|
|
8
11
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { getParam } from './md.js';
|
|
3
3
|
import { SETTING_FILE_NAME } from './configs.js';
|
|
4
|
-
import {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
import { getExecDir } from './path.js';
|
|
5
|
+
const BOOLEANS = ['skip-hidden'];
|
|
6
|
+
const STRINGS = ['exclude', 'include', 'filenames'];
|
|
7
|
+
const NUMBERS = ['depth'];
|
|
7
8
|
export const DEFAULT_MD_FILE_NAME = 'README.md';
|
|
8
9
|
export const DEFAULT_SETTINGS = Object.freeze({
|
|
9
10
|
'skip-hidden': true,
|
|
@@ -11,6 +12,7 @@ export const DEFAULT_SETTINGS = Object.freeze({
|
|
|
11
12
|
include: [],
|
|
12
13
|
filenames: [DEFAULT_MD_FILE_NAME],
|
|
13
14
|
output: DEFAULT_MD_FILE_NAME,
|
|
15
|
+
depth: 0,
|
|
14
16
|
});
|
|
15
17
|
export const parse = (txt) => {
|
|
16
18
|
const lines = txt.split('\n');
|
|
@@ -23,12 +25,15 @@ export const parse = (txt) => {
|
|
|
23
25
|
const key = keyValue[0].trim();
|
|
24
26
|
const value = keyValue[1].trim();
|
|
25
27
|
let val;
|
|
26
|
-
if (
|
|
28
|
+
if (BOOLEANS.includes(key)) {
|
|
27
29
|
val = JSON.parse(`${value}`);
|
|
28
30
|
}
|
|
29
|
-
else if (
|
|
31
|
+
else if (STRINGS.includes(key)) {
|
|
30
32
|
val = value.split(',');
|
|
31
33
|
}
|
|
34
|
+
else if (NUMBERS.includes(key)) {
|
|
35
|
+
val = Number(value);
|
|
36
|
+
}
|
|
32
37
|
else {
|
|
33
38
|
continue;
|
|
34
39
|
}
|
|
@@ -40,6 +45,6 @@ export const parse = (txt) => {
|
|
|
40
45
|
};
|
|
41
46
|
};
|
|
42
47
|
export const getSettings = (inputFilename) => {
|
|
43
|
-
const readme = readFileSync(`${
|
|
48
|
+
const readme = readFileSync(`${getExecDir()}/${inputFilename || SETTING_FILE_NAME}`, 'utf-8');
|
|
44
49
|
return parse(getParam(readme, 'CONFIG'));
|
|
45
50
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { getAllFiles } from '../../../_internal/utils/fs.js';
|
|
4
|
+
import { info, warn, success } from '../../../_internal/utils/log.js';
|
|
4
5
|
import { getParam, getTitle, replace } from '../../../_internal/utils/md.js';
|
|
5
|
-
import {
|
|
6
|
+
import { getExecDir } from '../../../_internal/utils/path.js';
|
|
6
7
|
import { getDir, getDepthType, DEPTH_TYPES } from '../../../_internal/utils/path.js';
|
|
7
8
|
const replacePath = (str) => str.replace(/\/{2,}/, '/');
|
|
8
9
|
const splitComma = (str, alternative) => (str ? str.split(',') : null) || alternative;
|
|
@@ -13,6 +14,7 @@ const mergeConfig = ({ options, settings }) => {
|
|
|
13
14
|
include: splitComma(options.include, settings.include),
|
|
14
15
|
filenames: splitComma(options.filenames, settings.filenames),
|
|
15
16
|
output: options.output || settings.output,
|
|
17
|
+
depth: Number(options.depth) || settings.depth,
|
|
16
18
|
};
|
|
17
19
|
};
|
|
18
20
|
const classify = (dataList) => {
|
|
@@ -63,17 +65,43 @@ const getPathDetails = (paths, config) => {
|
|
|
63
65
|
return classify(list);
|
|
64
66
|
};
|
|
65
67
|
export const action = async (args) => {
|
|
66
|
-
const
|
|
68
|
+
const isDebug = args.options.debug;
|
|
69
|
+
if (isDebug) {
|
|
70
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
71
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- DEBUG MODE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
72
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
warn('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
76
|
+
warn('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- PRODUCTION MODE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
77
|
+
warn('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
78
|
+
}
|
|
79
|
+
const execDir = getExecDir();
|
|
80
|
+
info('exec dir path', execDir);
|
|
67
81
|
const config = mergeConfig(args);
|
|
82
|
+
info('settings', JSON.stringify(config, null, 2));
|
|
68
83
|
const skipHidden = config['skip-hidden'] ? ['**/.*/**/*', '**/.*'] : [];
|
|
69
84
|
const exclude = [
|
|
70
85
|
'**/node_modules/.*/*',
|
|
71
86
|
'**/node_modules/**/*',
|
|
72
87
|
...skipHidden,
|
|
73
|
-
...config.exclude.map(path => replacePath(`${
|
|
88
|
+
...config.exclude.map(path => replacePath(`${execDir}/${path}`)),
|
|
74
89
|
];
|
|
75
|
-
|
|
76
|
-
const
|
|
90
|
+
info('exclude', JSON.stringify(exclude, null, 2));
|
|
91
|
+
const include = config.include.map(path => replacePath(`${execDir}/${path}`));
|
|
92
|
+
info('include', JSON.stringify(include, null, 2));
|
|
93
|
+
const paths = getAllFiles(execDir, {
|
|
94
|
+
include,
|
|
95
|
+
exclude,
|
|
96
|
+
...(config.depth >= 1 ? { depth: config.depth } : {}),
|
|
97
|
+
}).filter(path => config.filenames.some(filename => path.endsWith(`/${filename}`)));
|
|
98
|
+
info('target paths', JSON.stringify(paths, null, 2));
|
|
99
|
+
if (isDebug) {
|
|
100
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
101
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END OF DEBUG MODE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
102
|
+
info('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
77
105
|
const pathDetails = getPathDetails(paths, config);
|
|
78
106
|
for (const pathDetail of pathDetails) {
|
|
79
107
|
if (pathDetail.lock) {
|
|
@@ -82,6 +110,10 @@ export const action = async (args) => {
|
|
|
82
110
|
const content = replace(pathDetail, pathDetails);
|
|
83
111
|
const output = pathDetail.output || config.output;
|
|
84
112
|
const writePath = output ? join(pathDetail.dir, output) : pathDetail.path;
|
|
113
|
+
success('write file: ', writePath);
|
|
85
114
|
writeFileSync(writePath, content, 'utf-8');
|
|
86
115
|
}
|
|
116
|
+
success('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
117
|
+
success('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- END OF PRODUCTION MODE =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
118
|
+
success('=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-');
|
|
87
119
|
};
|
|
@@ -9,6 +9,7 @@ const setAliases = (commandClass) => {
|
|
|
9
9
|
.option('-f, --filenames <strings>', 'filenames, default: README.md only')
|
|
10
10
|
.option('-o, --output <filename>', 'output filename. default: README.md (replace)')
|
|
11
11
|
.option('-i, --input <filename>', 'target root filename, default: README.md')
|
|
12
|
+
.option('-D, --depth <filename>', 'depth level more than 0')
|
|
12
13
|
.action(options => {
|
|
13
14
|
return action(options);
|
|
14
15
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { platform } from 'node:process';
|
|
2
|
-
import { info } from '../../../_internal/utils/log.js';
|
|
2
|
+
import { info, hop } from '../../../_internal/utils/log.js';
|
|
3
3
|
import { get, ENVS } from '../../../_internal/utils/process.js';
|
|
4
4
|
const ASCII_ART = `
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
| |
|
|
8
|
-
| |
|
|
9
|
-
| |
|
|
10
|
-
| |
|
|
11
|
-
|
|
|
6
|
+
___ ___ _____ _ _ _____ _____ _____ _____ _____
|
|
7
|
+
/ |/ | | _ \\ | | | | / _ \\ | _ \\ | _ \\ | ____| | _ \\
|
|
8
|
+
/ /| /| | | | | | | |_| | | | | | | |_| | | |_| | | |__ | |_| |
|
|
9
|
+
/ / |__/ | | | | | | | _ | | | | | | ___/ | ___/ | __| | _ /
|
|
10
|
+
/ / | | | |_| | | | | | | |_| | | | | | | |___ | | \\ \\
|
|
11
|
+
/_/ |_| |_____/ |_| |_| \\_____/ |_| |_| |_____| |_| \\_\\
|
|
12
12
|
|
|
13
13
|
`;
|
|
14
14
|
const VERSIONS = `
|
|
15
|
-
|
|
15
|
+
MD Hopper: ${get(ENVS.PACKAGE_VERSION)}
|
|
16
16
|
Node: ${process.versions.node}
|
|
17
17
|
OS: ${platform} ${process.arch}
|
|
18
18
|
`;
|
|
19
19
|
const show = () => {
|
|
20
|
-
|
|
20
|
+
hop(ASCII_ART);
|
|
21
21
|
info(VERSIONS);
|
|
22
22
|
};
|
|
23
23
|
export const action = async (_) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "md-hopper",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -63,16 +63,16 @@
|
|
|
63
63
|
"@actions/exec": "^1.1.1",
|
|
64
64
|
"@actions/github": "^6.0.0",
|
|
65
65
|
"chalk": "^5.3.0",
|
|
66
|
-
"commander": "^12.
|
|
66
|
+
"commander": "^12.1.0",
|
|
67
67
|
"marked": "^12.0.2",
|
|
68
68
|
"minimatch": "^9.0.4",
|
|
69
|
-
"my-gadgetry": "^1.
|
|
70
|
-
"zx": "^8.1.
|
|
69
|
+
"my-gadgetry": "^1.2.5",
|
|
70
|
+
"zx": "^8.1.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@babel/core": "^7.24.
|
|
74
|
-
"@babel/preset-env": "^7.24.
|
|
75
|
-
"@babel/preset-typescript": "^7.24.
|
|
73
|
+
"@babel/core": "^7.24.6",
|
|
74
|
+
"@babel/preset-env": "^7.24.6",
|
|
75
|
+
"@babel/preset-typescript": "^7.24.6",
|
|
76
76
|
"@eslint/js": "^8.57.0",
|
|
77
77
|
"@types/jest": "^29.5.12",
|
|
78
78
|
"@typescript-eslint/eslint-plugin": "^7.9.0",
|
|
@@ -87,15 +87,15 @@
|
|
|
87
87
|
"fs-extra": "^11.2.0",
|
|
88
88
|
"husky": "^9.0.11",
|
|
89
89
|
"jest": "^29.7.0",
|
|
90
|
-
"lint-staged": "^15.2.
|
|
90
|
+
"lint-staged": "^15.2.5",
|
|
91
91
|
"npm-run-all2": "^6.2.0",
|
|
92
92
|
"prettier": "^3.2.5",
|
|
93
|
-
"ts-jest": "^29.1.
|
|
93
|
+
"ts-jest": "^29.1.4",
|
|
94
94
|
"ts-node": "^10.9.2",
|
|
95
95
|
"tsc-alias": "^1.8.10",
|
|
96
|
-
"tsx": "^4.
|
|
96
|
+
"tsx": "^4.11.0",
|
|
97
97
|
"typescript": "^5.4.5",
|
|
98
|
-
"typescript-eslint": "^7.
|
|
98
|
+
"typescript-eslint": "^7.11.0"
|
|
99
99
|
},
|
|
100
100
|
"files": [
|
|
101
101
|
"cli",
|