load-populate-files 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  <div style="text-align:center">
2
2
 
3
3
  # load-populate-files
4
+
4
5
  Load and dynamically populate file content based on a single file's config.
5
6
 
6
7
  [![npm package](https://badge.fury.io/js/load-populate-files.svg)](https://www.npmjs.com/package/load-populate-files)
@@ -71,10 +72,10 @@ Loads the config exported at `params.filePath` and passes it to [`populateFiles(
71
72
 
72
73
  **Parameters**
73
74
 
74
- | Parameter | Type | Default | Description |
75
- |-----------|------|---------|-------------|
76
- | `params.filePath` | `string` | — | Required. Path to the config module, resolved from `options.cwd`. When using the CLI, pass as `--file-path`. |
77
- | `options` | `object` | `{}` | Optional. See [options](#options) below. |
75
+ | Parameter | Type | Default | Description |
76
+ | ----------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------ |
77
+ | `params.filePath` | `string` | — | Required. Path to the config module, resolved from `options.cwd`. When using the CLI, pass as `--file-path`. |
78
+ | `options` | `object` | `{}` | Optional. See [options](#options) below. |
78
79
 
79
80
  **Returns** `Promise<PopulationResponse[]>`, from `populateFiles()`.
80
81
 
@@ -84,15 +85,15 @@ Loads the config exported at `params.filePath` and passes it to [`populateFiles(
84
85
 
85
86
  Options are passed through to the underlying `populateFiles()` call. They are also available as CLI flags.
86
87
 
87
- | Property | CLI flag | Type | Default | Description |
88
- |----------|----------|------|---------|-------------|
89
- | `check` | `--ci`, `--check` (`--no-ci` to write in CI) | `boolean` | `true` in CI, else `false` | If `true`, fails if writing a file would change its content. Useful for verifying version-controlled files are up to date before deployment. |
90
- | `dryRun` | `--dry-run` | `boolean` | `false` | If `true`, does not write any files regardless of changes. Can still fail if `check` is `true`. |
91
- | `cwd` | `--cwd` | `string \| URL` | `process.cwd()` | Used as the current working directory for `filePath` and the `targetDir` and `manifest` paths. Must be an existing directory. |
92
- | `targetDir` | `--target-dir`, `-t` | `string` | `'.'` | Target directory for resolving output file paths. Resolved relative to `cwd`. |
93
- | `clean` | `--clean` | `boolean` | `false` | If `true`, removes files in `targetDir` that were not generated (with `manifest`, only files it lists). In `--ci` mode, fails instead of removing. |
94
- | `force` | `--force` | `boolean` | `false` | Applies to `signed` files and the `manifest`. If `true`, overwrites files that were edited, are not signed or not listed, or are malformed. See [`populate-files`](https://www.npmjs.com/package/populate-files#signed-files). |
95
- | `manifest` | `--manifest` | `string` | — | Path of a manifest (relative to `cwd`) recording the generated files, to detect edits to any file type and `clean` only files it lists. See [`populate-files`](https://www.npmjs.com/package/populate-files#manifest). |
88
+ | Property | CLI flag | Type | Default | Description |
89
+ | ----------- | -------------------------------------------- | --------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
90
+ | `check` | `--ci`, `--check` (`--no-ci` to write in CI) | `boolean` | `true` in CI, else `false` | If `true`, fails if writing a file would change its content. Useful for verifying version-controlled files are up to date before deployment. |
91
+ | `dryRun` | `--dry-run` | `boolean` | `false` | If `true`, does not write any files regardless of changes. Can still fail if `check` is `true`. |
92
+ | `cwd` | `--cwd` | `string \| URL` | `process.cwd()` | Used as the current working directory for `filePath` and the `targetDir` and `manifest` paths. Must be an existing directory. |
93
+ | `targetDir` | `--target-dir`, `-t` | `string` | `'.'` | Target directory for resolving output file paths. Resolved relative to `cwd`. |
94
+ | `clean` | `--clean` | `boolean` | `false` | If `true`, removes files in `targetDir` that were not generated (with `manifest`, only files it lists). In `--ci` mode, fails instead of removing. |
95
+ | `force` | `--force` | `boolean` | `false` | Applies to `signed` files and the `manifest`. If `true`, overwrites files that were edited, are not signed or not listed, or are malformed. See [`populate-files`](https://www.npmjs.com/package/populate-files#signed-files). |
96
+ | `manifest` | `--manifest` | `string` | — | Path of a manifest (relative to `cwd`) recording the generated files, to detect edits to any file type and `clean` only files it lists. See [`populate-files`](https://www.npmjs.com/package/populate-files#manifest). |
96
97
 
97
98
  ## Types
98
99
 
package/bin.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- export { default } from './dist/bin.js';
3
+ export { default } from './dist/cli.js';
package/dist/cli.d.ts CHANGED
@@ -1,24 +1,13 @@
1
- import type { Main } from 'entry-script';
2
- import type { RegisterCommand } from './commands/lib/types.js';
1
+ import { EntryScript } from 'entry-script';
3
2
  /**
4
3
  * LoadPopulateFiles CLI. Run `./bin.mjs --help` for options.
5
- *
6
- * Uses `yargs` package for command line parsing and logic flow.
7
4
  */
8
- export declare class LoadPopulateFilesCli implements Main {
9
- #private;
10
- /**
11
- * @param commands - every command the CLI runs
12
- */
13
- constructor(commands: readonly RegisterCommand[]);
5
+ export default class Cli extends EntryScript {
14
6
  /**
15
7
  * Entry point to CLI script.
16
8
  *
17
- * Sets high level Yargs settings. Command/options logic is implemented in individual command modules.
18
- *
19
9
  * @param argv - process arguments
20
10
  */
21
- main(argv: string[]): Promise<void>;
11
+ static main(argv: string[]): Promise<void>;
22
12
  }
23
- export declare const loadPopulateFilesCliBinding: import("haywire").Binding<import("haywire").OutputHaywireId<import("haywire").HaywireId<LoadPopulateFilesCli, typeof LoadPopulateFilesCli, null, false, false, false, false, false>>, [import("haywire").HaywireId<RegisterCommand, null, null, true, false, false, false, false>], false>;
24
13
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -1,18 +1,25 @@
1
+ import { isCI } from 'ci-info';
1
2
  import yargs from 'yargs';
2
- import { bind } from 'haywire';
3
- import { commandId } from './commands/lib/types.js';
4
- export class LoadPopulateFilesCli {
5
- #commands;
6
- constructor(commands){
7
- this.#commands = commands;
3
+ import { EntryScript } from "entry-script";
4
+ import { loadAndPopulateFiles } from './lib/load-populate-files.js';
5
+ const yargsOutput = (e, _argv, log)=>{
6
+ if (e) {
7
+ process.exitCode = 1;
8
+ if (log) {
9
+ console.error(log);
10
+ }
11
+ } else if (log) {
12
+ console.log(log);
8
13
  }
9
- async main(argv) {
14
+ };
15
+ export default class Cli extends EntryScript {
16
+ static async main(argv) {
10
17
  const packageJson = await import('../package.json', {
11
18
  with: {
12
19
  type: 'json'
13
20
  }
14
21
  });
15
- let cli = yargs().scriptName('load-populate-files').option({
22
+ await yargs().scriptName('load-populate-files').option({
16
23
  cwd: {
17
24
  type: 'string',
18
25
  default: '.',
@@ -24,25 +31,54 @@ export class LoadPopulateFilesCli {
24
31
  describe: 'Target directory for resolving output file paths. Defaults to resolved cwd.',
25
32
  alias: 't'
26
33
  }
27
- }).strict().help().alias('help', 'info').version(packageJson.default.version);
28
- for (const register of this.#commands){
29
- cli = register(cli);
30
- }
31
- await cli.parseAsync(argv, {}, LoadPopulateFilesCli.#yargsOutput);
32
- }
33
- static #yargsOutput(e, _argv, log) {
34
- if (e) {
35
- process.exitCode = 1;
36
- if (log) {
37
- console.error(log);
38
- }
39
- } else if (log) {
40
- console.log(log);
41
- }
34
+ }).strict().help().alias('help', 'info').version(packageJson.default.version).command([
35
+ '$0',
36
+ 'load-populate-files'
37
+ ], 'Read pre-generated content and write to file', (command)=>command.options({
38
+ filePath: {
39
+ describe: 'File that exports data content to populate',
40
+ type: 'string',
41
+ required: true
42
+ },
43
+ ci: {
44
+ describe: 'Fail if file is not up to date. Implies --dry-run',
45
+ type: 'boolean',
46
+ default: isCI,
47
+ alias: 'check'
48
+ },
49
+ dryRun: {
50
+ describe: 'Do not write file',
51
+ type: 'boolean',
52
+ default: false
53
+ },
54
+ clean: {
55
+ describe: 'Remove files in --target-dir that were not generated. In --ci mode, fail instead of removing.',
56
+ type: 'boolean',
57
+ default: false
58
+ },
59
+ force: {
60
+ describe: 'Overwrite signed files even if they were edited, are not signed, or would lose manual sections',
61
+ type: 'boolean',
62
+ default: false
63
+ },
64
+ manifest: {
65
+ describe: 'Record generated files in this manifest (relative to --cwd), to detect edits to them and only --clean files it lists',
66
+ type: 'string'
67
+ }
68
+ }).strict(), async (options)=>{
69
+ await loadAndPopulateFiles({
70
+ filePath: options.filePath
71
+ }, {
72
+ cwd: options.cwd,
73
+ targetDir: options.targetDir,
74
+ check: options.ci,
75
+ dryRun: options.dryRun,
76
+ clean: options.clean,
77
+ force: options.force,
78
+ manifest: options.manifest
79
+ });
80
+ }).parseAsync(argv, {}, yargsOutput);
42
81
  }
43
82
  }
44
- export const loadPopulateFilesCliBinding = bind(LoadPopulateFilesCli).withDependencies([
45
- commandId
46
- ]).withConstructorProvider();
47
83
 
48
84
  //# sourceMappingURL=cli.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "1.1.3",
4
- "description": "Load and dynamically populate file content",
3
+ "version": "1.1.5",
4
+ "description": "Load and dynamically populate file content based on a single file's config.",
5
5
  "engines": {
6
6
  "node": ">=24"
7
7
  },
@@ -38,32 +38,30 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "ci-info": "^4.4.0",
41
- "default-import": "^3.0.2",
42
- "entry-script": "^4.1.2",
43
- "haywire": "^2.0.4",
44
- "haywire-launcher": "^1.1.1",
45
- "juniper": "^2.5.0",
46
- "juniper-validator": "^0.5.1",
47
- "parse-cwd": "^2.0.3",
48
- "populate-files": "^1.2.0",
49
- "unknown-error": "^0.1.1",
41
+ "default-import": "^3.1.0",
42
+ "entry-script": "^4.2.0",
43
+ "juniper": "^2.7.0",
44
+ "juniper-validator": "^0.6.0",
45
+ "parse-cwd": "^2.1.0",
46
+ "populate-files": "^1.2.1",
47
+ "unknown-error": "^0.2.0",
50
48
  "yargs": "^18.2.0"
51
49
  },
52
50
  "devDependencies": {
53
- "@biomejs/biome": "^2.5.14",
51
+ "@biomejs/biome": "^2.6.4",
54
52
  "@leyman/eslint-config": "^0.0.1",
55
53
  "@leyman/expect": "^0.0.1",
56
54
  "@swc/cli": "^0.8.1",
57
- "@swc/core": "^1.16.18",
55
+ "@swc/core": "^1.16.20",
58
56
  "@types/mocha": "^10.0.10",
59
- "@types/node": "^24.19.0",
57
+ "@types/node": "^24.19.2",
60
58
  "@types/yargs": "^17.0.35",
61
59
  "@typescript/native": "npm:typescript@^7.0.2",
62
60
  "c8": "^12.0.0",
63
61
  "eslint": "^10.13.0",
64
- "generated-signature": "^0.1.3",
62
+ "generated-signature": "^0.2.0",
65
63
  "mocha": "^12.0.3",
66
- "mocha-chain": "^1.0.2",
64
+ "mocha-chain": "^1.1.0",
67
65
  "tmp-promise": "^3.0.3",
68
66
  "typescript": "npm:@typescript/typescript6@^6.0.2"
69
67
  },
package/dist/bin.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare const _default: import("haywire-launcher").WrapperMain;
2
- export default _default;
3
- //# sourceMappingURL=bin.d.ts.map
package/dist/bin.js DELETED
@@ -1,7 +0,0 @@
1
- import { identifier } from 'haywire';
2
- import { launch } from 'haywire-launcher';
3
- import { LoadPopulateFilesCli } from './cli.js';
4
- import { cliContainer } from './container.js';
5
- export default launch(cliContainer, identifier(LoadPopulateFilesCli));
6
-
7
- //# sourceMappingURL=bin.js.map
@@ -1,20 +0,0 @@
1
- import type { Argv, CommandModule } from 'yargs';
2
- export interface LoadPopulateFilesCommandInput {
3
- cwd: string;
4
- targetDir: string;
5
- }
6
- export type Command<ExtendedInput extends LoadPopulateFilesCommandInput> = Pick<CommandModule<LoadPopulateFilesCommandInput, ExtendedInput>, 'builder' | 'command' | 'describe' | 'handler'>;
7
- /**
8
- * Adds a command to the CLI.
9
- *
10
- * Commands differ in the input their handler receives, so they cannot share an element type.
11
- * Wrapping each in a function that registers it keeps every command type-checked against its own input.
12
- */
13
- export type RegisterCommand = (cli: Argv<LoadPopulateFilesCommandInput>) => Argv<LoadPopulateFilesCommandInput>;
14
- /**
15
- * Every command the CLI runs. Each command binds itself:
16
- *
17
- * `bind(commandId).withInstance(cli => cli.command(myCommand))`
18
- */
19
- export declare const commandId: import("haywire").HaywireId<RegisterCommand, null, null, true, false, false, false, false>;
20
- //# sourceMappingURL=types.d.ts.map
@@ -1,4 +0,0 @@
1
- import { identifier } from 'haywire';
2
- export const commandId = identifier().list();
3
-
4
- //# sourceMappingURL=types.js.map
@@ -1,16 +0,0 @@
1
- import type { Command, LoadPopulateFilesCommandInput } from './lib/types.js';
2
- interface LoadPopulateFilesCommandExtendedInput extends LoadPopulateFilesCommandInput {
3
- filePath: string;
4
- ci: boolean;
5
- dryRun: boolean;
6
- clean: boolean;
7
- force: boolean;
8
- manifest: string | undefined;
9
- }
10
- /**
11
- * Main `load-populate-files` command
12
- */
13
- export declare const loadPopulateFilesCommand: Command<LoadPopulateFilesCommandExtendedInput>;
14
- export declare const loadPopulateFilesCommandBinding: import("haywire").Binding<import("haywire").OutputHaywireId<import("haywire").HaywireId<import("./lib/types.js").RegisterCommand, null, null, true, false, false, false, false>>, [], false>;
15
- export {};
16
- //# sourceMappingURL=load-populate-files-command.d.ts.map
@@ -1,59 +0,0 @@
1
- import { isCI } from 'ci-info';
2
- import { bind } from 'haywire';
3
- import { loadAndPopulateFiles } from '../lib/load-populate-files.js';
4
- import { commandId } from './lib/types.js';
5
- export const loadPopulateFilesCommand = {
6
- command: [
7
- '$0',
8
- 'load-populate-files'
9
- ],
10
- describe: 'Read pre-generated content and write to file',
11
- builder: (yargs)=>yargs.options({
12
- filePath: {
13
- describe: 'File that exports data content to populate',
14
- type: 'string',
15
- required: true
16
- },
17
- ci: {
18
- describe: 'Fail if file is not up to date. Implies --dry-run',
19
- type: 'boolean',
20
- default: isCI,
21
- alias: 'check'
22
- },
23
- dryRun: {
24
- describe: 'Do not write file',
25
- type: 'boolean',
26
- default: false
27
- },
28
- clean: {
29
- describe: 'Remove files in --target-dir that were not generated. In --ci mode, fail instead of removing.',
30
- type: 'boolean',
31
- default: false
32
- },
33
- force: {
34
- describe: 'Overwrite signed files even if they were edited, are not signed, or would lose manual sections',
35
- type: 'boolean',
36
- default: false
37
- },
38
- manifest: {
39
- describe: 'Record generated files in this manifest (relative to --cwd), to detect edits to them and only --clean files it lists',
40
- type: 'string'
41
- }
42
- }).strict(),
43
- handler: async (options)=>{
44
- await loadAndPopulateFiles({
45
- filePath: options.filePath
46
- }, {
47
- cwd: options.cwd,
48
- targetDir: options.targetDir,
49
- check: options.ci,
50
- dryRun: options.dryRun,
51
- clean: options.clean,
52
- force: options.force,
53
- manifest: options.manifest
54
- });
55
- }
56
- };
57
- export const loadPopulateFilesCommandBinding = bind(commandId).withInstance((cli)=>cli.command(loadPopulateFilesCommand));
58
-
59
- //# sourceMappingURL=load-populate-files-command.js.map
@@ -1,3 +0,0 @@
1
- export declare const cliModule: import("haywire").Module<[import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, false, false>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, false, true>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, true, false>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, true, true>], [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, false, false>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, false, true>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, true, false>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, true, true>], [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, false, false>], false>;
2
- export declare const cliContainer: import("haywire").SyncContainer<[import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, false, false>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, false, true>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, true, false>] | [import("haywire").NonExtendable<import("./cli.js").LoadPopulateFilesCli, typeof import("./cli.js").LoadPopulateFilesCli, null, false, true, true>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, false, false>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, false, true>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, true, false>] | [import("haywire").NonExtendable<import("./commands/lib/types.js").RegisterCommand, null, null, true, true, true>]>;
3
- //# sourceMappingURL=container.d.ts.map
package/dist/container.js DELETED
@@ -1,7 +0,0 @@
1
- import { createContainer, createModule } from 'haywire';
2
- import { loadPopulateFilesCliBinding } from './cli.js';
3
- import { loadPopulateFilesCommandBinding } from './commands/load-populate-files-command.js';
4
- export const cliModule = createModule(loadPopulateFilesCliBinding).addBinding(loadPopulateFilesCommandBinding);
5
- export const cliContainer = createContainer(cliModule);
6
-
7
- //# sourceMappingURL=container.js.map