md-hopper 1.0.0-alpha.1 → 1.0.0-alpha.10

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.
Files changed (58) hide show
  1. package/README.md +20 -5
  2. package/cli/commands/generate/actions/link/package.json +6 -0
  3. package/cli/commands/generate/actions/rc/package.json +6 -0
  4. package/cli/commands/link/README.md/package.json +6 -0
  5. package/cli/commands/link/action/package.json +6 -0
  6. package/cli/commands/link/command/package.json +6 -0
  7. package/dist/_internal/types/command.d.ts +3 -5
  8. package/dist/_internal/types/configs/generate.d.ts +46 -0
  9. package/dist/_internal/types/configs/generate.js +131 -0
  10. package/dist/_internal/types/configs/help.d.ts +2 -0
  11. package/dist/_internal/types/configs/links.d.ts +19 -0
  12. package/dist/_internal/types/configs/links.js +1 -0
  13. package/dist/_internal/types/configs.d.ts +3 -0
  14. package/dist/_internal/types/md.d.ts +5 -2
  15. package/dist/_internal/types/md.js +1 -0
  16. package/dist/_internal/utils/chalk.d.ts +7 -0
  17. package/dist/_internal/utils/chalk.js +8 -0
  18. package/dist/_internal/utils/command.d.ts +13 -11
  19. package/dist/_internal/utils/command.js +10 -4
  20. package/dist/_internal/utils/configs.d.ts +2 -1
  21. package/dist/_internal/utils/configs.js +2 -1
  22. package/dist/_internal/utils/fs.d.ts +4 -0
  23. package/dist/_internal/utils/fs.js +17 -0
  24. package/dist/_internal/utils/link.d.ts +4 -0
  25. package/dist/_internal/utils/{settings.js → link.js} +15 -10
  26. package/dist/_internal/utils/log.d.ts +1 -0
  27. package/dist/_internal/utils/log.js +8 -5
  28. package/dist/_internal/utils/md.d.ts +8 -1
  29. package/dist/_internal/utils/md.js +27 -2
  30. package/dist/_internal/utils/minimatch.d.ts +2 -0
  31. package/dist/_internal/utils/minimatch.js +13 -0
  32. package/dist/_internal/utils/path.d.ts +5 -3
  33. package/dist/_internal/utils/path.js +10 -17
  34. package/dist/_internal/utils/process.js +4 -1
  35. package/dist/cli/commands/generate/action.d.ts +4 -2
  36. package/dist/cli/commands/generate/action.js +9 -84
  37. package/dist/cli/commands/generate/actions/link.d.ts +2 -0
  38. package/dist/cli/commands/generate/actions/link.js +121 -0
  39. package/dist/cli/commands/generate/actions/rc.d.ts +2 -0
  40. package/dist/cli/commands/generate/actions/rc.js +39 -0
  41. package/dist/cli/commands/generate/command.d.ts +7 -2
  42. package/dist/cli/commands/generate/command.js +84 -17
  43. package/dist/cli/commands/help/action.d.ts +2 -2
  44. package/dist/cli/commands/help/action.js +9 -9
  45. package/dist/cli/commands/help/command.d.ts +5 -2
  46. package/dist/cli/commands/help/command.js +5 -7
  47. package/dist/cli/commands/index.js +14 -4
  48. package/dist/cli/commands/link/action.d.ts +5 -0
  49. package/dist/cli/commands/link/action.js +112 -0
  50. package/dist/cli/commands/link/command.d.ts +5 -0
  51. package/dist/cli/commands/link/command.js +21 -0
  52. package/package.json +23 -15
  53. package/cli/commands/generate/README.md/package.json +0 -6
  54. package/dist/_internal/types/options.d.ts +0 -15
  55. package/dist/_internal/types/settings.d.ts +0 -8
  56. package/dist/_internal/utils/settings.d.ts +0 -5
  57. /package/dist/_internal/types/{settings.js → configs/help.js} +0 -0
  58. /package/dist/_internal/types/{options.js → configs.js} +0 -0
package/README.md CHANGED
@@ -2,19 +2,34 @@
2
2
 
3
3
  # MD HOPPER
4
4
 
5
- This Package Link md files in same repository.
5
+ md-hopper is a tool that recursively processes README.md files, starting from a specified README.md file and adding links to other README.md files nested within its directories to the parent README.md file.
6
+ This helps consolidate dispersed README files into a single, easily manageable document.
6
7
 
7
- # Commands
8
+ ## Installation
9
+
10
+ ```bash
11
+ $ npm i -g md-hopper
12
+ ```
13
+
14
+ or
15
+
16
+ ```bash
17
+ $ npm i md-hopper
18
+ ```
19
+
20
+ ## Commands
8
21
 
9
22
  <!-- MD_HOPPER: LINK_NEXT_LINE:
10
- id: generate-command
23
+ id: link-command
11
24
  inline: true
12
25
  -->
13
26
 
14
- - [generate][md_hopper:generate-command]
27
+ ### [LINK][md_hopper:link-command]
28
+
29
+ <!-- MD_HOPPER: BEFORE_GENERATE_LINK (6/4/2024, 10:23:14 AM): - [generate][md_hopper:generate-command] -->
15
30
 
16
31
  <!-- MD_HOPPER: BEGIN_DEFINE_LINKS: -->
17
32
 
18
- [md_hopper:generate-command]: ./src/cli/commands/generate/README.md 'GENERATE COMMAND'
33
+ [md_hopper:link-command]: ./src/cli/commands/link/README.md 'LINK COMMAND'
19
34
 
20
35
  <!-- MD_HOPPER: END_DEFINE_LINKS: -->
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@cilly/md-hopper-cli-commands-generate-actions-link",
3
+ "types": "../../../../../dist/cli/commands/generate/actions/link.d.ts",
4
+ "main": "../../../../../dist/cli/commands/generate/actions/link.js",
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@cilly/md-hopper-cli-commands-generate-actions-rc",
3
+ "types": "../../../../../dist/cli/commands/generate/actions/rc.d.ts",
4
+ "main": "../../../../../dist/cli/commands/generate/actions/rc.js",
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@cilly/md-hopper-cli-commands-link-README.md",
3
+ "types": "../../../../dist/cli/commands/link/README.md.d.ts",
4
+ "main": "../../../../dist/cli/commands/link/README.md.js",
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@cilly/md-hopper-cli-commands-link-action",
3
+ "types": "../../../../dist/cli/commands/link/action.d.ts",
4
+ "main": "../../../../dist/cli/commands/link/action.js",
5
+ "sideEffects": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@cilly/md-hopper-cli-commands-link-command",
3
+ "types": "../../../../dist/cli/commands/link/command.d.ts",
4
+ "main": "../../../../dist/cli/commands/link/command.js",
5
+ "sideEffects": false
6
+ }
@@ -1,11 +1,9 @@
1
- import { Options, DefaultOptions } from './options.js';
2
- import { Settings } from './settings.js';
3
1
  export type Action = (...args: any[]) => any;
4
2
  export interface BeforeFunction {
5
3
  fn: Action;
6
4
  args: any[];
7
5
  }
8
- export interface ActionArg<T extends DefaultOptions> {
9
- options: Options<T>;
10
- settings: Settings;
6
+ export interface ActionArg<CommandOptions extends Record<string, any>, MdSettings extends Record<string, any>> {
7
+ options: CommandOptions;
8
+ settings: MdSettings;
11
9
  }
@@ -0,0 +1,46 @@
1
+ import { DistinctQuestion } from 'inquirer';
2
+ export declare const TYPES: {
3
+ readonly rc: "rc";
4
+ readonly link: "link";
5
+ };
6
+ export type Type = (typeof TYPES)[keyof typeof TYPES];
7
+ export interface CommandOptions {
8
+ debug?: boolean;
9
+ type?: Type;
10
+ include?: string;
11
+ exclude?: string;
12
+ filenames?: string;
13
+ input?: string;
14
+ output?: string;
15
+ idGen?: GenerateType;
16
+ depth?: number;
17
+ id?: string;
18
+ lock?: boolean;
19
+ skipHidden?: boolean;
20
+ title?: string;
21
+ }
22
+ export interface MdSettings {
23
+ include: string[];
24
+ exclude: string[];
25
+ filenames: string[];
26
+ skipHidden: boolean;
27
+ input: string;
28
+ output: string;
29
+ idGen: GenerateType;
30
+ id: string;
31
+ title: string;
32
+ lock: boolean;
33
+ depth: number;
34
+ }
35
+ export declare const RC_QUESTIONS: (_options: CommandOptions) => ReadonlyArray<DistinctQuestion>;
36
+ export declare const GENERATE_TYPES: Readonly<{
37
+ readonly path: "path";
38
+ readonly random: "random";
39
+ readonly manual: "manual";
40
+ }>;
41
+ export type GenerateType = (typeof GENERATE_TYPES)[keyof typeof GENERATE_TYPES];
42
+ export declare const LINK_QUESTIONS: (options: CommandOptions) => ReadonlyArray<DistinctQuestion>;
43
+ export declare const QUESTIONS: (options: CommandOptions) => {
44
+ rc: readonly DistinctQuestion[];
45
+ link: readonly DistinctQuestion[];
46
+ };
@@ -0,0 +1,131 @@
1
+ import { isNumber } from 'my-gadgetry/type-check';
2
+ import { DEFAULT_MD_FILENAME } from '../../utils/configs.js';
3
+ import { isDirectory } from '../../utils/path.js';
4
+ export const TYPES = {
5
+ rc: 'rc',
6
+ link: 'link',
7
+ };
8
+ const INPUT_QUESTION = {
9
+ type: 'input',
10
+ name: 'input',
11
+ message: 'Please put path from current dir with filename? ex: "./{path}/{filename}.md"',
12
+ };
13
+ const SKIP_HIDDEN_QUESTION = {
14
+ type: 'confirm',
15
+ name: 'skipHidden',
16
+ message: 'skip search hidden file? default Yes.',
17
+ default: true,
18
+ };
19
+ const INCLUDE_QUESTION = {
20
+ type: 'input',
21
+ name: 'include',
22
+ message: 'include pattern minimatch list with comma. ex: xxx,xxx',
23
+ default: '',
24
+ };
25
+ const EXCLUDE_QUESTION = {
26
+ type: 'input',
27
+ name: 'exclude',
28
+ message: 'exclude pattern minimatch list with comma. ex: xxx,xxx',
29
+ default: '',
30
+ };
31
+ const FILENAMES_QUESTION = {
32
+ type: 'input',
33
+ name: 'filenames',
34
+ message: 'search filenames with comma. (default: README.md) ex: README.md,CHANGELOG.md',
35
+ default: DEFAULT_MD_FILENAME,
36
+ };
37
+ const OUTPUT_QUESTION = {
38
+ type: 'input',
39
+ name: 'output',
40
+ message: 'output filename. (default: same name as read, means update file) ex: README_GENERATE.md',
41
+ };
42
+ const DEPTH_QUESTION = {
43
+ type: 'number',
44
+ name: 'depth',
45
+ message: 'search depth number. more than 0. (if all put 0)',
46
+ validate: input => {
47
+ return isNumber(input, true) && input >= 0;
48
+ },
49
+ filter: input => {
50
+ return input >= 0 ? Number(input) : '';
51
+ },
52
+ default: 0,
53
+ };
54
+ export const RC_QUESTIONS = (_options) => [
55
+ {
56
+ ...INPUT_QUESTION,
57
+ validate: input => {
58
+ return !!input;
59
+ },
60
+ },
61
+ SKIP_HIDDEN_QUESTION,
62
+ INCLUDE_QUESTION,
63
+ EXCLUDE_QUESTION,
64
+ FILENAMES_QUESTION,
65
+ OUTPUT_QUESTION,
66
+ DEPTH_QUESTION,
67
+ ];
68
+ export const GENERATE_TYPES = Object.freeze({
69
+ path: 'path',
70
+ random: 'random',
71
+ manual: 'manual',
72
+ });
73
+ const GENERATE_TYPE_CHOICES = Object.freeze([
74
+ { name: 'auto generate with directory path', short: 'dir path', value: GENERATE_TYPES.path },
75
+ { name: 'auto generate with uuid', short: 'random', value: GENERATE_TYPES.random },
76
+ { name: 'generate yourself', short: 'manually', value: GENERATE_TYPES.manual },
77
+ ]);
78
+ const DIR_QUESTIONS = (options) => [SKIP_HIDDEN_QUESTION, INCLUDE_QUESTION, EXCLUDE_QUESTION, FILENAMES_QUESTION, DEPTH_QUESTION].map(QUESTION => ({
79
+ ...QUESTION,
80
+ when: (answers) => isDirectory(answers.input || options.input || ''),
81
+ }));
82
+ const FILE_QUESTIONS = (options) => [
83
+ {
84
+ type: 'input',
85
+ name: 'title',
86
+ message: 'title name. (default: auto detect title)',
87
+ },
88
+ {
89
+ type: 'confirm',
90
+ name: 'lock',
91
+ message: 'is locked? if true not link this file. (default: false)',
92
+ default: false,
93
+ },
94
+ OUTPUT_QUESTION,
95
+ ].map(QUESTION => ({ ...QUESTION, when: (answers) => !isDirectory(answers.input || options.input || '') }));
96
+ export const LINK_QUESTIONS = (options) => [
97
+ {
98
+ ...INPUT_QUESTION,
99
+ message: 'Please put path from current dir with filename? (default: ".") ex: "./{path}/{filename}.md"',
100
+ default: '.',
101
+ },
102
+ {
103
+ type: 'list',
104
+ name: 'idGen',
105
+ message: `Choose generate type (default: ${GENERATE_TYPE_CHOICES[0].short})`,
106
+ choices: answers => {
107
+ if (isDirectory(answers.input || options.input || '')) {
108
+ return GENERATE_TYPE_CHOICES.filter(({ value }) => [GENERATE_TYPES.path, GENERATE_TYPES.random].includes(value));
109
+ }
110
+ return GENERATE_TYPE_CHOICES;
111
+ },
112
+ default: 0,
113
+ },
114
+ {
115
+ type: 'input',
116
+ name: 'id',
117
+ message: 'type id',
118
+ validate: input => {
119
+ return !!input;
120
+ },
121
+ when: answers => {
122
+ return answers.idGen === GENERATE_TYPES.manual;
123
+ },
124
+ },
125
+ ...DIR_QUESTIONS(options),
126
+ ...FILE_QUESTIONS(options),
127
+ ];
128
+ export const QUESTIONS = (options) => ({
129
+ [TYPES.rc]: RC_QUESTIONS(options),
130
+ [TYPES.link]: LINK_QUESTIONS(options),
131
+ });
@@ -0,0 +1,2 @@
1
+ export type CommandOptions = Record<never, never>;
2
+ export type MdSettings = Record<never, never>;
@@ -0,0 +1,19 @@
1
+ export interface CommandOptions {
2
+ debug?: boolean;
3
+ skipHidden?: boolean;
4
+ include?: string;
5
+ exclude?: string;
6
+ filenames?: string;
7
+ input?: string;
8
+ output?: string;
9
+ depth?: string;
10
+ }
11
+ export interface MdSettings {
12
+ ['skip-hidden']: boolean;
13
+ include: string[];
14
+ exclude: string[];
15
+ filenames: string[];
16
+ input: string;
17
+ output: string;
18
+ depth: number;
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export interface CommandOptions {
2
+ [key: string]: any;
3
+ }
@@ -7,13 +7,15 @@ export declare const PROPERTIES: {
7
7
  END_DEFINE_LINKS: string;
8
8
  BEFORE_GENERATE_LINK: string;
9
9
  };
10
- export interface PathInfo {
10
+ export interface MdAttributes {
11
11
  id: string;
12
12
  lock: boolean;
13
13
  title: string;
14
+ output: string;
15
+ }
16
+ export interface PathInfo extends MdAttributes {
14
17
  path: string;
15
18
  dir: string;
16
- output: string;
17
19
  outputPath: string;
18
20
  }
19
21
  export interface PathDepthClassify {
@@ -46,3 +48,4 @@ export declare const MD_HOPPER_COMMENT_PREFIX_REG_EXP: RegExp;
46
48
  export declare const MD_HOPPER_PARAMS_REG_EXP: RegExp;
47
49
  export declare const MD_HOPPER_CONTENT_REG_EXP: RegExp;
48
50
  export declare const MD_HOPPER_PROPERTY_REG_EXP: RegExp;
51
+ export declare const getParamExp: (param: string) => RegExp;
@@ -19,3 +19,4 @@ export const MD_HOPPER_COMMENT_PREFIX_REG_EXP = new RegExp(`${BEGIN_COMMENT}\\s*
19
19
  export const MD_HOPPER_PARAMS_REG_EXP = new RegExp(`^[^${PARAM_SEPARATOR}]+${PARAM_SEPARATOR}(.*?)${END_COMMENT}.*`, 's');
20
20
  export const MD_HOPPER_CONTENT_REG_EXP = new RegExp(`^[^${PARAM_SEPARATOR}]+${PARAM_SEPARATOR}.*${END_COMMENT}(.*)`, 's');
21
21
  export const MD_HOPPER_PROPERTY_REG_EXP = new RegExp(`^([^${PARAM_SEPARATOR}]+?)${PARAM_SEPARATOR}.*`, 's');
22
+ export const getParamExp = (param) => new RegExp(`${BEGIN_COMMENT}\\s*${MD_HOPPER_COMMENT_PREFIX}\\s*${PARAM_SEPARATOR}\\s*${param}\\s*${PARAM_SEPARATOR}.*?${END_COMMENT}\\n*`, 'gs');
@@ -0,0 +1,7 @@
1
+ export declare const success: import("chalk").ChalkInstance;
2
+ export declare const warn: import("chalk").ChalkInstance;
3
+ export declare const info: import("chalk").ChalkInstance;
4
+ export declare const error: import("chalk").ChalkInstance;
5
+ export declare const hop: import("chalk").ChalkInstance;
6
+ export declare const cyan: import("chalk").ChalkInstance;
7
+ export declare const bold: import("chalk").ChalkInstance;
@@ -0,0 +1,8 @@
1
+ import chalk from 'chalk';
2
+ export const success = chalk.green;
3
+ export const warn = chalk.hex('#FFA500');
4
+ export const info = chalk.hex('#77CFF5');
5
+ export const error = chalk.red;
6
+ export const hop = chalk.hex('#F577F5');
7
+ export const cyan = chalk.cyan;
8
+ export const bold = chalk.bold;
@@ -1,18 +1,20 @@
1
1
  import { Command as Program } from 'commander';
2
- import { Action, ActionArg } from '../types/command.js';
3
- import { DefaultOptions } from '../types/options.js';
4
- import { Settings } from '../types/settings.js';
5
- export declare class CommandClass<T extends DefaultOptions> {
2
+ import { Action } from '../types/command.js';
3
+ type SettingsFnc<CommandOptions extends Record<string, any>, MdSettings extends Record<string, any>> = (options: CommandOptions) => MdSettings;
4
+ export declare class CommandClass<CommandOptions extends Record<string, any>, MdSettings extends Record<string, any>> {
6
5
  program: Program;
7
6
  private befores;
8
7
  private args;
9
- constructor(program: Program);
10
- init(options: ActionArg<T>['options'], settings: Settings): Promise<this>;
8
+ private getSettingFnc;
9
+ constructor(program: Program, getSettingFnc: SettingsFnc<CommandOptions, MdSettings>);
10
+ init(options: CommandOptions, settings: MdSettings): this;
11
11
  command(command: string): this;
12
- help(helpTxt: string): CommandClass<T>;
13
- before(before: Action, ...args: any[]): CommandClass<T>;
14
- description(description: string): CommandClass<T>;
15
- option(...args: any[]): CommandClass<T>;
16
- requiredOption(...args: any[]): CommandClass<T>;
12
+ help(helpTxt: string): this;
13
+ before(before: Action, ...args: any[]): this;
14
+ description(description: string): this;
15
+ option(...args: any[]): this;
16
+ requiredOption(...args: any[]): this;
17
17
  action(action: Action): void;
18
18
  }
19
+ export declare const setCommands: <CommandOptions extends Record<string, any>, MdSettings extends Record<string, any>>(program: Program, commands: string[], initFnc: (commandClass: CommandClass<CommandOptions, MdSettings>) => void, getSettingFnc: SettingsFnc<CommandOptions, MdSettings>) => void;
20
+ export {};
@@ -1,12 +1,13 @@
1
- import { getSettings } from './settings.js';
2
1
  export class CommandClass {
3
2
  program;
4
3
  befores = [];
5
4
  args;
6
- constructor(program) {
5
+ getSettingFnc;
6
+ constructor(program, getSettingFnc) {
7
7
  this.program = program;
8
+ this.getSettingFnc = getSettingFnc;
8
9
  }
9
- async init(options, settings) {
10
+ init(options, settings) {
10
11
  this.args = {
11
12
  options,
12
13
  settings,
@@ -45,7 +46,7 @@ export class CommandClass {
45
46
  action(action) {
46
47
  this.program = this.program.action(async (...args) => {
47
48
  const options = args[0];
48
- await this.init(options, getSettings(options.input || ''));
49
+ await this.init(options, this.getSettingFnc(options));
49
50
  for (const before of this.befores) {
50
51
  await before.fn(options, ...before.args);
51
52
  }
@@ -53,3 +54,8 @@ export class CommandClass {
53
54
  });
54
55
  }
55
56
  }
57
+ export const setCommands = (program, commands, initFnc, getSettingFnc) => {
58
+ for (const command of commands) {
59
+ initFnc(new CommandClass(program, getSettingFnc).command(command));
60
+ }
61
+ };
@@ -1,3 +1,4 @@
1
- export declare const SETTING_FILE_NAME = "README.md";
1
+ export declare const DEFAULT_MD_FILENAME = "README.md";
2
+ export declare const SETTING_FILENAME = "README.md";
2
3
  export declare const importLineRegExp: RegExp;
3
4
  export declare const indentRegExp: RegExp;
@@ -1,3 +1,4 @@
1
- export const SETTING_FILE_NAME = 'README.md';
1
+ export const DEFAULT_MD_FILENAME = 'README.md';
2
+ export const SETTING_FILENAME = DEFAULT_MD_FILENAME;
2
3
  export const importLineRegExp = new RegExp(/\s*\/\/\s*@import\s+(\S+).*/g);
3
4
  export const indentRegExp = new RegExp(/^(\s*).*/);
@@ -1 +1,5 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  export { getAllFiles } from 'my-gadgetry/fs';
3
+ export declare const readJsonFileSync: (path: string, encode?: BufferEncoding) => {};
4
+ export declare const isDirectory: (path: string) => boolean;
5
+ export declare const getAllMdFiles: (filenames: string[], startDir: string, _options?: import("my-gadgetry/fs").Options | undefined) => string[];
@@ -1 +1,18 @@
1
+ import { readFileSync, statSync, existsSync } from 'fs';
2
+ import { getAllFiles } from 'my-gadgetry/fs';
3
+ import { isJson } from 'my-gadgetry/type-check';
1
4
  export { getAllFiles } from 'my-gadgetry/fs';
5
+ export const readJsonFileSync = (path, encode = 'utf-8') => {
6
+ const json = isJson(readFileSync(path, encode));
7
+ if (!json) {
8
+ return {};
9
+ }
10
+ return json;
11
+ };
12
+ export const isDirectory = (path) => {
13
+ if (!existsSync(path)) {
14
+ throw new Error('not exists');
15
+ }
16
+ return statSync(path).isDirectory();
17
+ };
18
+ export const getAllMdFiles = (filenames, ...args) => getAllFiles(...args).filter(path => filenames.some(filename => path.endsWith(`/${filename}`)));
@@ -0,0 +1,4 @@
1
+ import { MdSettings } from '../types/configs/links.js';
2
+ export declare const DEFAULT_SETTINGS: MdSettings;
3
+ export declare const parse: (txt: string) => MdSettings;
4
+ export declare const getSettings: (inputFilename: string) => MdSettings;
@@ -1,16 +1,18 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { getParam } from './md.js';
3
- import { SETTING_FILE_NAME } from './configs.js';
4
- import { getProjectRootPath } from './path.js';
5
- const Booleans = ['skip-hidden'];
6
- const Strings = ['exclude', 'include', 'filenames'];
7
- export const DEFAULT_MD_FILE_NAME = 'README.md';
3
+ import { SETTING_FILENAME, DEFAULT_MD_FILENAME } from './configs.js';
4
+ import { getExecDir } from './path.js';
5
+ const BOOLEANS = ['skip-hidden'];
6
+ const STRINGS = ['exclude', 'include', 'filenames'];
7
+ const NUMBERS = ['depth'];
8
8
  export const DEFAULT_SETTINGS = Object.freeze({
9
9
  'skip-hidden': true,
10
10
  exclude: [],
11
11
  include: [],
12
- filenames: [DEFAULT_MD_FILE_NAME],
13
- output: DEFAULT_MD_FILE_NAME,
12
+ filenames: [DEFAULT_MD_FILENAME],
13
+ output: DEFAULT_MD_FILENAME,
14
+ input: '.',
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 (Booleans.includes(key)) {
28
+ if (BOOLEANS.includes(key)) {
27
29
  val = JSON.parse(`${value}`);
28
30
  }
29
- else if (Strings.includes(key)) {
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(`${getProjectRootPath()}/${inputFilename || SETTING_FILE_NAME}`, 'utf-8');
48
+ const readme = readFileSync(`${getExecDir()}/${inputFilename || SETTING_FILENAME}`, 'utf-8');
44
49
  return parse(getParam(readme, 'CONFIG'));
45
50
  };
@@ -2,3 +2,4 @@ export declare const success: (...args: any[]) => void;
2
2
  export declare const warn: (...args: any[]) => void;
3
3
  export declare const info: (...args: any[]) => void;
4
4
  export declare const error: (...args: any[]) => void;
5
+ export declare const hop: (...args: any[]) => void;
@@ -1,13 +1,16 @@
1
- import chalk from 'chalk';
1
+ import * as chalk from './chalk.js';
2
2
  export const success = (...args) => {
3
- console.log(chalk.green(...args));
3
+ console.log(chalk.success(...args));
4
4
  };
5
5
  export const warn = (...args) => {
6
- console.log(chalk.hex('#FFA500')(...args));
6
+ console.log(chalk.warn(...args));
7
7
  };
8
8
  export const info = (...args) => {
9
- console.log(chalk.blue(...args));
9
+ console.log(chalk.info(...args));
10
10
  };
11
11
  export const error = (...args) => {
12
- console.log(chalk.red(...args));
12
+ console.log(chalk.error(...args));
13
+ };
14
+ export const hop = (...args) => {
15
+ console.log(chalk.hop(...args));
13
16
  };
@@ -1,4 +1,11 @@
1
- import { Detail } from '../types/md.js';
1
+ import { MdAttributes, Detail } from '../types/md.js';
2
2
  export declare const getParam: (txt: string, key: string) => string;
3
+ export declare const getParamComment: (param: string, value: string) => string;
4
+ export declare const getKeyValues: (keyValues: Record<string, string | number | boolean>) => string;
5
+ type CommentParams = Record<string, string | number | boolean>;
6
+ export declare const getParamsComment: <T extends CommentParams = CommentParams>(keyValues: T) => string;
7
+ export declare const removeParam: (md: string, param: string) => string;
3
8
  export declare const getTitle: (txt: string) => string;
4
9
  export declare const replace: (detail: Detail, details: Detail[]) => string;
10
+ export declare const getLinkedMdDetail: (md: string) => MdAttributes;
11
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from 'fs';
2
- import { PROPERTIES, LINK_NAME_PREFIX, COMMENT_REG_EXP, PARAM_SEPARATOR, LINK_REG_EXP, MD_HOPPER_COMMENT_PREFIX, MD_HOPPER_COMMENT_PREFIX_REG_EXP, MD_HOPPER_PROPERTY_REG_EXP, MD_HOPPER_PARAMS_REG_EXP, BRAKE_LINE_REG_EXP, MD_HOPPER_CONTENT_REG_EXP, BEGIN_COMMENT, END_COMMENT, } from '../types/md.js';
2
+ import { PROPERTIES, LINK_NAME_PREFIX, COMMENT_REG_EXP, PARAM_SEPARATOR, LINK_REG_EXP, MD_HOPPER_COMMENT_PREFIX, MD_HOPPER_COMMENT_PREFIX_REG_EXP, MD_HOPPER_PROPERTY_REG_EXP, MD_HOPPER_PARAMS_REG_EXP, BRAKE_LINE_REG_EXP, MD_HOPPER_CONTENT_REG_EXP, BEGIN_COMMENT, END_COMMENT, getParamExp, } from '../types/md.js';
3
3
  import { replaceLineToLink } from './md/line.js';
4
4
  import { getRelative } from './path.js';
5
5
  import { isBoolean } from './type-check.js';
@@ -11,6 +11,17 @@ export const getParam = (txt, key) => {
11
11
  }
12
12
  return reg.exec(txt)[1];
13
13
  };
14
+ export const getParamComment = (param, value) => `${BEGIN_COMMENT} ${MD_HOPPER_COMMENT_PREFIX}${PARAM_SEPARATOR} ${param}${PARAM_SEPARATOR} ${value} ${END_COMMENT}`;
15
+ export const getKeyValues = (keyValues) => {
16
+ const arr = Object.entries(keyValues);
17
+ const txt = arr.map(([key, value]) => `${key}${PARAM_SEPARATOR} ${value}`).join('\n');
18
+ const prefixSuffix = arr.length >= 2 ? '\n' : '';
19
+ return `${prefixSuffix}${txt}${prefixSuffix}`;
20
+ };
21
+ export const getParamsComment = (keyValues) => `${BEGIN_COMMENT} ${MD_HOPPER_COMMENT_PREFIX}${PARAM_SEPARATOR} ${getKeyValues(keyValues)} ${END_COMMENT}`;
22
+ export const removeParam = (md, param) => {
23
+ return md.replace(getParamExp(param), '');
24
+ };
14
25
  const getRemovedComment = (txt) => txt.replace(COMMENT_REG_EXP, '');
15
26
  const getFirstLine = (txt) => {
16
27
  const lines = txt.split('\n').filter(line => line.trim().length);
@@ -22,7 +33,9 @@ export const getTitle = (txt) => {
22
33
  return title;
23
34
  }
24
35
  const md = getRemovedComment(txt);
25
- return md.replace(/\r?\n?#+(.*?)\r?\n.*/s, '$1').trim() || getFirstLine(md);
36
+ const lines = md.split('\n').filter(line => /^#+\s*./.test(line));
37
+ const str = lines.length >= 1 ? lines[0].trim().replace(/^\s*#+\s*(.+)$/, '$1') : getFirstLine(md);
38
+ return str.replace(/[[\]():]/g, '');
26
39
  };
27
40
  const getLinkName = (id) => `${LINK_NAME_PREFIX}${id}`;
28
41
  const getLink = (id, title) => `[${title}][${getLinkName(id)}]`;
@@ -221,3 +234,15 @@ export const replace = (detail, details) => {
221
234
  }
222
235
  return sections.join(`${BEGIN_COMMENT} ${MD_HOPPER_COMMENT_PREFIX}${PARAM_SEPARATOR} `);
223
236
  };
237
+ export const getLinkedMdDetail = (md) => {
238
+ const id = getParam(md, 'ID').trim();
239
+ const LOCK = getParam(md, 'LOCK').trim();
240
+ const lock = LOCK ? JSON.parse(LOCK) : false;
241
+ const output = getParam(md, 'OUTPUT').trim();
242
+ return {
243
+ id,
244
+ lock,
245
+ title: (getTitle(md) || id).trim(),
246
+ output,
247
+ };
248
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getExclude: (basePath: string, excludes: string[], skipHidden: boolean) => string[];
2
+ export declare const getInclude: (basePath: string, includes: string[]) => string[];
@@ -0,0 +1,13 @@
1
+ import { join } from 'path';
2
+ const replacePath = (str) => str.replace(/\/{2,}/, '/');
3
+ export const getExclude = (basePath, excludes, skipHidden) => {
4
+ return [
5
+ '**/node_modules/.*/*',
6
+ '**/node_modules/**/*',
7
+ ...(skipHidden ? ['**/.*/**/*', '**/.*'] : []),
8
+ ...excludes.map(path => replacePath(join(basePath, path))),
9
+ ];
10
+ };
11
+ export const getInclude = (basePath, includes) => {
12
+ return includes.map(path => replacePath(join(basePath, path)));
13
+ };
@@ -1,6 +1,8 @@
1
- export declare const getProjectRootPath: () => string;
2
- export declare const getFullPath: (...path: string[]) => string;
3
- export declare const getDir: (path: string) => string;
1
+ export declare const isDirectory: (path: string) => boolean;
2
+ export declare const getExecDir: () => string;
3
+ export declare const getParseDirPath: (path: string) => string;
4
+ export declare const getParentDirname: (path: string) => string | undefined;
5
+ export declare const getCommands: (path: string, start?: number, end?: number) => string[];
4
6
  export declare const DEPTH_TYPES: {
5
7
  ancestor: string;
6
8
  parent: string;