load-populate-files 1.1.2 → 1.1.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Load and dynamically populate file content based on a single file's config.
8
8
 
9
9
  </div>
10
10
 
11
- Guides and the full reference are on the [docs site](https://jacobley.github.io/leyman/populate-files/guides/config-modules).
11
+ Guides and the full reference are on the [docs site](https://jacobley.github.io/leyman/packages/populate-files/), including [Config modules](https://jacobley.github.io/leyman/packages/populate-files/guides/config-modules) for this package.
12
12
 
13
13
  ## Contents
14
14
 
@@ -30,7 +30,7 @@ npm i load-populate-files
30
30
  ## Example
31
31
 
32
32
  ```ts
33
- // config.ts
33
+ // config.ts, compiled to config.js
34
34
  export default [
35
35
  {
36
36
  filePath: './foo.json',
@@ -54,7 +54,7 @@ await loadAndPopulateFiles({ filePath: './config.js' });
54
54
 
55
55
  `load-populate-files` is an ESM module. It must be `import`ed. To load from a CJS module, use dynamic import: `const { loadAndPopulateFiles } = await import('load-populate-files');`.
56
56
 
57
- Instead of calling `populateFiles()` directly, export file configs from a dedicated config module, then point `loadAndPopulateFiles()` at that file. The loaded file may export a single config object or an array of configs.
57
+ Instead of calling `populateFiles()` directly, export file configs from a dedicated config module, then point `loadAndPopulateFiles()` at that file. The config module is loaded with `import()`, so it must be JavaScript that Node can run: point at the compiled `.js`, not the `.ts` source. Its default export may be a single config object or an array of configs.
58
58
 
59
59
  This package is also available as a CLI:
60
60
 
@@ -78,15 +78,17 @@ Loads the config exported at `params.filePath` and passes it to [`populateFiles(
78
78
 
79
79
  **Returns** `Promise<PopulationResponse[]>`, from `populateFiles()`.
80
80
 
81
+ **Throws** (rejects) `Error` with `JS file not found: <path>` if the module doesn't exist, or with `File content does not fulfill populate-file input at: <path>` followed by a line per problem (e.g. `- 0.filePath: must have required property 'filePath'`) if the default export isn't a valid config. Errors from `populateFiles()` (such as a `PopulateFilesCheckError` with `check`) pass through. The CLI prints the error and exits with code 1.
82
+
81
83
  #### `options`
82
84
 
83
85
  Options are passed through to the underlying `populateFiles()` call. They are also available as CLI flags.
84
86
 
85
87
  | Property | CLI flag | Type | Default | Description |
86
88
  |----------|----------|------|---------|-------------|
87
- | `check` | `--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. |
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. |
88
90
  | `dryRun` | `--dry-run` | `boolean` | `false` | If `true`, does not write any files regardless of changes. Can still fail if `check` is `true`. |
89
- | `cwd` | `--cwd` | `string \| URL` | `process.env.PWD` | Used as the current working directory for `filePath` and re-used for relative `filePath`s in the loaded config. |
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. |
90
92
  | `targetDir` | `--target-dir`, `-t` | `string` | `'.'` | Target directory for resolving output file paths. Resolved relative to `cwd`. |
91
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. |
92
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). |
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
@@ -4,6 +4,7 @@ import type { PopulateFileParams } from 'populate-files';
4
4
  *
5
5
  * @param filePath - absolute path to JS file
6
6
  * @returns list of populate-files params exported by the file
7
+ * @rejects {Error} if the file doesn't exist, fails to load, or doesn't export populate-files params
7
8
  */
8
9
  export declare const loadFile: (filePath: string) => Promise<PopulateFileParams[]>;
9
10
  //# sourceMappingURL=loader.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "1.1.2",
4
- "description": "Load and dynamically populate file content",
3
+ "version": "1.1.4",
4
+ "description": "Load and dynamically populate file content based on a single file's config.",
5
5
  "engines": {
6
6
  "node": ">=24"
7
7
  },
@@ -13,7 +13,7 @@
13
13
  "url": "git+https://github.com/JacobLey/leyman.git",
14
14
  "directory": "apps/populate-files/load-populate-files"
15
15
  },
16
- "homepage": "https://github.com/JacobLey/leyman/tree/main/apps/populate-files/load-populate-files#readme",
16
+ "homepage": "https://jacobley.github.io/leyman/packages/populate-files/",
17
17
  "bugs": {
18
18
  "url": "https://github.com/JacobLey/leyman/issues"
19
19
  },
@@ -38,32 +38,30 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "ci-info": "^4.4.0",
41
- "default-import": "^3.0.1",
42
- "entry-script": "^4.1.1",
43
- "haywire": "^2.0.2",
44
- "haywire-launcher": "^1.1.0",
45
- "juniper": "^2.4.1",
46
- "juniper-validator": "^0.5.0",
47
- "parse-cwd": "^2.0.2",
48
- "populate-files": "^1.1.2",
49
- "unknown-error": "^0.1.0",
41
+ "default-import": "^3.0.2",
42
+ "entry-script": "^4.1.2",
43
+ "juniper": "^2.6.0",
44
+ "juniper-validator": "^0.5.2",
45
+ "parse-cwd": "^2.0.3",
46
+ "populate-files": "^1.2.0",
47
+ "unknown-error": "^0.1.1",
50
48
  "yargs": "^18.2.0"
51
49
  },
52
50
  "devDependencies": {
53
- "@biomejs/biome": "^2.5.14",
51
+ "@biomejs/biome": "^2.6.3",
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.2",
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
- "eslint": "^10.12.0",
64
- "generated-signature": "^0.1.1",
65
- "mocha": "^12.0.2",
66
- "mocha-chain": "^1.0.1",
61
+ "eslint": "^10.13.0",
62
+ "generated-signature": "^0.1.3",
63
+ "mocha": "^12.0.3",
64
+ "mocha-chain": "^1.0.2",
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