juisy 2.1.0 → 2.3.0

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 (56) hide show
  1. package/LICENSE +1 -1
  2. package/bin/cli/cli.js +14 -0
  3. package/bin/cli/cmds/index.js +6 -4
  4. package/bin/cli/cmds/public/AddExt.js +49 -0
  5. package/bin/cli/cmds/public/RemoveExt.js +49 -0
  6. package/bin/cli/index.js +1 -0
  7. package/bin/cli/init.js +1 -0
  8. package/bin/cli/lib/index.js +71 -0
  9. package/dist/DataExporter.d.ts +1 -0
  10. package/dist/bootstrap.d.ts +1 -0
  11. package/dist/cli/CLIFactory.d.ts +1 -0
  12. package/dist/cli/Command.d.ts +23 -2
  13. package/dist/cli/InterfaceUtils.d.ts +11 -9
  14. package/dist/cli/OutputUtils.d.ts +30 -16
  15. package/dist/cli/Plugin.d.ts +9 -0
  16. package/dist/cli/extract-usage.d.ts +8 -0
  17. package/dist/cli/index.d.ts +1 -0
  18. package/dist/cli/index.js +193 -113
  19. package/dist/cli/plugins/command-meta/augment.d.ts +0 -3
  20. package/dist/cli/plugins/command-meta/index.d.ts +4 -0
  21. package/dist/cli/plugins/default-command-fallbacks/command-visitors/default-command-fallbacks.d.ts +1 -1
  22. package/dist/cli/plugins/default-command-fallbacks/index.d.ts +4 -0
  23. package/dist/cli/plugins/load-env-file/index.d.ts +4 -0
  24. package/dist/cli/plugins/private-commands/augment.d.ts +8 -0
  25. package/dist/cli/plugins/private-commands/command-visitors/private-command.d.ts +7 -3
  26. package/dist/cli/plugins/private-commands/index.d.ts +4 -0
  27. package/dist/cli/plugins/register-bump-version-command/index.d.ts +4 -0
  28. package/dist/cli/plugins/register-changelog-command/index.d.ts +4 -0
  29. package/dist/cli/plugins/register-docs-commands/index.d.ts +4 -0
  30. package/dist/cli/plugins/register-git-hooks-commands/index.d.ts +4 -0
  31. package/dist/cli/plugins/register-lint-commands/index.d.ts +4 -0
  32. package/dist/cli/plugins/register-lint-commands/settings.d.ts +2 -0
  33. package/dist/cli/plugins/register-lint-commands/types.d.ts +5 -9
  34. package/dist/cli/plugins/register-release-command/index.d.ts +4 -0
  35. package/dist/cli/plugins/register-test-command/index.d.ts +4 -0
  36. package/dist/cli/types.d.ts +7 -0
  37. package/dist/cli/utils.d.ts +3 -4
  38. package/dist/eject.d.ts +1 -0
  39. package/dist/get-package-info.d.ts +1 -0
  40. package/dist/index.d.ts +5 -1
  41. package/dist/index.js +192 -13
  42. package/dist/project-globals.d.ts +2 -0
  43. package/dist/shims/shims.d.ts +1440 -0
  44. package/dist/templater/index.d.ts +4 -1
  45. package/dist/templater/index.js +42 -23
  46. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +8 -10
  47. package/dist/templater/markdown-templater/index.d.ts +10 -1
  48. package/dist/utils/misc.d.ts +92 -10
  49. package/package.json +38 -44
  50. package/bin/cli/cmds/private/docs/generate-api.js +0 -31
  51. package/bin/cli/cmds/private/docs/index.js +0 -20
  52. package/bin/cli/cmds/private/test.js +0 -33
  53. package/dist/vite/plugins/inject-css-variables/index.d.ts +0 -23
  54. package/dist/vite/plugins/inject-css-variables/index.js +0 -60
  55. package/dist/vite/plugins/inject-project-globals/index.d.ts +0 -19
  56. package/dist/vite/plugins/inject-project-globals/index.js +0 -58
package/LICENSE CHANGED
@@ -630,7 +630,7 @@ state the exclusion of warranty; and each file should have at least
630
630
  the "copyright" line and a pointer to where the full notice is found.
631
631
 
632
632
  juisy
633
- Copyright (C) 2024 Hervé Perchec <contact@herve-perchec.fr>
633
+ Copyright (C) 2022 - Present Hervé Perchec <contact@herve-perchec.fr>
634
634
 
635
635
  This program is free software: you can redistribute it and/or modify
636
636
  it under the terms of the GNU Affero General Public License as published
package/bin/cli/cli.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { DEFAULT_EXT_CACHE_PATH, loadExtensions } from './lib/index.js'
2
+ import mri from 'mri'
1
3
  import { CLIFactory } from '#juisy/cli'
2
4
 
3
5
  import { commands } from './cmds/index.js'
@@ -15,11 +17,23 @@ function getBanner () {
15
17
  return str
16
18
  }
17
19
 
20
+ // Use `mri` library to parse --ext-cache option
21
+ const extCacheOption = mri(CLI.helpers.hideBin(process.argv), {
22
+ string: [ 'ext-cache' ]
23
+ })['ext-cache']
24
+
25
+ await loadExtensions(extCacheOption)
26
+
18
27
  export default await CLIFactory(cli => cli
19
28
  .scriptName('juisy')
20
29
  .usage(`${getBanner()}\nUsage: $0 <command> [<options>]`)
21
30
  .disableDefaultCommand('docs generate:api')
22
31
  .globalCommandVisitorOptions('private-command-visitor', { envKey: '__JUISY_CLI_ENV__' })
32
+ .option('ext-cache', {
33
+ type: 'string',
34
+ describe: `Path to extensions cache file (default: "${DEFAULT_EXT_CACHE_PATH}")`,
35
+ requiresArg: true
36
+ })
23
37
  .command(commands)
24
38
  // .demandCommand(1, ('Command is missing. See help to learn more.').red)
25
39
  )
@@ -1,13 +1,15 @@
1
1
  // Private commands
2
- import docs from './private/docs/index.js'
3
- // import test from './private/test.js'
2
+ // ...
4
3
  // Public commands
4
+ import AddExtCommand from './public/AddExt.js'
5
+ import RemoveExtCommand from './public/RemoveExt.js'
5
6
  import printGlobals from './public/print-globals.js'
6
7
 
7
8
  export const commands = [
8
9
  // Private
9
- docs,
10
- // test,
10
+ // ...
11
11
  // Public
12
+ AddExtCommand,
13
+ RemoveExtCommand,
12
14
  printGlobals
13
15
  ]
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @import { Command } from '#juisy/cli'
3
+ */
4
+
5
+ /**
6
+ * @extends {Command}
7
+ */
8
+ export default class AddExtCommand extends CLI.Command {
9
+ /**
10
+ * The command signature
11
+ */
12
+ command = 'ext:add <ext>'
13
+
14
+ /**
15
+ * The command description
16
+ */
17
+ describe = 'Add a Juisy extension'
18
+
19
+ /**
20
+ * The command meta
21
+ */
22
+ meta = {}
23
+
24
+ /**
25
+ * Command builder
26
+ */
27
+ builder (cli) {
28
+ return cli
29
+ }
30
+
31
+ /**
32
+ * Command handler
33
+ */
34
+ async handler (args) {
35
+ // Utils
36
+ const { $style, step, substep } = CLI.OutputUtils
37
+ // const { run } = CLI.InterfaceUtils
38
+
39
+ /**
40
+ * Add extension
41
+ */
42
+ step('Adding extension')
43
+
44
+ this.log('Wants to add: ', args.ext)
45
+
46
+ substep($style.green('✔ Successfuly generated'), { last: true })
47
+ this.log() // blank line
48
+ }
49
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @import { Command } from '#juisy/cli'
3
+ */
4
+
5
+ /**
6
+ * @extends {Command}
7
+ */
8
+ export default class RemoveExtCommand extends CLI.Command {
9
+ /**
10
+ * The command signature
11
+ */
12
+ command = 'ext:remove <ext>'
13
+
14
+ /**
15
+ * The command description
16
+ */
17
+ describe = 'Remove a Juisy extension'
18
+
19
+ /**
20
+ * The command meta
21
+ */
22
+ meta = {}
23
+
24
+ /**
25
+ * Command builder
26
+ */
27
+ builder (cli) {
28
+ return cli
29
+ }
30
+
31
+ /**
32
+ * Command handler
33
+ */
34
+ async handler (args) {
35
+ // Utils
36
+ const { $style, step, substep } = CLI.OutputUtils
37
+ // const { run } = CLI.InterfaceUtils
38
+
39
+ /**
40
+ * Remove extension
41
+ */
42
+ step('Removing extension')
43
+
44
+ this.log('Wants to remove: ', args.ext)
45
+
46
+ substep($style.green('✔ Successfuly generated'), { last: true })
47
+ this.log() // blank line
48
+ }
49
+ }
package/bin/cli/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  'use strict'
4
4
 
5
+ import './init.js'
5
6
  import cli from './cli.js'
6
7
 
7
8
  const argv = CLI.helpers.hideBin(process.argv)
@@ -0,0 +1 @@
1
+ process.env.JUISY_ENABLE_EXTENSIONS = 'true'
@@ -0,0 +1,71 @@
1
+ import path from 'node:path'
2
+ import { pathToFileURL } from 'node:url'
3
+ import fs from 'fs-extra'
4
+ import { CLIFactory } from '#juisy/cli'
5
+
6
+ export const DEFAULT_EXT_CACHE_PATH = './node_modules/.cache/juisy/extensions.json'
7
+
8
+ /**
9
+ * Get the extensions locally added to juisy
10
+ * @param {string} extCachePath - The path to extensions cache file
11
+ * @returns {string[]} The extension names
12
+ */
13
+ export function getExtensions (extCachePath = DEFAULT_EXT_CACHE_PATH) {
14
+ const absolutePath = path.isAbsolute(extCachePath)
15
+ ? extCachePath
16
+ : path.resolve(extCachePath)
17
+
18
+ // If default, ensure file exists
19
+ if (extCachePath === DEFAULT_EXT_CACHE_PATH
20
+ && fs.existsSync(path.resolve('./node_modules'))
21
+ && !fs.existsSync(absolutePath)
22
+ ) {
23
+ fs.outputFileSync(absolutePath, '[]')
24
+ }
25
+
26
+ const content = fs.readFileSync(absolutePath, 'utf-8')
27
+ const extensionIds = JSON.parse(content)
28
+ return extensionIds
29
+ }
30
+
31
+ /**
32
+ * Load an extension
33
+ * @param {string} id - The module name or relative/absolute path
34
+ */
35
+ export async function loadExtension (id) {
36
+ // Module name or full path
37
+ const modPath = id.startsWith('.') // is relative?
38
+ ? path.resolve(id) // relative to process.cwd()
39
+ : id // can be module name or absolute path
40
+
41
+ const mod = await import(path.isAbsolute(modPath)
42
+ ? pathToFileURL(modPath).toString()
43
+ : id)
44
+
45
+ return mod.extension || mod.default
46
+ }
47
+
48
+ /**
49
+ * Load the extensions
50
+ * @param {?string} extCachePath - The path to extensions cache file
51
+ */
52
+ export async function loadExtensions (extCachePath) {
53
+ // Get extension identifiers
54
+ const extensionIds = getExtensions(extCachePath)
55
+
56
+ const extensions = []
57
+
58
+ for (const id of extensionIds) {
59
+ const loaded = {
60
+ id,
61
+ extension: await loadExtension(id)
62
+ }
63
+ extensions.push(loaded)
64
+ //
65
+ if (loaded.extension.juisyBin) {
66
+ loaded.extension.juisyBin(CLIFactory)
67
+ }
68
+ }
69
+
70
+ return extensions
71
+ }
@@ -53,6 +53,7 @@ declare const csvExporter: (data: any, options: Json2CsvOptions) => string;
53
53
  declare const xmlExporter: (data: any, options: XMLoptions) => string;
54
54
  /**
55
55
  * Universal data exporter
56
+ * @group None
56
57
  */
57
58
  export declare class DataExporter {
58
59
  /**
@@ -0,0 +1 @@
1
+ export default function bootstrap(importMeta: ImportMeta): Promise<void>;
@@ -41,6 +41,7 @@ export type PluginAPI = {
41
41
  * @param options - The options object
42
42
  * @param options.settingsPath - The path to CLI config file
43
43
  * @returns A function that takes optional argv as first parameter
44
+ * @group None
44
45
  * @example
45
46
  * import { CLIFactory } from 'juisy/cli'
46
47
  *
@@ -12,11 +12,13 @@ type CommandOptions = {
12
12
  };
13
13
  /**
14
14
  * Class to wrap command definition (CommandObject)
15
+ * See {@link juisy-templater.ReadmeTemplater#generate}
16
+ * @group None
15
17
  */
16
18
  export declare class Command implements CommandObject {
17
19
  /**
18
20
  * Creates a Command instance from object (CommandObject)
19
- * @param {CommandObject} commandObject - The command definition object
21
+ * @param commandObject - The command definition object
20
22
  */
21
23
  constructor(commandObject?: CommandOptions);
22
24
  /**
@@ -62,6 +64,10 @@ export declare class Command implements CommandObject {
62
64
  * @returns An array of command line arguments
63
65
  */
64
66
  getProcessArgv(): string[];
67
+ /**
68
+ * Get the command signature as string
69
+ */
70
+ getSignature(): string;
65
71
  /**
66
72
  * Get Command instance as plain object
67
73
  * @returns The command definition object to pass to yargs
@@ -86,9 +92,24 @@ export declare class Command implements CommandObject {
86
92
  /**
87
93
  * Static properties
88
94
  */
95
+ /**
96
+ * The CLI engine
97
+ * @ignore
98
+ */
99
+ private static _engine;
89
100
  /**
90
101
  * The CLI engine. Will be set by createEngine method
91
102
  */
92
- static engine: CLIEngine;
103
+ static get engine(): CLIEngine;
104
+ /**
105
+ * Set the CLI engine
106
+ * @param engine - The CLI engine
107
+ */
108
+ static setEngine(engine: CLIEngine): void;
109
+ /**
110
+ * Get the command signature as string
111
+ * @param cmdObj - Can be an instance of Command or a command object
112
+ */
113
+ static getSignature(cmdObj: Command | CommandOptions): string;
93
114
  }
94
115
  export {};
@@ -2,9 +2,14 @@ import { ResultPromise as ExecaResultPromise, ExecaError, Options as ExecaOption
2
2
  import { default as _prompts } from 'prompts';
3
3
  /**
4
4
  * Command execution error thrown by execa
5
+ * @group Types
5
6
  */
6
7
  export interface RunError extends ExecaError {
7
8
  }
9
+ /**
10
+ * CLI - interface utils
11
+ * @group None
12
+ */
8
13
  export declare class InterfaceUtils {
9
14
  /**
10
15
  * Get root directory path
@@ -14,13 +19,12 @@ export declare class InterfaceUtils {
14
19
  */
15
20
  static rootDir: string;
16
21
  /**
22
+ * Run command (child_process). See also `execa` package documentation
17
23
  * @param bin - Command
18
24
  * @param args - Same as execa second arg
19
25
  * @param opts - Options
20
26
  * @returns The `execa` Promise
21
27
  * @throws {RunError}
22
- * @description
23
- * Run command (child_process). See also `execa` package documentation
24
28
  * @example
25
29
  * const { run } = InterfaceUtils
26
30
  * await run('npm run test')
@@ -29,13 +33,12 @@ export declare class InterfaceUtils {
29
33
  * // Old way
30
34
  * await run('npm', [ 'run', 'test' ], { stdio: 'inherit' })
31
35
  */
32
- static run(command: string, opts?: ExecaOptions): ExecaResultPromise;
36
+ static run(bin: string, args?: string[] | ExecaOptions, opts?: ExecaOptions): ExecaResultPromise;
37
+ static run(bin: string, opts?: ExecaOptions): ExecaResultPromise;
33
38
  static run(bin: string, args: string[], opts?: ExecaOptions): ExecaResultPromise;
34
39
  /**
35
- * @param {number} [code] - Code for process.exit() (default: 0)
36
- * @returns {void}
37
- * @description
38
40
  * Exit process
41
+ * @param [code] - Code for process.exit() (default: 0)
39
42
  * @example
40
43
  * const { abort } = InterfaceUtils
41
44
  * abort() // => exit process with code 0
@@ -43,12 +46,11 @@ export declare class InterfaceUtils {
43
46
  */
44
47
  static abort(code?: number): void;
45
48
  /**
49
+ * Demand confirmation with prompts native util. If not confirmed, it will automatically abort the script.
46
50
  * @param question - A prompt question object
47
51
  * @param options - A prompt options object
48
- * @returns {Promise<boolean>} - True if confirmed
49
- * @description
50
- * Demand confirmation with prompts native util. If not confirmed, it will automatically abort the script.
51
52
  * @example
53
+ * const { confirm } = InterfaceUtils
52
54
  * confirm({ message: 'Confirm to continue' }) // Deny it will abort the script
53
55
  */
54
56
  static confirm(question: _prompts.PromptObject, options?: _prompts.Options): Promise<true | undefined>;
@@ -1,18 +1,37 @@
1
1
  import { default as indent } from 'indent-string';
2
2
  import { default as _stripAnsi } from 'strip-ansi';
3
+ import { LoggerInstance } from './types';
4
+ /**
5
+ * CLI - Output utils
6
+ * @group None
7
+ */
3
8
  export declare class OutputUtils {
4
9
  /**
5
10
  * To automatically increment step index
6
11
  * @ignore
7
12
  */
8
13
  private static stepsCache;
14
+ /**
15
+ * The logger instance
16
+ * @ignore
17
+ */
18
+ private static _loggerInstance;
9
19
  /**
10
20
  * Use `chalk` package to style output in console/stdout
11
21
  * @example
12
- * const { $style } = OutputUtils
13
- * console.log($style.green('Green text!')) // => '[32mGreen text![0m'
22
+ * const { $style, log } = OutputUtils
23
+ * log($style.green('Green text!')) // => '[32mGreen text![0m'
14
24
  */
15
25
  static $style: import('chalk').ChalkInstance;
26
+ /**
27
+ * Set logger instance
28
+ * @param loggerInstance - The logger instance to set
29
+ */
30
+ static setLoggerInstance(loggerInstance: LoggerInstance): void;
31
+ /**
32
+ * Get the logger instance
33
+ */
34
+ static getLoggerInstance(): LoggerInstance;
16
35
  /**
17
36
  * Format a message for console output
18
37
  * @param msg - The message to format
@@ -30,12 +49,11 @@ export declare class OutputUtils {
30
49
  indentChar?: string;
31
50
  }): string;
32
51
  /**
52
+ * Log message in console
33
53
  * @param msg - The message
34
54
  * @param options - (Optional) Options object
35
55
  * @param options.indent - How many repeat indent (see `indent-string` package)
36
56
  * @param options.indentChar - Indent character(s). If `options.indent` not provided, will be repeated only 1 time
37
- * @description
38
- * Log message in console
39
57
  * @example
40
58
  * const { log } = OutputUtils
41
59
  * log() // => blank line
@@ -43,9 +61,7 @@ export declare class OutputUtils {
43
61
  * log('To do:', { indent: 2 }) // => ' To do:'
44
62
  */
45
63
  static log(msg?: string, options?: Parameters<typeof this.formatOutputMessage>[1] & {
46
- loggerInstance?: {
47
- log: Function;
48
- };
64
+ loggerInstance?: LoggerInstance;
49
65
  }): void;
50
66
  /**
51
67
  * Display warning message
@@ -56,12 +72,11 @@ export declare class OutputUtils {
56
72
  */
57
73
  static warn(msg: string): void;
58
74
  /**
75
+ * Display error message. Throws `err` if provided.
59
76
  * @param msg - The message to display
60
77
  * @param err - If provided, throw the error
61
- * @description
62
- * Display error message. Throws `err` if provided.
63
78
  * @example
64
- * const { error } = require('@hperchec/juisy').utils
79
+ * const { error } = OutputUtils
65
80
  * error('No configuration file') // => '[31m⨉ ERROR: No configuration file[0m'
66
81
  * error('No configuration file', error) // => Log and throws error
67
82
  */
@@ -72,6 +87,7 @@ export declare class OutputUtils {
72
87
  * @param options - Options object
73
88
  * @param options.index - Custom index. If `null`, no index prepended to string
74
89
  * @example
90
+ * const { step } = OutputUtils
75
91
  * step('Important step') // => '● 1 - Important step'
76
92
  * step('Very important step') // => '● 2 - Very important step'
77
93
  */
@@ -84,7 +100,7 @@ export declare class OutputUtils {
84
100
  * @param options - Options object
85
101
  * @param options.last - Defines if it is the last substep
86
102
  * @example
87
- * const { substep } = require('@hperchec/juisy').utils
103
+ * const { substep } = OutputUtils
88
104
  * substep('Awesome substep') // => '├ Awesome substep'
89
105
  * substep('Last substep', { last: true }) // => '└ Last substep'
90
106
  */
@@ -92,13 +108,11 @@ export declare class OutputUtils {
92
108
  last?: boolean;
93
109
  }): void;
94
110
  /**
95
- * @param {string} message - Message to display
96
- * @param {Function} fct - The function to execute
97
- * @returns {Promise<void>}
98
- * @description
99
111
  * Wait function: display loading during 'fct' execution
112
+ * @param message - Message to display
113
+ * @param fct - The function to execute
100
114
  * @example
101
- * const { wait } = require('@hperchec/juisy').utils
115
+ * const { wait } = OutputUtils
102
116
  * await wait('Waiting', async () => {
103
117
  * // Do async logic
104
118
  * })
@@ -3,7 +3,16 @@ type PluginObject = {
3
3
  beforeCreate?: Plugin['beforeCreate'];
4
4
  created?: Plugin['created'];
5
5
  };
6
+ /**
7
+ * CLI - Plugin class
8
+ * @group None
9
+ */
6
10
  export declare class Plugin {
11
+ /**
12
+ * Creates a Plugin instance
13
+ * @param name - The unique name
14
+ * @param pluginObject - The plugin object
15
+ */
7
16
  constructor(name: string, pluginObject: PluginObject);
8
17
  /**
9
18
  * The plugin unique name
@@ -75,4 +75,12 @@ export type ExtractedUsage = {
75
75
  deprecated: boolean;
76
76
  }>;
77
77
  };
78
+ /**
79
+ * Extract command usage to create a command doclet from.
80
+ * @group None
81
+ * @param factory - The result of CLIFactory()
82
+ * @param recursive - Recursively extract child commands
83
+ * @param args - The args to pass (default: [''])
84
+ * @param locale - The locale (default: 'en')
85
+ */
78
86
  export declare function extractUsage(factory: Awaited<ReturnType<typeof CLIFactory>>, recursive?: boolean, args?: string[], locale?: string): Promise<CommandDoclet>;
@@ -30,3 +30,4 @@ export type * from './plugins/register-release-command/augment';
30
30
  export type * from './plugins/default-command-fallbacks/augment';
31
31
  export type * from './plugins/command-meta/augment';
32
32
  export type * from './plugins/private-commands/augment';
33
+ export type * from '../shims/shims';