juisy 3.0.0-beta.3 → 3.0.0-beta.4

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 (36) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +25 -12
  3. package/bin/cli/cli.js +28 -28
  4. package/bin/cli/cmds/index.js +11 -11
  5. package/bin/cli/cmds/public/print-globals.js +27 -27
  6. package/bin/cli/index.js +9 -9
  7. package/bin/scripts/prepare.js +22 -22
  8. package/dist/DataExporter.d.ts +133 -34
  9. package/dist/ReadmeTemplater-DobSI9Um.js +373 -0
  10. package/dist/bootstrap.d.ts +11 -3
  11. package/dist/bootstrap.js +15 -11
  12. package/dist/cli/Command.d.ts +4 -4
  13. package/dist/cli/OutputUtils.d.ts +1 -1
  14. package/dist/cli/cache-dir.d.ts +15 -0
  15. package/dist/cli/index.js +341 -148
  16. package/dist/cli/plugins/register-changelog-command/augment.d.ts +52 -34
  17. package/dist/cli/plugins/register-changelog-command/resolve-changelog-options.d.ts +19 -0
  18. package/dist/cli/plugins/register-release-command/build-temp-config.d.ts +13 -0
  19. package/dist/cli/plugins/register-release-command/release-args.d.ts +7 -0
  20. package/dist/cli/plugins/register-release-command/resolve-release-config.d.ts +40 -0
  21. package/dist/cli/serialize-cjs-module.d.ts +15 -0
  22. package/dist/cli/types.d.ts +1 -1
  23. package/dist/extensions.d.ts +33 -9
  24. package/dist/extensions.js +87 -20
  25. package/dist/get-package-info-CGDJsCsN.js +15 -0
  26. package/dist/index.d.ts +5 -1
  27. package/dist/index.js +109 -23
  28. package/dist/project-globals.d.ts +8 -2
  29. package/dist/templater/Templater.d.ts +1 -1
  30. package/dist/templater/index.d.ts +2 -2
  31. package/dist/templater/index.js +2 -335
  32. package/dist/templater/markdown-templater/ReadmeTemplater.d.ts +31 -2
  33. package/dist/templater/markdown-templater/index.d.ts +12 -1
  34. package/package.json +24 -29
  35. package/skills/juisy/SKILL.md +97 -0
  36. package/skills/juisy/references/recipes.md +85 -0
@@ -1,30 +1,49 @@
1
- import { default as ConventionalChangelogConfigSpec } from 'conventional-changelog-config-spec';
2
1
  import { GetSemverTagsParams, GetCommitsParams } from '@conventional-changelog/git-client';
3
2
  import { Preset as CCBumperPreset } from 'conventional-recommended-bump';
4
3
  declare module '../../types' {
5
4
  interface GlobalSettings {
6
5
  /**
7
- * conventional-changelog-cli configuration. All options are mapped using long name and converted to camelcase.
6
+ * conventional-changelog CLI configuration. All options are mapped using long name and converted to camelcase.
8
7
  * Use the additional `onReleaseConfig` to pass options to the
9
- * [@release-it/conventional-changelog](https://github.com/release-it/conventional-changelog) plugin.
10
- * @see https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli
8
+ * [\@release-it/conventional-changelog](https://github.com/release-it/conventional-changelog) plugin.
9
+ * @see https://conventional-changelog.js.org/conventional-changelog/cli/#options
11
10
  * @see https://github.com/release-it/conventional-changelog
12
11
  */
13
12
  changelog?: {
14
13
  /**
15
- * Pass or override specific options for @release-it/conventional-changelog plugin.
14
+ * Pass or override specific options for \@release-it/conventional-changelog plugin.
16
15
  * Default inherits from parent config.
17
16
  */
18
17
  onReleaseConfig?: {
19
- preset?: ConventionalChangelogConfigSpec.Config;
18
+ /**
19
+ * Changelog infile passed to \@release-it/conventional-changelog.
20
+ * Defaults to parent `changelog.infile`.
21
+ */
22
+ infile?: string;
23
+ /**
24
+ * Changelog header passed to \@release-it/conventional-changelog.
25
+ */
26
+ header?: string;
27
+ /**
28
+ * Template context object (not a filepath) for the release-it plugin.
29
+ */
30
+ context?: Record<string, unknown>;
31
+ /**
32
+ * Extra preset options merged into `{ name: changelog.preset }`.
33
+ */
34
+ preset?: Record<string, unknown>;
20
35
  tagOpts?: GetSemverTagsParams;
21
36
  commitsOpts?: GetCommitsParams;
37
+ /**
38
+ * Recommended-bump function. Juisy defaults to `async () => null`
39
+ * (conventional-changelog quirk) together with `ignoreRecommendedBump`.
40
+ */
22
41
  whatBump?: CCBumperPreset['whatBump'];
23
42
  /**
24
43
  * Use true to ignore the recommended bump, and use the version provided by release-it (command line argument or prompt).
25
44
  * Note that the changelog preview shows the recommended bump, as the desired version isn't known yet in the release-it process.
26
45
  * The infile will have the correct version.
27
- * Default value: false
46
+ * Default value: true (juisy default)
28
47
  */
29
48
  ignoreRecommendedBump?: boolean;
30
49
  /**
@@ -36,6 +55,10 @@ declare module '../../types' {
36
55
  */
37
56
  strictSemVer?: boolean;
38
57
  };
58
+ /**
59
+ * --preset: Preset that defines how commits are parsed and grouped.
60
+ */
61
+ preset?: 'angular' | 'conventionalcommits';
39
62
  /**
40
63
  * --infile: Read the CHANGELOG from this file
41
64
  */
@@ -46,31 +69,27 @@ declare module '../../types' {
46
69
  */
47
70
  outfile?: string;
48
71
  /**
49
- * --same-file: Outputting to the infile so you
50
- * don't need to specify the same file as outfile
51
- */
52
- sameFile?: true;
53
- /**
54
- * --preset: Name of the preset you want to use. Must be one of the following:
55
- * angular, atom, codemirror, conventionalcommits, ember, eslint, express, jquery or jshint
72
+ * --stdout: Print the result to stdout instead of writing a file
56
73
  */
57
- preset?: 'angular' | 'atom' | 'codemirror' | 'conventionalcommits' | 'ember' | 'eslint' | 'express' | 'jquery' | 'jshint';
74
+ stdout?: true;
58
75
  /**
59
76
  * --pkg: A filepath of where your package.json is located
60
77
  * Default is the closest package.json from cwd
61
78
  */
62
79
  pkg?: string;
63
80
  /**
64
- * --append: Should the newer release be appended to the older release
65
- * Default: false
81
+ * --append: Append newer releases below older ones instead of prepending.
66
82
  */
67
83
  append?: true;
68
84
  /**
69
- * --release-count: How many releases to be generated from the latest
70
- * If 0, the whole changelog will be regenerated and the outfile will be overwritten
71
- * Default: 1
85
+ * --release-count: How many releases to generate, counting from the latest.
86
+ * `0` regenerates the whole history and **overwrites** the outfile.
72
87
  */
73
88
  releaseCount?: number;
89
+ /**
90
+ * --first-release: Generate the changelog for the first time - equivalent to `--release-count 0`.
91
+ */
92
+ firstRelease?: true;
74
93
  /**
75
94
  * --skip-unstable: If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2
76
95
  */
@@ -80,31 +99,30 @@ declare module '../../types' {
80
99
  */
81
100
  outputUnreleased?: true;
82
101
  /**
83
- * --verbose: Verbose output. Use this for debugging
84
- * Default: false
102
+ * --tag-prefix: Tag prefix to consider when reading the tags
85
103
  */
86
- verbose?: string;
104
+ tagPrefix?: string;
87
105
  /**
88
- * --config: A filepath of your config script
89
- * Example of a config script: https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-cli/test/fixtures/config.cjs
106
+ * --lerna-package: Generate a changelog for a Lerna package, reading `name@1.0.0`-style tags.
90
107
  */
91
- config?: string;
108
+ lernaPackage?: string;
92
109
  /**
93
- * --context: A filepath of a json that is used to define template variables
110
+ * --commit-path: Generate a changelog scoped to a specific directory
94
111
  */
95
- context?: string;
112
+ commitPath?: string;
96
113
  /**
97
- * --lerna-package: Generate a changelog for a specific lerna package (:pkg-name@1.0.0)
114
+ * --config: Path to a config script that returns preset options. You can also pass an config object.
98
115
  */
99
- lernaPackage?: string;
116
+ config?: string | Record<string, unknown>;
100
117
  /**
101
- * --tag-prefix: Tag prefix to consider when reading the tags
118
+ * --context: A filepath of a json that is used to define template variables
102
119
  */
103
- tagPrefix?: string;
120
+ context?: string;
104
121
  /**
105
- * --commit-path: Generate a changelog scoped to a specific directory
122
+ * --verbose: Verbose output. Use this for debugging
123
+ * Default: false
106
124
  */
107
- commitPath?: string;
125
+ verbose?: string;
108
126
  };
109
127
  }
110
128
  }
@@ -0,0 +1,19 @@
1
+ import { ConventionalChangelog } from 'conventional-changelog';
2
+ export type ChangelogCommandSettings = {
3
+ onReleaseConfig?: unknown;
4
+ preset?: string | Record<string, unknown>;
5
+ config?: string | {
6
+ tags?: unknown;
7
+ commits?: unknown;
8
+ parser?: unknown;
9
+ writer?: unknown;
10
+ };
11
+ context?: string | Record<string, unknown>;
12
+ [key: string]: unknown;
13
+ };
14
+ /**
15
+ * Apply juisy changelog settings onto a ConventionalChangelog instance / CLI options
16
+ * when CLI argv did not already provide those fields.
17
+ * @ignore
18
+ */
19
+ export declare function applyChangelogSettingsDefaults(generator: Pick<ConventionalChangelog, 'loadPreset' | 'tags' | 'commits' | 'writer' | 'context'>, resolvedOptions: Record<string, unknown>, commandSettings: ChangelogCommandSettings): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Build the temporary release-it config object from juisy release + changelog settings.
3
+ * @param releaseSettings - Inline release-it settings (no `config` path)
4
+ * @param changelogSettings - Changelog settings including `onReleaseConfig`
5
+ * @returns release-it config with `@release-it/conventional-changelog` plugin block
6
+ * @ignore
7
+ */
8
+ export declare function buildReleaseItTempConfig(releaseSettings: Record<string, unknown>, changelogSettings: {
9
+ onReleaseConfig?: Record<string, unknown>;
10
+ preset?: string;
11
+ infile?: string;
12
+ context?: string | Record<string, unknown>;
13
+ }): Record<string, unknown>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Return CLI tokens after a given command name (pass-through for wrapped tools).
3
+ * @param tokens - Argv tokens without the node/bin prefix (e.g. hideBin result)
4
+ * @param command - Command name to search (e.g. `release`)
5
+ * @ignore
6
+ */
7
+ export declare function getArgsAfterCommand(tokens: string[], command: string): string[];
@@ -0,0 +1,40 @@
1
+ export type ReleaseSettings = Record<string, unknown> & {
2
+ config?: string;
3
+ };
4
+ export type ChangelogSettingsForRelease = {
5
+ onReleaseConfig?: Record<string, unknown>;
6
+ preset?: string;
7
+ infile?: string;
8
+ context?: string | Record<string, unknown>;
9
+ };
10
+ export type ResolvedReleaseItInvocation = {
11
+ mode: 'existing-config';
12
+ /**
13
+ * Extra CLI args to prepend (e.g. `--config path` from juisy settings).
14
+ */
15
+ configArgs: string[];
16
+ tempConfig?: undefined;
17
+ } | {
18
+ mode: 'temp-config';
19
+ configArgs: string[];
20
+ tempConfig: Record<string, unknown>;
21
+ };
22
+ /**
23
+ * Detect whether a dedicated release-it config already exists.
24
+ * @param cwd - Working directory to search
25
+ * @param packageJsonHasReleaseIt - Whether `package.json` defines `"release-it"`
26
+ * @ignore
27
+ */
28
+ export declare function hasExistingReleaseItConfig(cwd: string, packageJsonHasReleaseIt: boolean): boolean;
29
+ /**
30
+ * Resolve how juisy should invoke release-it (existing config vs temp `.cjs`).
31
+ * @param options - Inputs from package metadata + juisy settings
32
+ * @ignore
33
+ */
34
+ export declare function resolveReleaseItInvocation(options: {
35
+ cwd?: string;
36
+ packageJsonHasReleaseIt: boolean;
37
+ releaseSettings: ReleaseSettings;
38
+ changelogSettings: ChangelogSettingsForRelease;
39
+ tempConfigFilePath: string;
40
+ }): ResolvedReleaseItInvocation;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Serialize a JS value so it can be embedded in a CommonJS module source.
3
+ * Functions are written via `.toString()` (needed for release-it temp configs).
4
+ * @param value - Any JSON-like value, possibly containing functions
5
+ * @returns Source fragment (not a full module)
6
+ * @ignore
7
+ */
8
+ export declare function serializeJsValue(value: unknown): string;
9
+ /**
10
+ * Build a CommonJS module source that exports `value`.
11
+ * @param value - Module export value
12
+ * @returns Full `.cjs` file contents
13
+ * @ignore
14
+ */
15
+ export declare function serializeCjsModule(value: unknown): string;
@@ -111,7 +111,7 @@ export interface CommandObject {
111
111
  /** string used as the description for the command in help text, use `false` for a hidden command */
112
112
  describe: YargsCommandModule['describe'];
113
113
  /** a function which will be passed the parsed argv. */
114
- handler: YargsCommandModule['handler'];
114
+ handler: (argv: CommandHandlerArgs, positionals: Record<string, any>, options: Record<string, any>) => (void | Promise<void>);
115
115
  /** object declaring the options the command accepts, or a function accepting and returning a yargs instance */
116
116
  builder: (cli: CLIEngine) => CLIEngine | PromiseLike<CLIEngine>;
117
117
  middlewares?: MiddlewareFunction[];
@@ -1,26 +1,50 @@
1
1
  import { CLIFactory as _CLIFactory } from './cli/index.ts';
2
2
  /**
3
- * Juisy extension object
3
+ * Juisy extension object.
4
+ *
5
+ * Extensions are loaded by the **`juisy` bin** from `package.json#juisy.extensions`
6
+ * (via internal bootstrap). Authors typically export this shape as `extension`
7
+ * or as the module `default`.
8
+ *
9
+ * For a **project CLI** (`bin/cli`), prefer `CLIFactory.use(cliPlugin)` instead of
10
+ * relying on auto-loading.
4
11
  */
5
12
  export interface Extension {
6
13
  /**
7
- * Extends feature of the main juisy bin
8
- * @param CLIFactory - {@link _CLIFactory CLIFactory}
14
+ * Extends the main `juisy` bin by registering CLI plugins on {@link _CLIFactory}.
15
+ * @param CLIFactory - Shared {@link _CLIFactory CLIFactory} singleton
9
16
  */
10
17
  juisyBin?: (CLIFactory: typeof _CLIFactory) => void;
11
18
  }
12
19
  /**
13
- * Get the extensions locally added to juisy
14
- * @param pkgJsonPath - The path to package.json file
15
- * @returns The extension names
20
+ * Resolve the absolute path to the package.json used for `juisy.extensions`.
21
+ * @param pkgJsonPath - Explicit path; when omitted, walks up from `cwd` via `pkg-dir`
22
+ * @internal
23
+ */
24
+ export declare function resolveExtensionsPackageJsonPath(pkgJsonPath?: string): string;
25
+ /**
26
+ * Read `juisy.extensions` from a package.json.
27
+ * @param pkgJsonPath - Optional explicit package.json path (default: nearest package root)
28
+ * @returns Extension module ids (npm names or relative/absolute paths)
29
+ * @internal
16
30
  */
17
31
  export declare function getExtensions(pkgJsonPath?: string): string[];
18
32
  /**
19
- * Get the loaded extensions
33
+ * Snapshot of extensions loaded in this process.
34
+ * @internal
20
35
  */
21
36
  export declare function getLoadedExtensions(): Record<string, Extension>;
22
37
  /**
23
- * Load the extensions
24
- * @param pkgJsonPath - The path to extensions cache file
38
+ * Load extensions declared in package.json and run each `juisyBin` hook once.
39
+ *
40
+ * Used by the internal `juisy` bin bootstrap — not part of the public runtime API.
41
+ *
42
+ * @param pkgJsonPath - Optional explicit package.json path
43
+ * @internal
25
44
  */
26
45
  export declare function loadExtensions(pkgJsonPath?: string): Promise<Record<string, Extension>>;
46
+ /**
47
+ * Clear the in-process extension registry (unit tests).
48
+ * @internal
49
+ */
50
+ export declare function resetLoadedExtensions(): void;
@@ -1,44 +1,111 @@
1
1
  /*!
2
- * juisy v3.0.0-beta.3
2
+ * juisy v3.0.0-beta.4
3
3
  * Copyright © 2022-Present Hervé Perchec
4
4
  */
5
5
 
6
6
  import path from 'node:path';
7
7
  import { pathToFileURL } from 'node:url';
8
8
  import fs from 'fs-extra';
9
+ import { packageDirectorySync } from 'pkg-dir';
9
10
  import { CLIFactory } from 'juisy/cli';
10
11
 
11
12
  const loadedExtensions = /* @__PURE__ */ new Map();
12
- function getExtensions(pkgJsonPath = "./package.json") {
13
- const absolutePath = path.isAbsolute(pkgJsonPath) ? pkgJsonPath : path.resolve(pkgJsonPath);
13
+ function resolveExtensionsPackageJsonPath(pkgJsonPath) {
14
+ if (pkgJsonPath) {
15
+ return path.isAbsolute(pkgJsonPath) ? pkgJsonPath : path.resolve(process.cwd(), pkgJsonPath);
16
+ }
17
+ const pkgRoot = packageDirectorySync({ cwd: process.cwd() });
18
+ if (!pkgRoot) {
19
+ throw new Error("[juisy] Unable to locate a package.json from the current working directory");
20
+ }
21
+ return path.join(pkgRoot, "package.json");
22
+ }
23
+ function getExtensions(pkgJsonPath) {
24
+ const absolutePath = resolveExtensionsPackageJsonPath(pkgJsonPath);
25
+ if (!fs.existsSync(absolutePath)) {
26
+ throw new Error(`[juisy] package.json not found at "${absolutePath}"`);
27
+ }
14
28
  const content = fs.readFileSync(absolutePath, "utf-8");
15
- const extensionIds = JSON.parse(content).juisy?.extensions || [];
16
- return extensionIds;
29
+ let parsed;
30
+ try {
31
+ parsed = JSON.parse(content);
32
+ } catch (err) {
33
+ throw new Error(
34
+ `[juisy] Invalid JSON in "${absolutePath}": ${err instanceof Error ? err.message : String(err)}`,
35
+ { cause: err }
36
+ );
37
+ }
38
+ const raw = parsed.juisy?.extensions;
39
+ if (raw === void 0) {
40
+ return [];
41
+ }
42
+ if (!Array.isArray(raw) || raw.some((id) => typeof id !== "string")) {
43
+ throw new Error(
44
+ `[juisy] "juisy.extensions" in "${absolutePath}" must be an array of strings`
45
+ );
46
+ }
47
+ return raw;
17
48
  }
18
49
  function getLoadedExtensions() {
19
50
  const extensions = {};
20
- for (const id of loadedExtensions.keys()) {
21
- extensions[id] = loadedExtensions.get(id);
51
+ for (const [id, extension] of loadedExtensions) {
52
+ extensions[id] = extension;
22
53
  }
23
54
  return extensions;
24
55
  }
25
- async function loadExtension(id) {
26
- const modPath = id.startsWith(".") ? path.resolve(id) : id;
27
- const mod = await (path.isAbsolute(modPath) ? import(pathToFileURL(modPath).toString()) : import(id));
28
- return mod.extension || mod.default;
56
+ function assertExtension(candidate, id) {
57
+ if (candidate === null || typeof candidate !== "object") {
58
+ throw new Error(
59
+ `[juisy] Extension "${id}" must export an object as \`extension\` or \`default\``
60
+ );
61
+ }
62
+ const juisyBin = candidate.juisyBin;
63
+ if (juisyBin !== void 0 && typeof juisyBin !== "function") {
64
+ throw new Error(
65
+ `[juisy] Extension "${id}" has invalid "juisyBin" (expected a function)`
66
+ );
67
+ }
29
68
  }
30
- async function loadExtensions(pkgJsonPath = "./package.json") {
31
- const extensionIds = getExtensions(pkgJsonPath);
69
+ async function loadExtension(id, baseDir) {
70
+ let importTarget;
71
+ if (path.isAbsolute(id)) {
72
+ importTarget = pathToFileURL(id).href;
73
+ } else if (id.startsWith(".")) {
74
+ importTarget = pathToFileURL(path.resolve(baseDir, id)).href;
75
+ } else {
76
+ importTarget = id;
77
+ }
78
+ let mod;
79
+ try {
80
+ mod = await import(importTarget);
81
+ } catch (err) {
82
+ throw new Error(
83
+ `[juisy] Failed to load extension "${id}": ${err instanceof Error ? err.message : String(err)}`,
84
+ { cause: err }
85
+ );
86
+ }
87
+ const candidate = mod.extension ?? mod.default;
88
+ assertExtension(candidate, id);
89
+ return candidate;
90
+ }
91
+ async function loadExtensions(pkgJsonPath) {
92
+ const absolutePkgJson = resolveExtensionsPackageJsonPath(pkgJsonPath);
93
+ const baseDir = path.dirname(absolutePkgJson);
94
+ const extensionIds = getExtensions(absolutePkgJson);
32
95
  for (const id of extensionIds) {
33
- if (!loadedExtensions.has(id)) {
34
- const extension = await loadExtension(id);
35
- loadedExtensions.set(id, extension);
36
- if (extension.juisyBin) {
37
- extension.juisyBin(CLIFactory);
38
- }
96
+ if (loadedExtensions.has(id)) {
97
+ continue;
98
+ }
99
+ const extension = await loadExtension(id, baseDir);
100
+ loadedExtensions.set(id, extension);
101
+ if (extension.juisyBin) {
102
+ extension.juisyBin(CLIFactory);
39
103
  }
40
104
  }
41
105
  return getLoadedExtensions();
42
106
  }
107
+ function resetLoadedExtensions() {
108
+ loadedExtensions.clear();
109
+ }
43
110
 
44
- export { getExtensions, getLoadedExtensions, loadExtensions };
111
+ export { getExtensions, getLoadedExtensions, loadExtensions, resetLoadedExtensions, resolveExtensionsPackageJsonPath };
@@ -0,0 +1,15 @@
1
+ /*!
2
+ * juisy v3.0.0-beta.4
3
+ * Copyright © 2022-Present Hervé Perchec
4
+ */
5
+
6
+ import path from 'node:path';
7
+ import { readFileSync } from 'node:fs';
8
+ import { packageDirectorySync } from 'pkg-dir';
9
+
10
+ function getPackageInfo() {
11
+ const pkgPath = path.resolve(packageDirectorySync(), "./package.json");
12
+ return JSON.parse(readFileSync(pkgPath, "utf8"));
13
+ }
14
+
15
+ export { getPackageInfo as g };
package/dist/index.d.ts CHANGED
@@ -10,7 +10,11 @@ export { default as getPackageInfo } from './get-package-info';
10
10
  export { defineGlobals, getProjectGlobals } from './project-globals';
11
11
  export type * from './DataExporter';
12
12
  export type * from './eject';
13
- export type * from './extensions';
13
+ /**
14
+ * Public type for extension authors. Runtime loader (`loadExtensions`, bootstrap)
15
+ * stays internal to the `juisy` bin — do not re-export it from this barrel.
16
+ */
17
+ export type { Extension } from './extensions';
14
18
  export type * from './project-globals';
15
19
  export type * from './shims/shims';
16
20
  declare const _default: {};