juisy 2.0.0-beta.0 → 2.0.0-beta.1

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 (110) hide show
  1. package/bin/cli/cli.js +6 -4
  2. package/bin/cli/cmds/index.js +10 -10
  3. package/bin/cli/cmds/private/docs/generate-api.js +31 -0
  4. package/bin/cli/cmds/{docs → private/docs}/index.js +4 -6
  5. package/bin/cli/cmds/{print-globals.js → public/print-globals.js} +0 -1
  6. package/bin/scripts/prepare.js +22 -0
  7. package/dist/DataExporter.d.ts +6 -0
  8. package/dist/cli/CLIFactory.d.ts +48 -11
  9. package/dist/cli/Command.d.ts +23 -13
  10. package/dist/cli/GlobalSettings.schema.json +1 -0
  11. package/dist/cli/InterfaceUtils.d.ts +8 -2
  12. package/dist/cli/OutputUtils.d.ts +3 -3
  13. package/dist/cli/Plugin.d.ts +21 -0
  14. package/dist/cli/extract-usage.d.ts +7 -1
  15. package/dist/cli/index.d.ts +19 -6
  16. package/dist/cli/index.js +1160 -138
  17. package/dist/cli/plugins/command-handler-injections/augment.d.ts +29 -0
  18. package/dist/cli/{command-visitors → plugins/command-handler-injections/command-visitors}/command-handler-injections.d.ts +1 -1
  19. package/dist/cli/plugins/command-handler-injections/index.d.ts +3 -0
  20. package/dist/cli/plugins/command-meta/augment.d.ts +23 -0
  21. package/dist/cli/{command-visitors/get-command-meta.d.ts → plugins/command-meta/command-visitors/command-meta.d.ts} +1 -1
  22. package/dist/cli/plugins/command-meta/index.d.ts +3 -0
  23. package/dist/cli/plugins/default-command-fallbacks/augment.d.ts +3 -0
  24. package/dist/cli/plugins/default-command-fallbacks/command-visitors/default-command-fallbacks.d.ts +10 -0
  25. package/dist/cli/plugins/default-command-fallbacks/index.d.ts +3 -0
  26. package/dist/cli/plugins/load-env-file/augment.d.ts +9 -0
  27. package/dist/cli/plugins/load-env-file/index.d.ts +3 -0
  28. package/dist/cli/plugins/private-commands/augment.d.ts +6 -0
  29. package/dist/cli/{command-visitors → plugins/private-commands/command-visitors}/private-command.d.ts +1 -1
  30. package/dist/cli/plugins/private-commands/index.d.ts +3 -0
  31. package/dist/cli/plugins/register-changelog-command/augment.d.ts +110 -0
  32. package/dist/cli/plugins/register-changelog-command/cmds/index.d.ts +3 -0
  33. package/dist/cli/plugins/register-changelog-command/index.d.ts +3 -0
  34. package/dist/cli/plugins/register-docs-commands/augment.d.ts +18 -0
  35. package/dist/cli/plugins/register-docs-commands/cmds/generate-api.d.ts +3 -0
  36. package/dist/cli/plugins/register-docs-commands/cmds/generate-cli.d.ts +3 -0
  37. package/dist/cli/plugins/register-docs-commands/cmds/generate-readme.d.ts +3 -0
  38. package/dist/cli/plugins/register-docs-commands/cmds/index.d.ts +3 -0
  39. package/dist/cli/plugins/register-docs-commands/index.d.ts +3 -0
  40. package/dist/cli/plugins/register-git-hooks-commands/augment.d.ts +40 -0
  41. package/dist/cli/plugins/register-git-hooks-commands/cmds/index.d.ts +3 -0
  42. package/dist/cli/plugins/register-git-hooks-commands/cmds/reset.d.ts +3 -0
  43. package/dist/cli/plugins/register-git-hooks-commands/cmds/sync.d.ts +3 -0
  44. package/dist/cli/plugins/register-git-hooks-commands/index.d.ts +3 -0
  45. package/dist/cli/plugins/register-lint-commands/augment.d.ts +39 -0
  46. package/dist/cli/plugins/register-lint-commands/cmds/commit.d.ts +3 -0
  47. package/dist/cli/plugins/register-lint-commands/cmds/default.d.ts +3 -0
  48. package/dist/cli/plugins/register-lint-commands/cmds/markdown.d.ts +3 -0
  49. package/dist/cli/plugins/register-lint-commands/cmds/staged.d.ts +3 -0
  50. package/dist/cli/plugins/register-lint-commands/index.d.ts +3 -0
  51. package/dist/cli/plugins/register-lint-commands/settings.d.ts +11 -0
  52. package/dist/cli/plugins/register-lint-commands/types.d.ts +26 -0
  53. package/dist/cli/plugins/register-release-command/augment.d.ts +9 -0
  54. package/dist/cli/plugins/register-release-command/cmds/index.d.ts +3 -0
  55. package/dist/cli/plugins/register-release-command/index.d.ts +3 -0
  56. package/dist/cli/plugins/register-test-command/augment.d.ts +3 -0
  57. package/dist/cli/plugins/register-test-command/cmds/index.d.ts +3 -0
  58. package/dist/cli/plugins/register-test-command/index.d.ts +3 -0
  59. package/dist/cli/types.d.ts +73 -44
  60. package/dist/cli/utils.d.ts +3 -3
  61. package/dist/eject.d.ts +11 -4
  62. package/dist/index.d.ts +8 -2
  63. package/dist/index.js +80 -76
  64. package/dist/project-globals.d.ts +9 -0
  65. package/dist/templater/index.d.ts +6 -1
  66. package/dist/templater/index.js +27 -40
  67. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +28 -28
  68. package/dist/templater/markdown-templater/index.d.ts +3 -0
  69. package/dist/templater/types.d.ts +6 -0
  70. package/dist/utils/misc.d.ts +1 -1
  71. package/package.json +69 -55
  72. package/README.md +0 -211
  73. package/bin/cli/cmds/changelog.js +0 -41
  74. package/bin/cli/cmds/docs/generate-api.js +0 -22
  75. package/bin/cli/cmds/docs/generate-cli.js +0 -11
  76. package/bin/cli/cmds/docs/generate-readme.js +0 -11
  77. package/bin/cli/cmds/eject.js +0 -28
  78. package/bin/cli/cmds/git-hooks/index.js +0 -20
  79. package/bin/cli/cmds/git-hooks/reset.js +0 -48
  80. package/bin/cli/cmds/git-hooks/sync.js +0 -19
  81. package/bin/cli/cmds/release.js +0 -231
  82. package/bin/cli/lib/docs/generate-api-doc.js +0 -78
  83. package/bin/cli/lib/version/update-version.js +0 -52
  84. package/bin/scripts/commit-msg.js +0 -32
  85. package/bin/scripts/pre-commit.js +0 -24
  86. package/dist/cli/command-visitors/index.d.ts +0 -9
  87. package/src/index.js +0 -507
  88. package/template/CHANGELOG.md +0 -0
  89. package/template/bin/cli/cli.js +0 -27
  90. package/template/bin/cli/cmds/changelog.js +0 -71
  91. package/template/bin/cli/cmds/docs.js +0 -30
  92. package/template/bin/cli/cmds/docs_cmds/generate-api.js +0 -75
  93. package/template/bin/cli/cmds/docs_cmds/generate-readme.js +0 -51
  94. package/template/bin/cli/cmds/git-hooks.js +0 -30
  95. package/template/bin/cli/cmds/git_hooks_cmds/reset.js +0 -76
  96. package/template/bin/cli/cmds/git_hooks_cmds/sync.js +0 -44
  97. package/template/bin/cli/cmds/release.js +0 -219
  98. package/template/bin/cli/index.js +0 -7
  99. package/template/bin/cli/lib/docs/generate-api-doc.js +0 -33
  100. package/template/bin/cli/lib/release/generate-release-note.js +0 -3
  101. package/template/bin/cli/lib/version/update-version.js +0 -51
  102. package/template/bin/scripts/commit-msg.js +0 -42
  103. package/template/bin/scripts/pre-commit.js +0 -32
  104. package/template/docs/api/docs.config.js +0 -10
  105. package/template/docs/readme/config.js +0 -22
  106. package/template/docs/readme/readme.js +0 -70
  107. package/template/docs/readme/template.md +0 -53
  108. /package/bin/cli/cmds/{docs → private/docs}/lint.js +0 -0
  109. /package/bin/cli/cmds/{test.js → private/test.js} +0 -0
  110. /package/bin/cli/cmds/{squeeze.js → public/squeeze.js} +0 -0
@@ -1,59 +1,84 @@
1
- import { Argv, CommandModule as YargsCommandModule, CommandBuilder, MiddlewareFunction } from 'yargs';
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
- * An array whose first element is not undefined.
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 NotEmptyArray<T = any> = [T, ...T[]];
12
- /** Shims for private yargs types */
13
- interface Positional {
14
- cmd: NotEmptyArray<string>;
15
- variadic: boolean;
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
- export interface YargsCommandHandler {
18
- builder: CommandBuilder;
19
- demanded: Positional[];
20
- deprecated?: boolean;
21
- description?: string | false;
22
- handler: CommandModule['handler'];
23
- middlewares: MiddlewareFunction[];
24
- optional: Positional[];
25
- original: string;
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
- _meta: Record<string, any> & {
36
- private: boolean;
37
- };
59
+ _disabledDefaultCommands: Set<string>;
60
+ _settings: Record<string, any>;
38
61
  originalCommand: Argv['command'];
39
- globalCommandVisitor: (name: string, visitor: CommandVisitor, defaultOptions: any) => this;
40
- globalCommandVisitorOptions: (name: string, options: Record<any, any>) => this;
41
- hasGlobalCommandVisitor: (name: string) => boolean;
42
- disableGlobalCommandVisitors: (visitors: string[]) => this;
43
- enableGlobalCommandVisitors: (visitors: string[]) => this;
44
- isPrivate: () => this['_isPrivate'];
45
- getMeta: () => this['_meta'];
46
- getDemandedCommands: () => Dictionary<{
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: () => Dictionary<string | undefined>;
53
- getDeprecatedOptions: () => Dictionary<string | boolean | undefined>;
54
- getGroups: () => Dictionary<string[]>;
55
- getOptions: () => Record<string, any>;
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
- export type CommandModule = {
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: YargsCommandModule['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: YargsCommandModule['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: (this: YargsCommandHandler & {
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
- meta: Record<string, any>;
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: CommandModule,
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 | CommandModule);
140
+ options: any) => false | CommandObject);
112
141
  export {};
@@ -1,4 +1,4 @@
1
- import { CommandModule, CLIEngine } from './types';
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: CommandModule['builder'], builder: (cli: CLIEngine) => CLIEngine): (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
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: CommandModule['handler'], handler: CommandModule['handler']): CommandModule["handler"];
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
- type EjectOptions = {
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 juisy/template folder). Can be a glob pattern (ex: `bin\/**\/*`).
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(identifier: string, options?: EjectOptions): Promise<void>;
22
- export {};
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 * from './project-globals';
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 v1.4.0
2
+ * juisy v2.0.0-beta.0
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
- const __dirname = dirname(__filename);
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 localTemplatePath = path.resolve(__dirname, "../template");
101
- const fullPath = path.resolve(localTemplatePath, identifier);
159
+ const fullPath = path.resolve(templateDir, identifier);
102
160
  if (await isFile(fullPath)) {
103
- await ejectFile(fullPath, path.resolve(targetDir, identifier), identifier, {
104
- processor: options?.processor,
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 ReadmeTemplaterUserConfiguration } from './markdown-templater/ReadmeTemplater';
11
+ export type { UserConfiguration as ReadmeTemplaterUserConfig, Configuration as ReadmeTemplaterConfig } from './markdown-templater/ReadmeTemplater';
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * juisy v1.4.0
2
+ * juisy v2.0.0-beta.0
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, { dirname } from 'path';
12
- import { fileURLToPath, pathToFileURL } from 'url';
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';
@@ -28,7 +28,7 @@ class Templater {
28
28
  this.methodsMap.compile = async (template) => {
29
29
  return handlebars.compile(template, options.engineOptions);
30
30
  };
31
- this.methodsMap.render = async (template, data = void 0, opts = void 0) => {
31
+ this.methodsMap.render = async (template, data = undefined, opts = undefined) => {
32
32
  return this.methodsMap.compile(template).template(data);
33
33
  };
34
34
  break;
@@ -37,7 +37,7 @@ class Templater {
37
37
  this.methodsMap.compile = async (template) => {
38
38
  return ejs.compile(template, options.engineOptions);
39
39
  };
40
- this.methodsMap.render = async (template, data = void 0, opts) => {
40
+ this.methodsMap.render = async (template, data = undefined, opts) => {
41
41
  return ejs.render(template, data, {
42
42
  ...options.engineOptions,
43
43
  ...opts || {}
@@ -66,7 +66,7 @@ class Templater {
66
66
  /**
67
67
  * Renders a template with the given context.
68
68
  */
69
- async render(template, data = void 0, options = void 0) {
69
+ async render(template, data = undefined, options = undefined) {
70
70
  const mergedData = { ...this.defaultData, ...data || {} };
71
71
  return await this.methodsMap.render(template, mergedData, options);
72
72
  }
@@ -99,8 +99,8 @@ class MarkdownTemplater extends Templater {
99
99
  use: [
100
100
  ...options.use || []
101
101
  ],
102
- toc: options.toc === true ? defaultRemarkTocOptions : options.toc !== void 0 ? options.toc : defaultRemarkTocOptions,
103
- frontmatter: options.frontmatter === true ? defaultRemarkFrontmatterOptions : options.frontmatter !== void 0 ? options.frontmatter : defaultRemarkFrontmatterOptions
102
+ toc: options.toc === true ? defaultRemarkTocOptions : options.toc !== undefined ? options.toc : defaultRemarkTocOptions,
103
+ frontmatter: options.frontmatter === true ? defaultRemarkFrontmatterOptions : options.frontmatter !== undefined ? options.frontmatter : defaultRemarkFrontmatterOptions
104
104
  };
105
105
  }
106
106
  initProcessor() {
@@ -116,17 +116,23 @@ class MarkdownTemplater extends Templater {
116
116
  /**
117
117
  * Renders a template with the given context.
118
118
  */
119
- async render(template, data = void 0, options = void 0) {
119
+ async render(template, data = undefined, options = undefined) {
120
120
  const content = await super.render(template, data, options);
121
121
  return (await this.processor.process(content)).toString();
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
- * readmeGenerator.generate(config) // => output to README.md file
145
- * readmeGenerator.generate('./.docs/readme/config.js') // pass config path
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
- * const result = readmeGenerator.render(config)
177
- * const result = readmeGenerator.render('./.docs/readme/config.js')
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);
@@ -237,18 +229,14 @@ class ReadmeTemplater {
237
229
  } else {
238
230
  result.ejsOptions = ReadmeTemplater.defaultConfig.ejsOptions;
239
231
  }
240
- result.appendAutoGenMessage = customConfig.appendAutoGenMessage !== void 0 ? customConfig.appendAutoGenMessage : ReadmeTemplater.defaultConfig.appendAutoGenMessage;
241
- result.autoToc = customConfig.autoToc !== void 0 ? customConfig.autoToc : ReadmeTemplater.defaultConfig.autoToc;
242
- result.slugify = customConfig.slugify !== void 0 ? customConfig.slugify : ReadmeTemplater.defaultConfig.slugify;
232
+ result.appendAutoGenMessage = customConfig.appendAutoGenMessage !== undefined ? customConfig.appendAutoGenMessage : ReadmeTemplater.defaultConfig.appendAutoGenMessage;
233
+ result.autoToc = customConfig.autoToc !== undefined ? customConfig.autoToc : ReadmeTemplater.defaultConfig.autoToc;
234
+ result.slugify = customConfig.slugify !== undefined ? customConfig.slugify : ReadmeTemplater.defaultConfig.slugify;
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
  /**