juisy 2.0.0-beta.0 → 2.0.0-beta.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.
- package/LICENSE +661 -0
- package/bin/cli/cli.js +6 -4
- package/bin/cli/cmds/index.js +10 -10
- package/bin/cli/cmds/private/docs/generate-api.js +31 -0
- package/bin/cli/cmds/{docs → private/docs}/index.js +4 -6
- package/bin/cli/cmds/{print-globals.js → public/print-globals.js} +0 -1
- package/bin/cli/index.js +1 -1
- package/bin/scripts/prepare.js +22 -0
- package/dist/DataExporter.d.ts +6 -0
- package/dist/cli/CLIFactory.d.ts +48 -11
- package/dist/cli/Command.d.ts +23 -13
- package/dist/cli/GlobalSettings.schema.json +1 -0
- package/dist/cli/InterfaceUtils.d.ts +8 -2
- package/dist/cli/OutputUtils.d.ts +3 -3
- package/dist/cli/Plugin.d.ts +21 -0
- package/dist/cli/extract-usage.d.ts +7 -1
- package/dist/cli/index.d.ts +18 -6
- package/dist/cli/index.js +1252 -129
- package/dist/cli/plugins/command-handler-injections/augment.d.ts +29 -0
- package/dist/cli/{command-visitors → plugins/command-handler-injections/command-visitors}/command-handler-injections.d.ts +1 -1
- package/dist/cli/plugins/command-handler-injections/index.d.ts +3 -0
- package/dist/cli/plugins/command-meta/augment.d.ts +23 -0
- package/dist/cli/{command-visitors/get-command-meta.d.ts → plugins/command-meta/command-visitors/command-meta.d.ts} +1 -1
- package/dist/cli/plugins/command-meta/index.d.ts +3 -0
- package/dist/cli/plugins/default-command-fallbacks/augment.d.ts +3 -0
- package/dist/cli/plugins/default-command-fallbacks/command-visitors/default-command-fallbacks.d.ts +10 -0
- package/dist/cli/plugins/default-command-fallbacks/index.d.ts +3 -0
- package/dist/cli/plugins/load-env-file/augment.d.ts +9 -0
- package/dist/cli/plugins/load-env-file/index.d.ts +3 -0
- package/dist/cli/plugins/private-commands/augment.d.ts +6 -0
- package/dist/cli/{command-visitors → plugins/private-commands/command-visitors}/private-command.d.ts +1 -1
- package/dist/cli/plugins/private-commands/index.d.ts +3 -0
- package/dist/cli/plugins/register-bump-version-command/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-bump-version-command/index.d.ts +3 -0
- package/dist/cli/plugins/register-changelog-command/augment.d.ts +110 -0
- package/dist/cli/plugins/register-changelog-command/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-changelog-command/index.d.ts +3 -0
- package/dist/cli/plugins/register-docs-commands/augment.d.ts +18 -0
- package/dist/cli/plugins/register-docs-commands/cmds/generate-api.d.ts +3 -0
- package/dist/cli/plugins/register-docs-commands/cmds/generate-cli.d.ts +3 -0
- package/dist/cli/plugins/register-docs-commands/cmds/generate-readme.d.ts +3 -0
- package/dist/cli/plugins/register-docs-commands/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-docs-commands/index.d.ts +3 -0
- package/dist/cli/plugins/register-git-hooks-commands/augment.d.ts +40 -0
- package/dist/cli/plugins/register-git-hooks-commands/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-git-hooks-commands/cmds/reset.d.ts +3 -0
- package/dist/cli/plugins/register-git-hooks-commands/cmds/sync.d.ts +3 -0
- package/dist/cli/plugins/register-git-hooks-commands/index.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/augment.d.ts +39 -0
- package/dist/cli/plugins/register-lint-commands/cmds/commit.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/cmds/default.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/cmds/markdown.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/cmds/staged.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/index.d.ts +3 -0
- package/dist/cli/plugins/register-lint-commands/settings.d.ts +11 -0
- package/dist/cli/plugins/register-lint-commands/types.d.ts +26 -0
- package/dist/cli/plugins/register-release-command/augment.d.ts +9 -0
- package/dist/cli/plugins/register-release-command/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-release-command/index.d.ts +3 -0
- package/dist/cli/plugins/register-test-command/cmds/index.d.ts +3 -0
- package/dist/cli/plugins/register-test-command/index.d.ts +3 -0
- package/dist/cli/types.d.ts +73 -44
- package/dist/cli/utils.d.ts +3 -3
- package/dist/eject.d.ts +11 -4
- package/dist/index.d.ts +8 -2
- package/dist/index.js +80 -76
- package/dist/project-globals.d.ts +9 -0
- package/dist/templater/index.d.ts +6 -1
- package/dist/templater/index.js +18 -31
- package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +28 -28
- package/dist/templater/markdown-templater/index.d.ts +3 -0
- package/dist/templater/types.d.ts +6 -0
- package/dist/utils/misc.d.ts +1 -1
- package/package.json +201 -179
- package/README.md +0 -211
- package/bin/cli/cmds/changelog.js +0 -41
- package/bin/cli/cmds/docs/generate-api.js +0 -22
- package/bin/cli/cmds/docs/generate-cli.js +0 -11
- package/bin/cli/cmds/docs/generate-readme.js +0 -11
- package/bin/cli/cmds/docs/lint.js +0 -42
- package/bin/cli/cmds/eject.js +0 -28
- package/bin/cli/cmds/git-hooks/index.js +0 -20
- package/bin/cli/cmds/git-hooks/reset.js +0 -48
- package/bin/cli/cmds/git-hooks/sync.js +0 -19
- package/bin/cli/cmds/release.js +0 -231
- package/bin/cli/lib/docs/generate-api-doc.js +0 -78
- package/bin/cli/lib/version/update-version.js +0 -52
- package/bin/scripts/commit-msg.js +0 -32
- package/bin/scripts/pre-commit.js +0 -24
- package/dist/cli/command-visitors/index.d.ts +0 -9
- package/src/index.js +0 -507
- package/template/CHANGELOG.md +0 -0
- package/template/bin/cli/cli.js +0 -27
- package/template/bin/cli/cmds/changelog.js +0 -71
- package/template/bin/cli/cmds/docs.js +0 -30
- package/template/bin/cli/cmds/docs_cmds/generate-api.js +0 -75
- package/template/bin/cli/cmds/docs_cmds/generate-readme.js +0 -51
- package/template/bin/cli/cmds/git-hooks.js +0 -30
- package/template/bin/cli/cmds/git_hooks_cmds/reset.js +0 -76
- package/template/bin/cli/cmds/git_hooks_cmds/sync.js +0 -44
- package/template/bin/cli/cmds/release.js +0 -219
- package/template/bin/cli/index.js +0 -7
- package/template/bin/cli/lib/docs/generate-api-doc.js +0 -33
- package/template/bin/cli/lib/release/generate-release-note.js +0 -3
- package/template/bin/cli/lib/version/update-version.js +0 -51
- package/template/bin/scripts/commit-msg.js +0 -42
- package/template/bin/scripts/pre-commit.js +0 -32
- package/template/docs/api/docs.config.js +0 -10
- package/template/docs/readme/config.js +0 -22
- package/template/docs/readme/readme.js +0 -70
- package/template/docs/readme/template.md +0 -53
- /package/bin/cli/cmds/{test.js → private/test.js} +0 -0
- /package/bin/cli/cmds/{squeeze.js → public/squeeze.js} +0 -0
package/dist/cli/types.d.ts
CHANGED
|
@@ -1,59 +1,84 @@
|
|
|
1
|
-
import { Argv, CommandModule as YargsCommandModule,
|
|
1
|
+
import { Argv, CommandModule as YargsCommandModule, MiddlewareFunction } from 'yargs';
|
|
2
|
+
import { Command } from './Command';
|
|
2
3
|
/**
|
|
3
4
|
* An object whose all properties have the same type.
|
|
4
5
|
*/
|
|
5
6
|
type Dictionary<T = any> = {
|
|
6
7
|
[key: string]: T;
|
|
7
8
|
};
|
|
9
|
+
/** ---------------------------- */
|
|
10
|
+
/**
|
|
11
|
+
* @group Types
|
|
12
|
+
*/
|
|
13
|
+
export type DefaultCommandObject = {
|
|
14
|
+
fullSignature: string;
|
|
15
|
+
commandObject: Command;
|
|
16
|
+
children?: Array<DefaultCommandObject>;
|
|
17
|
+
};
|
|
8
18
|
/**
|
|
9
|
-
*
|
|
19
|
+
* Provide a configuration object or an object with only "config" property
|
|
20
|
+
* @group Types
|
|
21
|
+
* @example
|
|
22
|
+
* {
|
|
23
|
+
* config: 'path/to/config/file'
|
|
24
|
+
* }
|
|
10
25
|
*/
|
|
11
|
-
type
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
export type UserProvidedConfigSetting<T> = {
|
|
27
|
+
/**
|
|
28
|
+
* The configuration file path
|
|
29
|
+
*/
|
|
30
|
+
config: string;
|
|
31
|
+
} | (T & {
|
|
32
|
+
config?: never;
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* CLI global settings
|
|
36
|
+
* @group Types
|
|
37
|
+
*/
|
|
38
|
+
export interface GlobalSettings {
|
|
39
|
+
[key: string]: any;
|
|
16
40
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The CLIFactory function options
|
|
43
|
+
* @group Types
|
|
44
|
+
*/
|
|
45
|
+
export interface CLIFactoryOptions {
|
|
46
|
+
/**
|
|
47
|
+
* The path to settings file
|
|
48
|
+
*/
|
|
49
|
+
settingsPath?: string;
|
|
26
50
|
}
|
|
27
|
-
/** ---------------------------- */
|
|
28
51
|
/**
|
|
29
52
|
* Our custon extended Yargs type
|
|
53
|
+
* @group Types
|
|
30
54
|
*/
|
|
31
55
|
export interface CLIEngine extends Argv {
|
|
32
56
|
_isPrivate: boolean;
|
|
33
57
|
_globalCommandVisitors: Record<string, CommandVisitor>;
|
|
34
58
|
_globalCommandVisitorsEnabled: Set<string>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
59
|
+
_disabledDefaultCommands: Set<string>;
|
|
60
|
+
_settings: Record<string, any>;
|
|
38
61
|
originalCommand: Argv['command'];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
62
|
+
disableDefaultCommand(signature: string): this;
|
|
63
|
+
hasDefaultCommand(signature: string): boolean;
|
|
64
|
+
globalCommandVisitor(name: string, visitor: CommandVisitor, defaultOptions: any): this;
|
|
65
|
+
globalCommandVisitorOptions(name: string, options: Record<any, any>): this;
|
|
66
|
+
hasGlobalCommandVisitor(name: string): boolean;
|
|
67
|
+
disableGlobalCommandVisitors(visitors: string[]): this;
|
|
68
|
+
enableGlobalCommandVisitors(visitors: string[]): this;
|
|
69
|
+
isPrivate(): this['_isPrivate'];
|
|
70
|
+
getSettings(path?: string): this['_settings'];
|
|
71
|
+
getDemandedCommands(): Dictionary<{
|
|
47
72
|
min: number;
|
|
48
73
|
max: number;
|
|
49
74
|
minMsg?: string | null;
|
|
50
75
|
maxMsg?: string | null;
|
|
51
76
|
}>;
|
|
52
|
-
getDemandedOptions
|
|
53
|
-
getDeprecatedOptions
|
|
54
|
-
getGroups
|
|
55
|
-
getOptions
|
|
56
|
-
getInternalMethods
|
|
77
|
+
getDemandedOptions(): Dictionary<string | undefined>;
|
|
78
|
+
getDeprecatedOptions(): Dictionary<string | boolean | undefined>;
|
|
79
|
+
getGroups(): Dictionary<string[]>;
|
|
80
|
+
getOptions(): Record<string, any>;
|
|
81
|
+
getInternalMethods(): {
|
|
57
82
|
getCommandInstance(): any;
|
|
58
83
|
getContext(): any;
|
|
59
84
|
getHasOutput(): boolean;
|
|
@@ -72,27 +97,31 @@ export interface CLIEngine extends Argv {
|
|
|
72
97
|
setHasOutput(): void;
|
|
73
98
|
};
|
|
74
99
|
}
|
|
75
|
-
|
|
100
|
+
/**
|
|
101
|
+
* @group Types
|
|
102
|
+
*/
|
|
103
|
+
export interface CommandObject {
|
|
76
104
|
/** array of strings (or a single string) representing aliases of `exports.command`, positional args defined in an alias are ignored */
|
|
77
|
-
aliases
|
|
105
|
+
aliases?: YargsCommandModule['aliases'];
|
|
78
106
|
/** string (or array of strings) that executes this command when given on the command line, first string may contain positional args */
|
|
79
107
|
command: YargsCommandModule['command'];
|
|
80
108
|
/** boolean (or string) to show deprecation notice */
|
|
81
|
-
deprecated
|
|
109
|
+
deprecated?: YargsCommandModule['deprecated'];
|
|
82
110
|
/** string used as the description for the command in help text, use `false` for a hidden command */
|
|
83
111
|
describe: YargsCommandModule['describe'];
|
|
84
112
|
/** a function which will be passed the parsed argv. */
|
|
85
|
-
handler:
|
|
86
|
-
engine?: CLIEngine;
|
|
87
|
-
log?: (msg?: string, options?: any) => void;
|
|
88
|
-
}, argv: Parameters<YargsCommandModule['handler']>[0]) => ReturnType<YargsCommandModule['handler']>;
|
|
113
|
+
handler: CommandHandler;
|
|
89
114
|
/** object declaring the options the command accepts, or a function accepting and returning a yargs instance */
|
|
90
115
|
builder: (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
|
|
91
|
-
|
|
92
|
-
}
|
|
116
|
+
middlewares?: MiddlewareFunction[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @group Types
|
|
120
|
+
*/
|
|
93
121
|
export type CLIBuilder = (cli: CLIEngine) => CLIEngine;
|
|
94
122
|
/**
|
|
95
123
|
* Custom global command visitor callback.
|
|
124
|
+
* @group Types
|
|
96
125
|
*/
|
|
97
126
|
export type CommandVisitor = {
|
|
98
127
|
options?: Record<any, any>;
|
|
@@ -100,7 +129,7 @@ export type CommandVisitor = {
|
|
|
100
129
|
/**
|
|
101
130
|
* The exported command object
|
|
102
131
|
*/
|
|
103
|
-
commandObject:
|
|
132
|
+
commandObject: CommandObject,
|
|
104
133
|
/**
|
|
105
134
|
* The current CLI instance
|
|
106
135
|
*/
|
|
@@ -108,5 +137,5 @@ engine: CLIEngine,
|
|
|
108
137
|
/**
|
|
109
138
|
* The default options to set
|
|
110
139
|
*/
|
|
111
|
-
options: any) => false |
|
|
140
|
+
options: any) => false | CommandObject);
|
|
112
141
|
export {};
|
package/dist/cli/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommandObject, CLIEngine, CommandHandler } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* @ignore
|
|
4
4
|
* @param target - The target builder
|
|
@@ -7,7 +7,7 @@ import { CommandModule, CLIEngine } from './types';
|
|
|
7
7
|
* Wrap command builder (target) with builder passed as second parameter
|
|
8
8
|
* that will be called before target. Target can be undefined
|
|
9
9
|
*/
|
|
10
|
-
export declare function wrapCommandBuilder(target:
|
|
10
|
+
export declare function wrapCommandBuilder(target: CommandObject['builder'], builder: (cli: CLIEngine) => CLIEngine): (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
|
|
11
11
|
/**
|
|
12
12
|
* @ignore
|
|
13
13
|
* @param target - The target handler
|
|
@@ -16,4 +16,4 @@ export declare function wrapCommandBuilder(target: CommandModule['builder'], bui
|
|
|
16
16
|
* Wrap command handler (target) with handler passed as second parameter
|
|
17
17
|
* that will be called before target. Target can be undefined
|
|
18
18
|
*/
|
|
19
|
-
export declare function wrapCommandhandler(target:
|
|
19
|
+
export declare function wrapCommandhandler(target: CommandHandler, handler: CommandHandler): CommandHandler;
|
package/dist/eject.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { LogLevelDesc } from 'loglevel';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @group Types
|
|
4
|
+
*/
|
|
5
|
+
export type EjectOptions = {
|
|
3
6
|
force?: boolean;
|
|
4
7
|
targetDir?: string;
|
|
5
8
|
logLevel?: LogLevelDesc;
|
|
9
|
+
ignoreFiles?: string[];
|
|
6
10
|
processor?: (content: string, identifier: string) => string | Promise<string>;
|
|
7
11
|
onError?: (identifier: string, fromPath: string, toPath: string, err: Error) => void | Promise<void>;
|
|
8
12
|
onSuccess?: (identifier: string, fromPath: string, toPath: string) => void | Promise<void>;
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
15
|
* Eject from file from template to user project
|
|
12
|
-
* @param identifier - The identifier of the file to eject (relative to
|
|
16
|
+
* @param identifier - The identifier of the file to eject (relative to templateDir folder). Can be a glob pattern (ex: `bin\/**\/*`).
|
|
13
17
|
* @param options - The options object
|
|
14
18
|
* @param options.force - If true, the target files will be overwritten
|
|
15
19
|
* @param options.targetDir - The target directory absolute path
|
|
@@ -18,5 +22,8 @@ type EjectOptions = {
|
|
|
18
22
|
* @param options.onError - The callback if an error occurs
|
|
19
23
|
* @param options.onSuccess - The callback in of success
|
|
20
24
|
*/
|
|
21
|
-
export default function eject(
|
|
22
|
-
|
|
25
|
+
export default function eject(
|
|
26
|
+
/**
|
|
27
|
+
* The absolute path to template directory. Default is juisy/template
|
|
28
|
+
*/
|
|
29
|
+
templateDir: string, identifier: string, options?: EjectOptions): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,14 @@
|
|
|
4
4
|
* @author Hervé Perchec
|
|
5
5
|
*/
|
|
6
6
|
import * as utils from './utils/misc';
|
|
7
|
+
export { DataExporter } from './DataExporter';
|
|
7
8
|
export { default as eject } from './eject';
|
|
8
|
-
export * from './DataExporter';
|
|
9
9
|
export { default as getPackageInfo } from './get-package-info';
|
|
10
|
-
export
|
|
10
|
+
export { defineGlobals, getProjectGlobals } from './project-globals';
|
|
11
|
+
/**
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
11
14
|
export { utils };
|
|
15
|
+
export type * from './DataExporter';
|
|
16
|
+
export type * from './eject';
|
|
17
|
+
export type * from './project-globals';
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy
|
|
2
|
+
* juisy v2.0.0-beta.10
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import path, { dirname } from 'node:path';
|
|
7
7
|
import { readdir, readFileSync } from 'node:fs';
|
|
8
8
|
import { glob } from 'glob';
|
|
9
|
+
import yaml from 'yaml';
|
|
10
|
+
import { json2csv } from 'json-2-csv';
|
|
11
|
+
import jstoxml from 'jstoxml';
|
|
9
12
|
import fs from 'fs-extra';
|
|
10
13
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
11
14
|
import { packageDirectorySync } from 'pkg-dir';
|
|
12
15
|
import log from 'loglevel';
|
|
13
16
|
import { Templater } from 'juisy/templater';
|
|
14
|
-
import yaml from 'yaml';
|
|
15
|
-
import { json2csv } from 'json-2-csv';
|
|
16
|
-
import jstoxml from 'jstoxml';
|
|
17
17
|
import dotenv from '@dotenvx/dotenvx';
|
|
18
18
|
import deepmerge from 'deepmerge';
|
|
19
19
|
|
|
@@ -39,8 +39,66 @@ const misc = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
|
|
39
39
|
getFiles
|
|
40
40
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
41
41
|
|
|
42
|
+
const xml = jstoxml.toXML;
|
|
43
|
+
const SUPPORTED_FORMATS = [
|
|
44
|
+
"json",
|
|
45
|
+
"yaml",
|
|
46
|
+
"csv",
|
|
47
|
+
"xml"
|
|
48
|
+
// 'bson',
|
|
49
|
+
// 'msgpack',
|
|
50
|
+
// 'protobuf',
|
|
51
|
+
// 'avro'
|
|
52
|
+
];
|
|
53
|
+
const jsonExporter = function(data, options = {}) {
|
|
54
|
+
return JSON.stringify(data, options.replacer, options.space);
|
|
55
|
+
};
|
|
56
|
+
const yamlExporter = function(data, options = {}) {
|
|
57
|
+
return yaml.stringify(data, options.replacer, options.exporter);
|
|
58
|
+
};
|
|
59
|
+
const csvExporter = function(data, options) {
|
|
60
|
+
return json2csv(data, options);
|
|
61
|
+
};
|
|
62
|
+
const xmlExporter = function(data, options) {
|
|
63
|
+
return xml(data, options);
|
|
64
|
+
};
|
|
65
|
+
class DataExporter {
|
|
66
|
+
/**
|
|
67
|
+
* The target format
|
|
68
|
+
*/
|
|
69
|
+
format;
|
|
70
|
+
/**
|
|
71
|
+
* Creates new instance of Costume
|
|
72
|
+
* @param options - Costume options
|
|
73
|
+
*/
|
|
74
|
+
constructor(format) {
|
|
75
|
+
if (SUPPORTED_FORMATS.includes(format)) {
|
|
76
|
+
this.format = format;
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error(`DataConverter: Unsupported "${format}" format`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exportSync(data, options) {
|
|
82
|
+
switch (this.format) {
|
|
83
|
+
case "json":
|
|
84
|
+
return jsonExporter(data, options);
|
|
85
|
+
case "yaml":
|
|
86
|
+
return yamlExporter(data, options);
|
|
87
|
+
case "csv":
|
|
88
|
+
return csvExporter(data, options);
|
|
89
|
+
case "xml":
|
|
90
|
+
return xmlExporter(data, options);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export(...args) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
resolve(this.exportSync(...args));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
42
100
|
const __filename = fileURLToPath(import.meta.url);
|
|
43
|
-
|
|
101
|
+
dirname(__filename);
|
|
44
102
|
const templater = new Templater("ejs", {
|
|
45
103
|
engineOptions: {
|
|
46
104
|
// ...
|
|
@@ -88,33 +146,37 @@ async function ejectFile(from, to, identifier = null, options) {
|
|
|
88
146
|
await onError(identifier, from, to, err);
|
|
89
147
|
}
|
|
90
148
|
}
|
|
91
|
-
async function eject(identifier, options) {
|
|
149
|
+
async function eject(templateDir, identifier, options) {
|
|
92
150
|
const targetDir = options?.targetDir || packageDirectorySync() || process.cwd();
|
|
93
151
|
const logLevel = options?.logLevel || "trace";
|
|
152
|
+
const ignoreFiles = options?.ignoreFiles || [];
|
|
94
153
|
const originalLogLevel = log.getLevel();
|
|
95
154
|
log.setLevel(logLevel);
|
|
96
155
|
if (!identifier) {
|
|
97
156
|
throw new Error("eject: identifier is required");
|
|
98
157
|
} else {
|
|
99
158
|
try {
|
|
100
|
-
const
|
|
101
|
-
const fullPath = path.resolve(localTemplatePath, identifier);
|
|
159
|
+
const fullPath = path.resolve(templateDir, identifier);
|
|
102
160
|
if (await isFile(fullPath)) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
onSuccess: options?.onSuccess,
|
|
106
|
-
onError: options?.onError
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
const globPattern = await isDirectory(fullPath) ? identifier + "/**/*" : identifier;
|
|
110
|
-
for (const fileRelativePath of getFileUrls(globPattern, { cwd: localTemplatePath, nodir: true, posix: true })) {
|
|
111
|
-
const fullTemplateFilePath = path.resolve(localTemplatePath, fileRelativePath);
|
|
112
|
-
await ejectFile(fullTemplateFilePath, path.resolve(targetDir, fileRelativePath), fileRelativePath, {
|
|
161
|
+
if (!ignoreFiles.includes(identifier)) {
|
|
162
|
+
await ejectFile(fullPath, path.resolve(targetDir, identifier), identifier, {
|
|
113
163
|
processor: options?.processor,
|
|
114
164
|
onSuccess: options?.onSuccess,
|
|
115
165
|
onError: options?.onError
|
|
116
166
|
});
|
|
117
167
|
}
|
|
168
|
+
} else {
|
|
169
|
+
const globPattern = await isDirectory(fullPath) ? identifier + "/**/*" : identifier;
|
|
170
|
+
for (const fileRelativePath of getFileUrls(globPattern, { cwd: templateDir, nodir: true, posix: true, dot: true })) {
|
|
171
|
+
const fullTemplateFilePath = path.resolve(templateDir, fileRelativePath);
|
|
172
|
+
if (!ignoreFiles.includes(fileRelativePath)) {
|
|
173
|
+
await ejectFile(fullTemplateFilePath, path.resolve(targetDir, fileRelativePath), fileRelativePath, {
|
|
174
|
+
processor: options?.processor,
|
|
175
|
+
onSuccess: options?.onSuccess,
|
|
176
|
+
onError: options?.onError
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
118
180
|
}
|
|
119
181
|
log.info(`Successfully ejected "${identifier}"`);
|
|
120
182
|
} finally {
|
|
@@ -123,64 +185,6 @@ async function eject(identifier, options) {
|
|
|
123
185
|
}
|
|
124
186
|
}
|
|
125
187
|
|
|
126
|
-
const xml = jstoxml.toXML;
|
|
127
|
-
const SUPPORTED_FORMATS = [
|
|
128
|
-
"json",
|
|
129
|
-
"yaml",
|
|
130
|
-
"csv",
|
|
131
|
-
"xml"
|
|
132
|
-
// 'bson',
|
|
133
|
-
// 'msgpack',
|
|
134
|
-
// 'protobuf',
|
|
135
|
-
// 'avro'
|
|
136
|
-
];
|
|
137
|
-
const jsonExporter = function(data, options = {}) {
|
|
138
|
-
return JSON.stringify(data, options.replacer, options.space);
|
|
139
|
-
};
|
|
140
|
-
const yamlExporter = function(data, options = {}) {
|
|
141
|
-
return yaml.stringify(data, options.replacer, options.exporter);
|
|
142
|
-
};
|
|
143
|
-
const csvExporter = function(data, options) {
|
|
144
|
-
return json2csv(data, options);
|
|
145
|
-
};
|
|
146
|
-
const xmlExporter = function(data, options) {
|
|
147
|
-
return xml(data, options);
|
|
148
|
-
};
|
|
149
|
-
class DataExporter {
|
|
150
|
-
/**
|
|
151
|
-
* The target format
|
|
152
|
-
*/
|
|
153
|
-
format;
|
|
154
|
-
/**
|
|
155
|
-
* Creates new instance of Costume
|
|
156
|
-
* @param options - Costume options
|
|
157
|
-
*/
|
|
158
|
-
constructor(format) {
|
|
159
|
-
if (SUPPORTED_FORMATS.includes(format)) {
|
|
160
|
-
this.format = format;
|
|
161
|
-
} else {
|
|
162
|
-
throw new Error(`DataConverter: Unsupported "${format}" format`);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
exportSync(data, options) {
|
|
166
|
-
switch (this.format) {
|
|
167
|
-
case "json":
|
|
168
|
-
return jsonExporter(data, options);
|
|
169
|
-
case "yaml":
|
|
170
|
-
return yamlExporter(data, options);
|
|
171
|
-
case "csv":
|
|
172
|
-
return csvExporter(data, options);
|
|
173
|
-
case "xml":
|
|
174
|
-
return xmlExporter(data, options);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
export(...args) {
|
|
178
|
-
return new Promise((resolve, reject) => {
|
|
179
|
-
resolve(this.exportSync(...args));
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
188
|
function getPackageInfo() {
|
|
185
189
|
const pkgPath = path.resolve(packageDirectorySync(), "./package.json");
|
|
186
190
|
return JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DotenvConfigOptions } from '@dotenvx/dotenvx';
|
|
2
2
|
import { IPackageJson as PackageJson, IAuthor as PackageJsonAuthor, IRepository as PackageJsonRepository, IBugs as PackageJsonBugs } from 'package-json-type';
|
|
3
|
+
/**
|
|
4
|
+
* @group Types
|
|
5
|
+
*/
|
|
3
6
|
export type ProjectGlobals = Record<string, string | Record<string, unknown> | undefined> & {
|
|
4
7
|
ENV: NodeJS.ProcessEnv;
|
|
5
8
|
PACKAGE: {
|
|
@@ -19,7 +22,13 @@ export type ProjectGlobals = Record<string, string | Record<string, unknown> | u
|
|
|
19
22
|
ISSUES_URL: PackageJsonBugs['url'];
|
|
20
23
|
HOMEPAGE: PackageJson['homepage'];
|
|
21
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* @group Types
|
|
27
|
+
*/
|
|
22
28
|
export type DotenvOptions = Omit<DotenvConfigOptions, 'processEnv'>;
|
|
29
|
+
/**
|
|
30
|
+
* @group Types
|
|
31
|
+
*/
|
|
23
32
|
export type DefineGlobalsBuilder = (ctx: {
|
|
24
33
|
env: NodeJS.ProcessEnv;
|
|
25
34
|
pkg: PackageJson;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API of juisy/templater library
|
|
3
|
+
* @module juisy\/templater
|
|
4
|
+
* @author Hervé Perchec
|
|
5
|
+
*/
|
|
1
6
|
export { Templater } from './Templater';
|
|
2
7
|
export { MarkdownTemplater } from './markdown-templater';
|
|
3
8
|
export { ReadmeTemplater } from './markdown-templater/ReadmeTemplater';
|
|
4
9
|
export type * from './types';
|
|
5
10
|
export type { MarkdownTemplaterOptions } from './markdown-templater';
|
|
6
|
-
export type { UserConfiguration as
|
|
11
|
+
export type { UserConfiguration as ReadmeTemplaterUserConfig, Configuration as ReadmeTemplaterConfig } from './markdown-templater/ReadmeTemplater';
|
package/dist/templater/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* juisy
|
|
2
|
+
* juisy v2.0.0-beta.10
|
|
3
3
|
* Copyright © 2022-Present Hervé Perchec
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -8,8 +8,8 @@ import handlebars from 'handlebars';
|
|
|
8
8
|
import { remark } from 'remark';
|
|
9
9
|
import remarkToc from 'remark-toc';
|
|
10
10
|
import remarkFrontmatter from 'remark-frontmatter';
|
|
11
|
-
import path
|
|
12
|
-
import {
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { pathToFileURL } from 'node:url';
|
|
13
13
|
import fs from 'fs-extra';
|
|
14
14
|
import chalk from 'chalk';
|
|
15
15
|
import merge from 'lodash.merge';
|
|
@@ -122,11 +122,17 @@ class MarkdownTemplater extends Templater {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
126
|
-
dirname(__filename);
|
|
127
125
|
const slugger = new GithubSlugger();
|
|
128
126
|
const DEFAULT_INIT_TARGET_RELATIVE_PATH = "./docs/readme";
|
|
129
127
|
class ReadmeTemplater {
|
|
128
|
+
/**
|
|
129
|
+
* @param config - The user configuration file path (as string) or object
|
|
130
|
+
* @example
|
|
131
|
+
* // Path as string
|
|
132
|
+
* const templater = new ReadmeTemplater('./.docs/readme/config.js')
|
|
133
|
+
* // Pass object. See configuration below
|
|
134
|
+
* const templater = new ReadmeTemplater({ /* ... *\/ })
|
|
135
|
+
*/
|
|
130
136
|
constructor(config) {
|
|
131
137
|
this.config = config;
|
|
132
138
|
this.templater = new MarkdownTemplater("ejs", {});
|
|
@@ -134,21 +140,13 @@ class ReadmeTemplater {
|
|
|
134
140
|
config;
|
|
135
141
|
templater;
|
|
136
142
|
/**
|
|
137
|
-
* @param {Configuration|string} config - The config object to process. Can be path to config file as string.
|
|
138
|
-
* @param {object} [options] - Same as render
|
|
139
|
-
* @returns {void|Promise<void>} Promise is immediately resolved except if a module is async.
|
|
140
|
-
* @throws Throws error if render or file writing fails
|
|
141
|
-
* @description
|
|
142
143
|
* Writes rendered README markdown to file
|
|
144
|
+
* @param config - The config object to process. Can be path to config file as string.
|
|
145
|
+
* @param options - Same as render
|
|
146
|
+
* @throws Throws error if render or file writing fails
|
|
143
147
|
* @example
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* readmeGenerator.generate(config, { data: { foo: 'bar' } }) // pass options
|
|
147
|
-
* // Async
|
|
148
|
-
* await readmeGenerator.generate('./.docs/readme/config.js') // async module
|
|
149
|
-
* await readmeGenerator.generate({
|
|
150
|
-
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
151
|
-
* })
|
|
148
|
+
* await templater.generate() // => output to README.md file
|
|
149
|
+
* await templater.generate({ data: { foo: 'bar' } }) // pass options
|
|
152
150
|
*/
|
|
153
151
|
async generate(options = {}) {
|
|
154
152
|
const processedConfig = await ReadmeTemplater.processConfig(this.config);
|
|
@@ -173,14 +171,8 @@ class ReadmeTemplater {
|
|
|
173
171
|
* @param options.data - Additionnal data object to merge with default EJS data
|
|
174
172
|
* @returns Returns the rendered markdown as string. Promise is immediately resolved except if a module is async.
|
|
175
173
|
* @example
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* const result = readmeGenerator.render(config, { data: { foo: 'bar' } })
|
|
179
|
-
* // Async
|
|
180
|
-
* const result = await readmeGenerator.render('./.docs/readme/config.js') // async module
|
|
181
|
-
* const result = await readmeGenerator.render({
|
|
182
|
-
* ejsDataPath: '/path/to/ejs/data.js' // async module
|
|
183
|
-
* })
|
|
174
|
+
* await templater.render()
|
|
175
|
+
* await templater.render({ data: { foo: 'bar' } })
|
|
184
176
|
*/
|
|
185
177
|
async render(options = {}) {
|
|
186
178
|
const processedConfig = await ReadmeTemplater.processConfig(this.config);
|
|
@@ -243,12 +235,8 @@ class ReadmeTemplater {
|
|
|
243
235
|
return result;
|
|
244
236
|
}
|
|
245
237
|
/**
|
|
246
|
-
* @alias module:readme-generator.defaultConfig
|
|
247
|
-
* @type {Configuration}
|
|
248
|
-
* @description
|
|
249
238
|
* Returns the default configuration object.
|
|
250
239
|
* This base configuration is used by `processConfig` method and so `generate` and `render` methods.
|
|
251
|
-
* See also {@link module:readme-generator~Configuration Configuration} defaults.
|
|
252
240
|
*/
|
|
253
241
|
static defaultConfig = {
|
|
254
242
|
fileName: "README.md",
|
|
@@ -258,7 +246,6 @@ class ReadmeTemplater {
|
|
|
258
246
|
ejsOptions: {
|
|
259
247
|
/**
|
|
260
248
|
* Always render in async mode
|
|
261
|
-
* @since v3.0.0
|
|
262
249
|
*/
|
|
263
250
|
async: true,
|
|
264
251
|
/**
|