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
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-docs-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-git-hooks-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-lint-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -2,6 +2,8 @@ import { GlobalSettings } from '../../types';
2
2
  import { SettingsLintMarkdown } from './types';
3
3
  /**
4
4
  * Resolve settings for 'lint' namespace
5
+ * @param settings - The lint settings object
6
+ * @group None
5
7
  */
6
8
  export default function resolveSettings(settings?: Required<GlobalSettings>['lint']): {
7
9
  default?: import('../..').UserProvidedConfigSetting<import("eslint").Linter.LegacyConfig | import("eslint").Linter.Config | import("eslint").Linter.Config[]>;
@@ -4,23 +4,19 @@
4
4
  */
5
5
  type MarkdownlintCLI2Config = {
6
6
  [key: string]: any;
7
- globs?: never;
8
7
  fix?: never;
9
8
  };
10
9
  /**
11
10
  * Object for root config in lint.markdown settings
11
+ * @group Types
12
12
  */
13
- export type SettingsLintMarkdown = Array<SettingsLintMarkdownRootConfig | SettingsLintMarkdownConfig>;
13
+ export type SettingsLintMarkdown = Array<SettingsLintMarkdownConfig>;
14
14
  /**
15
- * Object for root config in lint.markdown settings
15
+ * Object for config in lint.markdown settings
16
+ * @group Types
16
17
  */
17
- export type SettingsLintMarkdownRootConfig = {
18
+ export type SettingsLintMarkdownConfig = {
18
19
  config: string | MarkdownlintCLI2Config;
19
- };
20
- /**
21
- * Object for glob scoped config in lint.markdown settings
22
- */
23
- export type SettingsLintMarkdownConfig = SettingsLintMarkdownRootConfig & {
24
20
  globs?: string[];
25
21
  };
26
22
  export {};
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-release-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -1,3 +1,7 @@
1
1
  import { Plugin } from '../../Plugin';
2
+ /**
3
+ * Built-in plugin: 'built-in:register-test-command'
4
+ * @group None
5
+ */
2
6
  declare const _default: Plugin;
3
7
  export default _default;
@@ -142,4 +142,11 @@ engine: CLIEngine,
142
142
  * The default options to set
143
143
  */
144
144
  options: any) => false | CommandObject);
145
+ /**
146
+ * CLI engine logger instance interface
147
+ * @group Types
148
+ */
149
+ export interface LoggerInstance {
150
+ log: Function;
151
+ }
145
152
  export {};
@@ -1,10 +1,9 @@
1
1
  import { CommandObject, CLIEngine } from './types';
2
2
  /**
3
- * @ignore
4
- * @param target - The target builder
5
- * @param builder - The wrap
6
- * @description
7
3
  * Wrap command builder (target) with builder passed as second parameter
8
4
  * that will be called before target. Target can be undefined
5
+ * @param target - The target builder
6
+ * @param builder - The wrap
7
+ * @ignore
9
8
  */
10
9
  export declare function wrapCommandBuilder(target: CommandObject['builder'], builder: (cli: CLIEngine) => CLIEngine): (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
package/dist/eject.d.ts CHANGED
@@ -23,6 +23,7 @@ export type EjectOptions = {
23
23
  * Takes content as unique argument and must return string or a Promise that resolves a string
24
24
  * @param options.onError - The callback if an error occurs
25
25
  * @param options.onSuccess - The callback in of success
26
+ * @group None
26
27
  */
27
28
  export default function eject(
28
29
  /**
@@ -2,5 +2,6 @@ import { IPackageJson as PackageJson } from 'package-json-type';
2
2
  /**
3
3
  * Get package.json content
4
4
  * @returns The package.json content as object
5
+ * @group None
5
6
  */
6
7
  export default function getPackageInfo(): PackageJson;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Public API of juisy library
3
3
  * @module juisy
4
+ * @importTarget .
4
5
  * @author Hervé Perchec
5
6
  */
6
7
  import * as utils from './utils/misc';
@@ -10,8 +11,11 @@ export { default as getPackageInfo } from './get-package-info';
10
11
  export { defineGlobals, getProjectGlobals } from './project-globals';
11
12
  /**
12
13
  * @ignore
13
- */
14
+ */
14
15
  export { utils };
15
16
  export type * from './DataExporter';
16
17
  export type * from './eject';
17
18
  export type * from './project-globals';
19
+ export type * from './shims/shims';
20
+ declare const _default: {};
21
+ export default _default;
package/dist/index.js CHANGED
@@ -1,22 +1,100 @@
1
1
  /*!
2
- * juisy v2.1.0
2
+ * juisy v2.3.0
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
6
6
  import path$1, { dirname } from 'node:path';
7
- import { readdir, readFileSync } from 'node:fs';
7
+ import { pathToFileURL, fileURLToPath } from 'node:url';
8
+ import fs from 'fs-extra';
9
+ import { CLIFactory } from 'juisy/cli';
10
+ import { readdir } from 'node:fs/promises';
11
+ import { readdirSync, readFileSync } from 'node:fs';
8
12
  import { glob } from 'glob';
13
+ import { packageDirectorySync } from 'pkg-dir';
9
14
  import yaml from 'yaml';
10
15
  import { json2csv } from 'json-2-csv';
11
16
  import jstoxml from 'jstoxml';
12
- import fs from 'fs-extra';
13
- import { fileURLToPath, pathToFileURL } from 'node:url';
14
- import { packageDirectorySync } from 'pkg-dir';
15
17
  import log from 'loglevel';
16
18
  import { Templater } from 'juisy/templater';
17
19
  import dotenv from '@dotenvx/dotenvx';
18
20
  import deepmerge from 'deepmerge';
19
21
 
22
+ // export const DEFAULT_EXT_CACHE_PATH = './node_modules/.cache/juisy/extensions.json'
23
+ const DEFAULT_EXT_CACHE_PATH = './package.json';
24
+
25
+ /**
26
+ * Get the extensions locally added to juisy
27
+ * @param {string} extCachePath - The path to extensions cache file
28
+ * @returns {string[]} The extension names
29
+ */
30
+ function getExtensions (extCachePath = DEFAULT_EXT_CACHE_PATH) {
31
+ const absolutePath = path$1.isAbsolute(extCachePath)
32
+ ? extCachePath
33
+ : path$1.resolve(extCachePath);
34
+
35
+ // // If default, ensure file exists
36
+ // if (extCachePath === DEFAULT_EXT_CACHE_PATH
37
+ // && fs.existsSync(path.resolve('./node_modules'))
38
+ // && !fs.existsSync(absolutePath)
39
+ // ) {
40
+ // fs.outputFileSync(absolutePath, '[]')
41
+ // }
42
+
43
+ const content = fs.readFileSync(absolutePath, 'utf-8');
44
+ const extensionIds = JSON.parse(content).juisy?.extensions || [];
45
+ return extensionIds
46
+ }
47
+
48
+ /**
49
+ * Load an extension
50
+ * @param {string} id - The module name or relative/absolute path
51
+ */
52
+ async function loadExtension (id) {
53
+ // Module name or full path
54
+ const modPath = id.startsWith('.') // is relative?
55
+ ? path$1.resolve(id) // relative to process.cwd()
56
+ : id; // can be module name or absolute path
57
+
58
+ const mod = await import(path$1.isAbsolute(modPath)
59
+ ? pathToFileURL(modPath).toString()
60
+ : id);
61
+
62
+ return mod.extension || mod.default
63
+ }
64
+
65
+ /**
66
+ * Load the extensions
67
+ * @param {?string} extCachePath - The path to extensions cache file
68
+ */
69
+ async function loadExtensions (extCachePath) {
70
+ // Get extension identifiers
71
+ const extensionIds = getExtensions(extCachePath);
72
+
73
+ const extensions = [];
74
+
75
+ for (const id of extensionIds) {
76
+ const loaded = {
77
+ id,
78
+ extension: await loadExtension(id)
79
+ };
80
+ extensions.push(loaded);
81
+ //
82
+ if (loaded.extension.juisyBin) {
83
+ loaded.extension.juisyBin(CLIFactory);
84
+ }
85
+ }
86
+
87
+ return extensions
88
+ }
89
+
90
+ let isAlreadyBootstraped = false;
91
+ async function bootstrap(importMeta) {
92
+ await loadExtensions();
93
+ console.log("importMeta.url:", importMeta.url);
94
+ console.log("isAlreadyBootstraped ? ", isAlreadyBootstraped);
95
+ isAlreadyBootstraped = true;
96
+ }
97
+
20
98
  function getFileUrls(pattern, options) {
21
99
  const files = glob.sync(pattern, options || {});
22
100
  return files;
@@ -32,6 +110,22 @@ async function* getFiles(dir) {
32
110
  }
33
111
  }
34
112
  }
113
+ function getFilesSync(dir) {
114
+ const files = [];
115
+ const dirents = readdirSync(dir, { withFileTypes: true });
116
+ for (const dirent of dirents) {
117
+ const res = path$1.resolve(dir, dirent.name);
118
+ if (dirent.isDirectory()) {
119
+ files.push(...getFilesSync(res));
120
+ } else {
121
+ files.push(res);
122
+ }
123
+ }
124
+ return files;
125
+ }
126
+ function getRootDir() {
127
+ return packageDirectorySync();
128
+ }
35
129
  const path = {
36
130
  /**
37
131
  * Convert a path to win32 format (with `\\` separator)
@@ -64,11 +158,53 @@ const path = {
64
158
  return platform === "win32" ? path.toWin32(val) : path.toPosix(val);
65
159
  },
66
160
  /**
67
- * Util to resolve relative file path to root directory
161
+ * Check if the given path is win32 format
162
+ * @param val - The path to check
163
+ * @example
164
+ * utils.path.isWin32('a/posix/path') // => false
165
+ * utils.path.isWin32('C:\\a\\win32\\absolute\\path') // => true
166
+ * utils.path.isWin32('a/mixed\\path') // => true
167
+ */
168
+ isWin32(val) {
169
+ return /^[a-zA-Z]:/.test(val) || val.includes("\\");
170
+ },
171
+ /**
172
+ * Check if the given path is posix format
173
+ * @param val - The path to check
174
+ * @example
175
+ * utils.path.isPosix('a/posix/path') // => true
176
+ * utils.path.isPosix('C:\\a\\win32\\absolute\\path') // => false
177
+ * utils.path.isPosix('a/mixed\\path') // => false
178
+ */
179
+ isPosix(val) {
180
+ return !path.isWin32(val);
181
+ },
182
+ /**
183
+ * Normalize a path depending on base format
184
+ * @param val - The path to normalize
185
+ * @example
186
+ * utils.path.normalize('a/Posix/path') // => 'a/Posix/path'
187
+ * utils.path.normalize('C:\\a\\Win32\\Absolute\\path\\') // => 'c:\a\win32\absolute\path'
188
+ * utils.path.normalize('a/Mixed\\Path') // => 'a\mixed\path'
189
+ */
190
+ normalize(val) {
191
+ let normalized;
192
+ if (path.isWin32(val)) {
193
+ normalized = path$1.win32.normalize(val).toLowerCase();
194
+ } else {
195
+ normalized = path$1.posix.normalize(val);
196
+ }
197
+ if ((normalized.endsWith("/") || normalized.endsWith("\\")) && normalized.length > 1) {
198
+ normalized = normalized.slice(0, -1);
199
+ }
200
+ return normalized;
201
+ },
202
+ /**
203
+ * Util to resolve a relative file path
68
204
  * @param from - The "from" absolute file path
69
205
  * @param to - The "to" absolute file path
70
206
  * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
71
- * @returns The resolved relative path to root directory
207
+ * @returns The resolved relative path
72
208
  * @example
73
209
  * const base = 'C:\\Users\\JohnDoe\\Documents\\Projects\\MyProject'
74
210
  *
@@ -79,14 +215,51 @@ const path = {
79
215
  resolveRel(from, to, separator) {
80
216
  const relativePath = path$1.relative(from, to);
81
217
  return separator ? separator === "posix" ? path.toPosix(relativePath) : path.toWin32(relativePath) : path.toOsFormat(relativePath);
218
+ },
219
+ /**
220
+ * Util to resolve relative file path from root directory
221
+ * @param to - The absolute file path
222
+ * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
223
+ * @returns The resolved relative path from root directory
224
+ */
225
+ resolveRelFromRoot(to, separator) {
226
+ return path.resolveRel(getRootDir(), to, separator);
227
+ },
228
+ /**
229
+ * Util to resolve absolute file path from root directory
230
+ * @param to - The relative file path
231
+ * @param separator - (Optional) The separator type: can be `"posix"` or `"win32"`
232
+ * @returns The resolved absolute path from root directory
233
+ */
234
+ resolveAbsFromRoot(to, separator) {
235
+ const absolutePath = path$1.join(getRootDir(), to);
236
+ return separator ? separator === "posix" ? path.toPosix(absolutePath) : path.toWin32(absolutePath) : path.toOsFormat(absolutePath);
237
+ },
238
+ /**
239
+ * Util function to compare two file paths
240
+ * @param a - The first file path to compare
241
+ * @param b - The second file path to compare
242
+ * @returns True if the two paths are the same
243
+ * @example
244
+ * utils.path.isSameAs('src/index.ts', 'src\\index.ts') // true
245
+ * utils.path.isSameAs('../src/index.ts', '..\\src\\index.ts') // true
246
+ * utils.path.isSameAs('C:\\a\\Win32\\Absolute\\path\\', 'c:/a/Win32/Absolute/path') // true
247
+ * utils.path.isSameAs('C:\\a\\Win32\\Absolute\\path\\', '/a/Win32/Absolute/path')// false
248
+ * utils.path.isSameAs('/a/posix/absolute/path', '/a/posix/absolute/path/../../absolute/path') // true
249
+ * utils.path.isSameAs('/a/posix/absolute/path', '/a/Posix/Absolute/path') // false
250
+ */
251
+ isSameAs(a, b) {
252
+ return path.normalize(path.toPosix(a)) === path.normalize(path.toPosix(b));
82
253
  }
83
254
  };
84
255
 
85
256
  const misc = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
86
- __proto__: null,
87
- getFileUrls,
88
- getFiles,
89
- path
257
+ __proto__: null,
258
+ getFileUrls,
259
+ getFiles,
260
+ getFilesSync,
261
+ getRootDir,
262
+ path
90
263
  }, Symbol.toStringTag, { value: 'Module' }));
91
264
 
92
265
  const xml = jstoxml.toXML;
@@ -185,7 +358,10 @@ async function ejectFile(from, to, identifier = null, options) {
185
358
  const write = await fs.exists(to) ? force : true;
186
359
  if (write) {
187
360
  const template = await fs.readFile(from, { encoding: "utf8" });
188
- const content = await templater.render(template, typeof templateData === "function" ? await templateData(identifier) : templateData);
361
+ const content = await templater.render(
362
+ template,
363
+ typeof templateData === "function" ? await templateData(identifier) : templateData
364
+ );
189
365
  const processedContent = await processor(content, identifier);
190
366
  await fs.ensureFile(to);
191
367
  await fs.writeFile(to, processedContent);
@@ -300,4 +476,7 @@ async function getProjectGlobals(filePath = "./project.globals.js") {
300
476
  return (await import(pathToFileURL(path$1.resolve(filePath)))).default;
301
477
  }
302
478
 
303
- export { DataExporter, defineGlobals, eject, getPackageInfo, getProjectGlobals, misc as utils };
479
+ bootstrap(import.meta);
480
+ const index = {};
481
+
482
+ export { DataExporter, index as default, defineGlobals, eject, getPackageInfo, getProjectGlobals, misc as utils };
@@ -38,6 +38,7 @@ export type DefineGlobalsBuilder<T extends Record<string, any>> = (ctx: {
38
38
  * @param config - The config object
39
39
  * @param builder - The builder function
40
40
  * @returns The computed globals object
41
+ * @group None
41
42
  */
42
43
  export declare function defineGlobals<CustomGlobals extends Record<string, any>>(config: {
43
44
  env?: {
@@ -49,5 +50,6 @@ export declare function defineGlobals<CustomGlobals extends Record<string, any>>
49
50
  * Get project globals
50
51
  * @param filePath - The filePath. Default is `'./project.globals.js'`
51
52
  * @returns The resolved project globals object
53
+ * @group None
52
54
  */
53
55
  export declare function getProjectGlobals(filePath?: string): Promise<DefaultProjectGlobals & Record<string, string | Record<string, unknown> | undefined>>;