load-populate-files 0.1.1 → 1.0.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.
package/.npmignore ADDED
@@ -0,0 +1,13 @@
1
+ CHANGELOG.md
2
+ project.json
3
+ tsconfig.json
4
+
5
+ coverage/**
6
+ eslint.config.js
7
+
8
+ dist/tsconfig.tsbuildinfo
9
+ dist/**/*.map
10
+ dist-test/**
11
+ test/**
12
+
13
+ src/**
package/README.md CHANGED
@@ -1,43 +1,31 @@
1
1
  <div style="text-align:center">
2
2
 
3
3
  # load-populate-files
4
- Load and dynamically populate file content based on a single files config.
4
+ Load and dynamically populate file content based on a single file's config.
5
5
 
6
6
  [![npm package](https://badge.fury.io/js/load-populate-files.svg)](https://www.npmjs.com/package/load-populate-files)
7
7
  [![License](https://img.shields.io/npm/l/load-populate-files.svg)](https://github.com/JacobLey/leyman/blob/main/tools/load-populate-files/LICENSE)
8
8
 
9
9
  </div>
10
10
 
11
- ## Table of Contents
11
+ ## Contents
12
12
 
13
- - [Introduction](#introduction)
14
- - [Installation](#installation)
13
+ - [Install](#install)
14
+ - [Example](#example)
15
15
  - [Usage](#usage)
16
16
  - [API](#api)
17
- - [loadAndPopulateFiles](#loadandpopulatefilesfilepath-options)
17
+ - [loadAndPopulateFiles](#loadandpopulatefilesfilepath-options)
18
18
  - [Types](#types)
19
- - [PopulateFileParams](#populatefileparams)
19
+ - [PopulateFileParams](#populatefileparams)
20
20
  - [Also See](#also-see)
21
21
 
22
- ## Introduction
22
+ ## Install
23
23
 
24
- `load-populate-files` is a small library to simplify usage of [populate-files](https://www.npmjs.com/package/populate-files), which will dynamically write files based on calculated content.
25
-
26
- Instead of calling `populateFiles()` directly, we can can export the file configs, and defer the execution of file writing to `loadAndPopulateFiles()`.
27
-
28
- This is useful for CLI scripts, or NX plugins like [nx-populate-files](https://www.npmjs.com/package/nx-populate-files).
29
-
30
- ## Installation
31
-
32
- `npm i load-populate-files`
33
-
34
- Populate-files is an ESM module. That means it _must_ be `import`ed. To load from a CJS module, use dynamic import `const { loadAndPopulateFiles } = await import('load-populate-files');`.
35
-
36
- ## Usage
37
-
38
- Provide the file path to a file that _default exports_ the parameters for `populateFiles()`
24
+ ```sh
25
+ npm i load-populate-files
26
+ ```
39
27
 
40
- Options are supported the same as `populateFiles()`.
28
+ ## Example
41
29
 
42
30
  ```ts
43
31
  // config.ts
@@ -55,41 +43,56 @@ export default [
55
43
  ];
56
44
 
57
45
  // index.ts
46
+ import { loadAndPopulateFiles } from 'load-populate-files';
47
+
58
48
  await loadAndPopulateFiles('./config.js');
59
49
  ```
60
50
 
61
- This is also exposed as a CLI:
51
+ ## Usage
52
+
53
+ `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');`.
54
+
55
+ 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.
62
56
 
63
- `pnpx load-populate-files --help`
64
- `pnpx load-populate-files --file-path ./config.js`
57
+ This package is also available as a CLI:
58
+
59
+ ```sh
60
+ pnpx load-populate-files --help
61
+ pnpx load-populate-files --file-path ./config.js
62
+ ```
65
63
 
66
64
  ## API
67
65
 
68
- ### loadAndPopulateFiles(filePath, options)
66
+ ### `loadAndPopulateFiles(filePath, options?)`
69
67
 
70
- Loads the config specified at `filePath`, and passes that to [populateFiles()](https://www.npmjs.com/package/populate-files#populatefilesparams-options).
68
+ Loads the config exported at `filePath` and passes it to [`populateFiles()`](https://www.npmjs.com/package/populate-files#populatefilesparams-options).
71
69
 
72
- The loaded file may either be a single object config, or an array of separate configs.
70
+ **Parameters**
73
71
 
74
- If using the CLI, the `--file-path` parameter is required.
72
+ | Parameter | Type | Default | Description |
73
+ |-----------|------|---------|-------------|
74
+ | `filePath` | `string` | — | Required. Path to the config module. When using the CLI, pass as `--file-path`. |
75
+ | `options` | `object` | `{}` | Optional. See [options](#options) below. |
75
76
 
76
- #### options
77
+ **Returns** `Promise<void>`
77
78
 
78
- An optional object as the secondary parameter. Passed to underlying `populateFiles()` call.
79
+ #### `options`
79
80
 
80
- They are also available as optional flags in the CLI.
81
+ Options are passed through to the underlying `populateFiles()` call. They are also available as CLI flags.
81
82
 
82
- | property | CLI flag | type | default | description |
83
+ | Property | CLI flag | Type | Default | Description |
83
84
  |----------|----------|------|---------|-------------|
84
- | check | `--ci` | `boolean` | `true` if in a CI environment. Else `false` | If `true`, will fail if writing the file would result in changing the files content. Useful for CI environments to make sure the version-controlled code is up to date before deployment. |
85
- | dryRun | `--dry-run` | | `boolean` | `false` | If `true`, will not write file regardless of changes. Can still fail if `check` is `true`. |
86
- | cwd | `--cwd` | `string \| URL` | `process.env.PWD` | Used as the current working directory if `filePath` is a relative file. Will be re-used in filePaths derived from loaded config |
85
+ | `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. |
86
+ | `dryRun` | `--dry-run` | `boolean` | `false` | If `true`, does not write any files regardless of changes. Can still fail if `check` is `true`. |
87
+ | `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. |
88
+ | `targetDir` | `--target-dir`, `-t` | `string` | `'.'` | Target directory for resolving output file paths. Resolved relative to `cwd`. |
89
+ | `clean` | `--clean` | `boolean` | `false` | If `true`, removes files in `targetDir` that were not generated. In `--ci` mode, fails instead of removing. |
87
90
 
88
91
  ## Types
89
92
 
90
- ### PopulateFileParams
93
+ ### `PopulateFileParams`
91
94
 
92
- Type of the exported config at the specified file. Represents the parametesr to `populateFiles()`. It is highly recommended to combine with the `satisfies` keyword to ensure your exported config will succeed.
95
+ The type of a single exported config entry — equivalent to the params accepted by `populateFiles()`. Use with the `satisfies` keyword to validate your config at compile time.
93
96
 
94
97
  ```ts
95
98
  import type { PopulateFileParams } from 'load-populate-files';
@@ -100,18 +103,9 @@ export default {
100
103
  } satisfies PopulateFileParams;
101
104
  ```
102
105
 
103
- Note this type can also be imported from [populate-files](https://www.npmjs.com/package/populate-files) directly.
106
+ This type can also be imported directly from [`populate-files`](https://www.npmjs.com/package/populate-files).
104
107
 
105
108
  ## Also See
106
109
 
107
- ### [parse-cwd](https://www.npmjs.com/package/parse-cwd)
108
-
109
- Used internally to interpret `cwd` option.
110
-
111
- ### [populate-files](https://www.npmjs.com/package/populate-files)
112
-
113
- Populate and format a file based on dynamic content.
114
-
115
- ### [nx-populate-files](https://www.npmjs.com/package/nx-populate-files)
116
-
117
- Load and populate files as an nx target.
110
+ - [`populate-files`](https://www.npmjs.com/package/populate-files) — the underlying package that writes files; use directly when you don't need a separate config file
111
+ - [`parse-cwd`](https://www.npmjs.com/package/parse-cwd) — used internally to interpret the `cwd` option
package/dist/bin.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- declare const _default: import("haywire-launcher").WrapperMain;
2
- export default _default;
1
+ export { LoadPopulateFilesCli as default } from './cli.js';
3
2
  //# sourceMappingURL=bin.d.ts.map
package/dist/bin.js CHANGED
@@ -1,16 +1,3 @@
1
- import { EntryScript } from "entry-script";
2
- import { bind, singletonScope } from 'haywire';
3
- import { launch } from 'haywire-launcher';
4
- import { LoadPopulateFilesCli } from './cli.js';
5
- import { commandsId, commandsModule } from './commands/index.js';
6
- import { consoleErrorId, consoleLogId, exitCodeId } from './commands/lib/dependencies.js';
7
- export default launch(commandsModule.addBinding(bind(EntryScript).withDependencies([
8
- LoadPopulateFilesCli
9
- ]).withProvider((cli)=>cli).scoped(singletonScope)).addBinding(bind(LoadPopulateFilesCli).withDependencies([
10
- commandsId.supplier(),
11
- consoleLogId,
12
- consoleErrorId,
13
- exitCodeId
14
- ]).withConstructorProvider().scoped(singletonScope)).toContainer());
1
+ export { LoadPopulateFilesCli as default } from './cli.js';
15
2
 
16
3
  //# sourceMappingURL=bin.js.map
package/dist/cli.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  import { EntryScript } from 'entry-script';
2
- import type { Supplier } from 'haywire';
3
- import type { ConsoleLog, ExitCode } from './commands/lib/dependencies.js';
4
- import type { AbstractCommand } from './commands/lib/types.js';
5
2
  /**
6
3
  * LoadPopulateFiles CLI. Run `./bin.mjs --help` for options.
7
4
  *
@@ -9,7 +6,6 @@ import type { AbstractCommand } from './commands/lib/types.js';
9
6
  */
10
7
  export declare class LoadPopulateFilesCli extends EntryScript {
11
8
  #private;
12
- constructor(getCommands: Supplier<AbstractCommand[]>, logger: ConsoleLog, errorLogger: ConsoleLog, exitCode: ExitCode);
13
9
  /**
14
10
  * Entry point to CLI script.
15
11
  *
@@ -17,6 +13,6 @@ export declare class LoadPopulateFilesCli extends EntryScript {
17
13
  *
18
14
  * @param argv - process arguments
19
15
  */
20
- main(argv: string[]): Promise<void>;
16
+ static main(argv: string[]): Promise<void>;
21
17
  }
22
18
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js CHANGED
@@ -1,43 +1,35 @@
1
1
  import yargs from 'yargs';
2
2
  import { EntryScript } from "entry-script";
3
+ import { loadPopulateFilesCommand } from './commands/load-populate-files-command.js';
3
4
  export class LoadPopulateFilesCli extends EntryScript {
4
- #getCommands;
5
- #logger;
6
- #errorLogger;
7
- #exitCode;
8
- constructor(getCommands, logger, errorLogger, exitCode){
9
- super();
10
- this.#getCommands = getCommands;
11
- this.#logger = logger;
12
- this.#errorLogger = errorLogger;
13
- this.#exitCode = exitCode;
14
- }
15
- async main(argv) {
5
+ static async main(argv) {
16
6
  const packageJson = await import('../package.json', {
17
7
  with: {
18
8
  type: 'json'
19
9
  }
20
10
  });
21
- const yarg = yargs().scriptName('load-populate-files').option({
11
+ await yargs().scriptName('load-populate-files').option({
22
12
  cwd: {
23
13
  type: 'string',
24
14
  default: '.',
25
15
  describe: 'Relative working directory for all paths'
16
+ },
17
+ targetDir: {
18
+ type: 'string',
19
+ default: '.',
20
+ describe: 'Target directory for resolving output file paths. Defaults to resolved cwd.',
21
+ alias: 't'
26
22
  }
27
- }).strict().help().alias('help', 'info').version(packageJson.default.version);
28
- for (const command of this.#getCommands()){
29
- yarg.command(command);
30
- }
31
- await yarg.parseAsync(argv, {}, this.#yargsOutput.bind(this));
23
+ }).strict().help().alias('help', 'info').version(packageJson.default.version).command(loadPopulateFilesCommand).parseAsync(argv, {}, LoadPopulateFilesCli.#yargsOutput);
32
24
  }
33
- #yargsOutput(e, _argv, log) {
25
+ static #yargsOutput(e, _argv, log) {
34
26
  if (e) {
35
- this.#exitCode(1);
27
+ process.exitCode = 1;
36
28
  if (log) {
37
- this.#errorLogger(log);
29
+ console.error(log);
38
30
  }
39
31
  } else if (log) {
40
- this.#logger(log);
32
+ console.log(log);
41
33
  }
42
34
  }
43
35
  }
@@ -1,9 +1,7 @@
1
1
  import type { CommandModule } from 'yargs';
2
2
  export interface LoadPopulateFilesCommandInput {
3
3
  cwd: string;
4
+ targetDir: string;
4
5
  }
5
6
  export type Command<ExtendedInput extends LoadPopulateFilesCommandInput> = Pick<CommandModule<LoadPopulateFilesCommandInput, ExtendedInput>, 'builder' | 'command' | 'describe' | 'handler'>;
6
- export interface AbstractCommand extends Pick<CommandModule<LoadPopulateFilesCommandInput, LoadPopulateFilesCommandInput>, 'builder' | 'command' | 'describe'> {
7
- handler: (args: any) => Promise<void>;
8
- }
9
7
  //# sourceMappingURL=types.d.ts.map
@@ -1,21 +1,13 @@
1
- import type { Argv } from 'yargs';
2
- import type { LoadAndPopulateFiles } from 'load-populate-files';
3
1
  import type { Command, LoadPopulateFilesCommandInput } from './lib/types.js';
4
2
  interface LoadPopulateFilesCommandExtendedInput extends LoadPopulateFilesCommandInput {
5
3
  filePath: string;
6
4
  ci: boolean;
7
5
  dryRun: boolean;
6
+ clean: boolean;
8
7
  }
9
8
  /**
10
9
  * Main `load-populate-files` command
11
10
  */
12
- export declare class LoadPopulateFilesCommand implements Command<LoadPopulateFilesCommandExtendedInput> {
13
- #private;
14
- readonly command: string[];
15
- readonly describe = "Read pre-generated content and write to file";
16
- constructor(loadPopulateFiles: LoadAndPopulateFiles);
17
- builder(this: void, yargs: Argv<LoadPopulateFilesCommandInput>): Argv<LoadPopulateFilesCommandExtendedInput>;
18
- handler(options: LoadPopulateFilesCommandExtendedInput): Promise<void>;
19
- }
11
+ export declare const loadPopulateFilesCommand: Command<LoadPopulateFilesCommandExtendedInput>;
20
12
  export {};
21
13
  //# sourceMappingURL=load-populate-files-command.d.ts.map
@@ -1,17 +1,12 @@
1
1
  import { isCI } from 'ci-info';
2
- export class LoadPopulateFilesCommand {
3
- command = [
2
+ import { loadAndPopulateFiles } from '../lib/load-populate-files.js';
3
+ export const loadPopulateFilesCommand = {
4
+ command: [
4
5
  '$0',
5
6
  'load-populate-files'
6
- ];
7
- describe = 'Read pre-generated content and write to file';
8
- #loadPopulateFiles;
9
- constructor(loadPopulateFiles){
10
- this.#loadPopulateFiles = loadPopulateFiles;
11
- this.handler = this.handler.bind(this);
12
- }
13
- builder(yargs) {
14
- return yargs.options({
7
+ ],
8
+ describe: 'Read pre-generated content and write to file',
9
+ builder: (yargs)=>yargs.options({
15
10
  filePath: {
16
11
  describe: 'File that exports data content to populate',
17
12
  type: 'string',
@@ -27,18 +22,24 @@ export class LoadPopulateFilesCommand {
27
22
  describe: 'Do not write file',
28
23
  type: 'boolean',
29
24
  default: false
25
+ },
26
+ clean: {
27
+ describe: 'Remove files in --target-dir that were not generated. In --ci mode, fail instead of removing.',
28
+ type: 'boolean',
29
+ default: false
30
30
  }
31
- }).strict();
32
- }
33
- async handler(options) {
34
- await this.#loadPopulateFiles({
31
+ }).strict(),
32
+ handler: async (options)=>{
33
+ await loadAndPopulateFiles({
35
34
  filePath: options.filePath
36
35
  }, {
37
36
  cwd: options.cwd,
37
+ targetDir: options.targetDir,
38
38
  check: options.ci,
39
- dryRun: options.dryRun
39
+ dryRun: options.dryRun,
40
+ clean: options.clean
40
41
  });
41
42
  }
42
- }
43
+ };
43
44
 
44
45
  //# sourceMappingURL=load-populate-files-command.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export type { PopulateFileParams } from 'populate-files';
2
2
  export type { LoadAndPopulateFiles } from './lib/load-populate-files.js';
3
- export declare const loadAndPopulateFiles: import("./lib/load-populate-files.js").LoadAndPopulateFiles;
3
+ export { loadAndPopulateFiles } from './lib/load-populate-files.js';
4
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import { createContainer } from 'haywire';
2
- import { loadAndPopulateFilesId, loadAndPopulateFilesModule } from './lib/index.js';
3
- export const loadAndPopulateFiles = createContainer(loadAndPopulateFilesModule).get(loadAndPopulateFilesId);
1
+ export { loadAndPopulateFiles } from './lib/load-populate-files.js';
4
2
 
5
3
  //# sourceMappingURL=index.js.map
@@ -1,15 +1,14 @@
1
- import AjvDefault from 'ajv/dist/2020.js';
2
- export declare const isPopulateFileParams: AjvDefault.ValidateFunction<(Partial<{
1
+ export declare const isPopulateFileParams: (x: unknown) => x is (Partial<{
3
2
  filePath: string;
4
- content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
3
+ content: Promise<import("populate-files").FileContent> | import("populate-files").FileContent;
5
4
  }> & Required<Pick<{
6
5
  filePath: string;
7
- content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
8
- }, "content" | "filePath">>) | (Partial<{
6
+ content: Promise<import("populate-files").FileContent> | import("populate-files").FileContent;
7
+ }, "content" | "filePath">>)[] | (Partial<{
9
8
  filePath: string;
10
- content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
9
+ content: Promise<import("populate-files").FileContent> | import("populate-files").FileContent;
11
10
  }> & Required<Pick<{
12
11
  filePath: string;
13
- content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
14
- }, "content" | "filePath">>)[]>;
12
+ content: Promise<import("populate-files").FileContent> | import("populate-files").FileContent;
13
+ }, "content" | "filePath">>);
15
14
  //# sourceMappingURL=populate-files-validator.d.ts.map
@@ -1,7 +1,5 @@
1
- import AjvDefault from 'ajv/dist/2020.js';
2
- import { defaultImport } from 'default-import';
3
1
  import { arraySchema, mergeSchema, objectSchema, stringSchema } from 'juniper';
4
- const Ajv = defaultImport(AjvDefault);
2
+ import { makeValidator } from 'juniper-validator';
5
3
  const populateFileParam = objectSchema({
6
4
  properties: {
7
5
  filePath: stringSchema(),
@@ -18,8 +16,6 @@ const populateFileParams = mergeSchema().oneOf([
18
16
  items: populateFileParam
19
17
  })
20
18
  ]);
21
- export const isPopulateFileParams = new Ajv({
22
- strict: true
23
- }).compile(populateFileParams.toJSON());
19
+ export const isPopulateFileParams = makeValidator(populateFileParams).is;
24
20
 
25
21
  //# sourceMappingURL=populate-files-validator.js.map
@@ -1,14 +1,5 @@
1
- import type { PopulateFiles, PopulationResponse } from 'populate-files';
2
- import type { LoadFile } from './loader.js';
3
- import type { NormalizeParams } from './normalize.js';
1
+ import type { PopulationResponse } from 'populate-files';
4
2
  import type { RawOptions, RawParams } from './types.js';
5
3
  export type LoadAndPopulateFiles = (params: RawParams, options?: RawOptions) => Promise<PopulationResponse[]>;
6
- /**
7
- * Factory for generating primary `loadAndPopulateFiles` function
8
- */
9
- export declare class LoadPopulateFilesFactory {
10
- #private;
11
- readonly loadAndPopulateFiles: LoadAndPopulateFiles;
12
- constructor(normalizeParams: NormalizeParams, loadFile: LoadFile, populateFiles: PopulateFiles);
13
- }
4
+ export declare const loadAndPopulateFiles: LoadAndPopulateFiles;
14
5
  //# sourceMappingURL=load-populate-files.d.ts.map
@@ -1,19 +1,10 @@
1
- export class LoadPopulateFilesFactory {
2
- #normalizeParams;
3
- #loadFile;
4
- #populateFiles;
5
- loadAndPopulateFiles;
6
- constructor(normalizeParams, loadFile, populateFiles){
7
- this.#normalizeParams = normalizeParams;
8
- this.#loadFile = loadFile;
9
- this.#populateFiles = populateFiles;
10
- this.loadAndPopulateFiles = this.#loadAndPopulateFiles.bind(this);
11
- }
12
- async #loadAndPopulateFiles(params, options = {}) {
13
- const normalized = await this.#normalizeParams(params, options);
14
- const files = await this.#loadFile(normalized.filePath);
15
- return this.#populateFiles(files, normalized.options);
16
- }
17
- }
1
+ import { populateFiles } from 'populate-files';
2
+ import { loadFile } from './loader.js';
3
+ import { normalizeParams } from './normalize.js';
4
+ export const loadAndPopulateFiles = async (params, options = {})=>{
5
+ const normalized = await normalizeParams(params, options);
6
+ const files = await loadFile(normalized.filePath);
7
+ return populateFiles(files, normalized.options);
8
+ };
18
9
 
19
10
  //# sourceMappingURL=load-populate-files.js.map
@@ -1,5 +1,9 @@
1
1
  import type { PopulateFileParams } from 'populate-files';
2
- import type { Importer } from './lib/dependencies.js';
3
- export type LoadFile = (filePath: string) => Promise<PopulateFileParams[]>;
4
- export declare const loadFileProvider: (importer: Importer) => LoadFile;
2
+ /**
3
+ * Dynamically import a JS file and validate its default export as populate-files input.
4
+ *
5
+ * @param filePath - absolute path to JS file
6
+ * @returns list of populate-files params exported by the file
7
+ */
8
+ export declare const loadFile: (filePath: string) => Promise<PopulateFileParams[]>;
5
9
  //# sourceMappingURL=loader.d.ts.map
@@ -1,19 +1,19 @@
1
1
  import { defaultImport } from 'default-import';
2
2
  import { isPopulateFileParams } from './lib/populate-files-validator.js';
3
- export const loadFileProvider = (importer)=>async (filePath)=>{
4
- const mod = await importer(filePath).catch((err)=>{
5
- if (String(err).includes('ERR_MODULE_NOT_FOUND')) {
6
- throw new Error(`JS file not found: ${filePath}`);
7
- }
8
- throw err;
9
- });
10
- const params = defaultImport(mod);
11
- if (isPopulateFileParams(params)) {
12
- return [
13
- params
14
- ].flat();
3
+ export const loadFile = async (filePath)=>{
4
+ const mod = await import(filePath).catch((err)=>{
5
+ if (String(err).includes('ERR_MODULE_NOT_FOUND')) {
6
+ throw new Error(`JS file not found: ${filePath}`);
15
7
  }
16
- throw new Error(`File content does not fulfill populate-file input at: ${filePath}`);
17
- };
8
+ throw err;
9
+ });
10
+ const params = defaultImport(mod);
11
+ if (isPopulateFileParams(params)) {
12
+ return [
13
+ params
14
+ ].flat();
15
+ }
16
+ throw new Error(`File content does not fulfill populate-file input at: ${filePath}`);
17
+ };
18
18
 
19
19
  //# sourceMappingURL=loader.js.map
@@ -1,5 +1,3 @@
1
- import type { ParseCwd } from 'parse-cwd';
2
1
  import type { NormalizedParams, RawOptions, RawParams } from './types.js';
3
- export type NormalizeParams = (params: RawParams, options?: RawOptions) => Promise<NormalizedParams>;
4
- export declare const normalizeParamsProvider: (parseCwd: ParseCwd) => NormalizeParams;
2
+ export declare const normalizeParams: (params: RawParams, options?: RawOptions) => Promise<NormalizedParams>;
5
3
  //# sourceMappingURL=normalize.d.ts.map
@@ -1,14 +1,17 @@
1
1
  import Path from 'node:path';
2
- export const normalizeParamsProvider = (parseCwd)=>async (params, options = {})=>{
3
- const cwd = await parseCwd(options.cwd);
4
- return {
5
- filePath: Path.resolve(cwd, params.filePath),
6
- options: {
7
- cwd,
8
- check: options.check,
9
- dryRun: options.dryRun
10
- }
11
- };
2
+ import { parseCwd } from 'parse-cwd';
3
+ export const normalizeParams = async (params, options = {})=>{
4
+ const cwd = await parseCwd(options.cwd);
5
+ return {
6
+ filePath: Path.resolve(cwd, params.filePath),
7
+ options: {
8
+ cwd,
9
+ check: options.check,
10
+ dryRun: options.dryRun,
11
+ targetDir: options.targetDir,
12
+ clean: options.clean
13
+ }
12
14
  };
15
+ };
13
16
 
14
17
  //# sourceMappingURL=normalize.js.map
@@ -4,15 +4,19 @@ export interface RawParams {
4
4
  }
5
5
  export interface RawOptions {
6
6
  cwd?: Directory;
7
- check?: boolean | undefined;
8
- dryRun?: boolean | undefined;
7
+ targetDir?: string | null | undefined;
8
+ check?: boolean | null | undefined;
9
+ dryRun?: boolean | null | undefined;
10
+ clean?: boolean | null | undefined;
9
11
  }
10
12
  export interface NormalizedParams {
11
13
  filePath: string;
12
14
  options: {
13
15
  cwd: string;
14
- check?: boolean | undefined;
15
- dryRun?: boolean | undefined;
16
+ targetDir?: string | null | undefined;
17
+ check?: boolean | null | undefined;
18
+ dryRun?: boolean | null | undefined;
19
+ clean?: boolean | null | undefined;
16
20
  };
17
21
  }
18
22
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "description": "Load and dynamically populate file content",
5
5
  "engines": {
6
- "node": ">=20"
6
+ "node": ">=24"
7
7
  },
8
8
  "type": "module",
9
9
  "author": "JacobLey",
10
10
  "license": "MIT",
11
- "repository": "JacobLey/leyman",
12
- "homepage": "https://github.com/JacobLey/leyman/tree/main/apps/populate-files/load-populate-files/nx-tsc#readme",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "JacobLey/leyman"
14
+ },
15
+ "homepage": "https://github.com/JacobLey/leyman/tree/main/apps/populate-files/load-populate-files#readme",
13
16
  "bugs": {
14
17
  "url": "https://github.com/JacobLey/leyman/issues"
15
18
  },
@@ -27,35 +30,32 @@
27
30
  "load-populate-files": "./bin.mjs"
28
31
  },
29
32
  "dependencies": {
30
- "ajv": "^8.17.1",
31
- "ci-info": "^4.1.0",
32
- "yargs": "^17.7.2",
33
- "default-import": "^2.0.7",
34
- "haywire-launcher": "^0.1.10",
35
- "juniper": "^1.2.4",
36
- "parse-cwd": "^1.1.1",
37
- "populate-files": "^0.2.3",
38
- "entry-script": "^3.0.8",
39
- "haywire": "^0.1.7"
33
+ "ci-info": "^4.4.0",
34
+ "default-import": "^3.0.0",
35
+ "entry-script": "^4.0.0",
36
+ "juniper": "^2.0.0",
37
+ "juniper-validator": "^0.1.0",
38
+ "parse-cwd": "^2.0.0",
39
+ "populate-files": "^1.0.0",
40
+ "yargs": "^18.2.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@biomejs/biome": "^1.9.4",
43
- "@swc/cli": "^0.5.2",
44
- "@swc/core": "^1.10.4",
45
- "@types/chai": "^5.0.1",
46
- "@types/chai-as-promised": "^8.0.1",
43
+ "@biomejs/biome": "^2.5.14",
44
+ "@leyman/eslint-config": "^0.0.1",
45
+ "@leyman/expect": "^0.0.1",
46
+ "@swc/cli": "^0.8.1",
47
+ "@swc/core": "^1.16.2",
47
48
  "@types/mocha": "^10.0.10",
48
- "@types/node": "^22.10.2",
49
- "@types/yargs": "^17.0.33",
50
- "c8": "^10.1.3",
51
- "chai": "^5.1.2",
52
- "chai-as-promised": "^8.0.1",
53
- "eslint": "^9.17.0",
54
- "mocha": "^11.0.1",
55
- "typescript": "^5.7.2",
56
- "@leyman/eslint-config": "^0.0.5",
57
- "mocha-chain": "^0.0.10",
58
- "nx-update-ts-references": "^0.2.0",
59
- "pnpm-dedicated-lockfile": "^0.0.3"
49
+ "@types/node": "^24.19.0",
50
+ "@types/yargs": "^17.0.35",
51
+ "@typescript/native": "npm:typescript@^7.0.2",
52
+ "c8": "^12.0.0",
53
+ "eslint": "^9.39.5",
54
+ "mocha": "^12.0.2",
55
+ "mocha-chain": "^1.0.0",
56
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
57
+ },
58
+ "imports": {
59
+ "#internal/*": "./dist/*"
60
60
  }
61
61
  }
@@ -1,5 +0,0 @@
1
- import type { AbstractCommand } from './lib/types.js';
2
- import { LoadPopulateFilesCommand } from './load-populate-files-command.js';
3
- export declare const commandsId: import("haywire").HaywireId<AbstractCommand[], null, null, false, false, false, false>;
4
- export declare const commandsModule: import("haywire").Module<[import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | null | undefined, null, "log">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | null, null, "log">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | undefined, null, "log">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog, null, "log">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | null | undefined, null, "error">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | null, null, "error">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog | undefined, null, "error">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ConsoleLog, null, "error">] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ExitCode | null | undefined, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ExitCode | null, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ExitCode | undefined, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").ExitCode, null, null>] | [import("haywire").NonExtendable<import("../lib/lib/dependencies.js").Importer | null | undefined, null, null>] | [import("haywire").NonExtendable<import("../lib/lib/dependencies.js").Importer | null, null, null>] | [import("haywire").NonExtendable<import("../lib/lib/dependencies.js").Importer | undefined, null, null>] | [import("haywire").NonExtendable<import("../lib/lib/dependencies.js").Importer, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | null | undefined, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | null, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | undefined, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles, null, null>] | [import("haywire").NonExtendable<import("../lib/load-populate-files.js").LoadPopulateFilesFactory | null | undefined, typeof import("../lib/load-populate-files.js").LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<import("../lib/load-populate-files.js").LoadPopulateFilesFactory | null, typeof import("../lib/load-populate-files.js").LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<import("../lib/load-populate-files.js").LoadPopulateFilesFactory | undefined, typeof import("../lib/load-populate-files.js").LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<import("../lib/load-populate-files.js").LoadPopulateFilesFactory, typeof import("../lib/load-populate-files.js").LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<import("../lib/normalize.js").NormalizeParams, null, null>] | [import("haywire").NonExtendable<import("../lib/loader.js").LoadFile, null, null>] | [import("haywire").NonExtendable<import("../index.js").LoadAndPopulateFiles | null | undefined, null, null>] | [import("haywire").NonExtendable<import("../index.js").LoadAndPopulateFiles | null, null, null>] | [import("haywire").NonExtendable<import("../index.js").LoadAndPopulateFiles | undefined, null, null>] | [import("haywire").NonExtendable<import("../index.js").LoadAndPopulateFiles, null, null>] | [import("haywire").NonExtendable<import("../lib/loader.js").LoadFile | null | undefined, null, null>] | [import("haywire").NonExtendable<import("../lib/loader.js").LoadFile | null, null, null>] | [import("haywire").NonExtendable<import("../lib/loader.js").LoadFile | undefined, null, null>] | [import("haywire").NonExtendable<import("../lib/normalize.js").NormalizeParams | null | undefined, null, null>] | [import("haywire").NonExtendable<import("../lib/normalize.js").NormalizeParams | null, null, null>] | [import("haywire").NonExtendable<import("../lib/normalize.js").NormalizeParams | undefined, null, null>] | [import("haywire").NonExtendable<AbstractCommand[] | null | undefined, null, null>] | [import("haywire").NonExtendable<AbstractCommand[] | null, null, null>] | [import("haywire").NonExtendable<AbstractCommand[] | undefined, null, null>] | [import("haywire").NonExtendable<AbstractCommand[], null, null>] | [import("haywire").NonExtendable<LoadPopulateFilesCommand, typeof LoadPopulateFilesCommand, null>] | [import("haywire").NonExtendable<LoadPopulateFilesCommand | null | undefined, typeof LoadPopulateFilesCommand, null>] | [import("haywire").NonExtendable<LoadPopulateFilesCommand | null, typeof LoadPopulateFilesCommand, null>] | [import("haywire").NonExtendable<LoadPopulateFilesCommand | undefined, typeof LoadPopulateFilesCommand, null>], [import("haywire").NonExtendable<import("../lib/lib/dependencies.js").Importer, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles, null, null>] | [import("haywire").NonExtendable<import("../lib/load-populate-files.js").LoadPopulateFilesFactory, typeof import("../lib/load-populate-files.js").LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<import("../lib/normalize.js").NormalizeParams, null, null>] | [import("haywire").NonExtendable<import("../lib/loader.js").LoadFile, null, null>] | [import("haywire").NonExtendable<import("../index.js").LoadAndPopulateFiles, null, null>] | [import("haywire").NonExtendable<LoadPopulateFilesCommand, typeof LoadPopulateFilesCommand, null>], false>;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1,12 +0,0 @@
1
- import { bind, identifier } from 'haywire';
2
- import { loadAndPopulateFilesId, loadAndPopulateFilesModule } from '../lib/index.js';
3
- import { dependenciesModule } from './lib/dependencies.js';
4
- import { LoadPopulateFilesCommand } from './load-populate-files-command.js';
5
- export const commandsId = identifier();
6
- export const commandsModule = dependenciesModule.mergeModule(loadAndPopulateFilesModule).addBinding(bind(commandsId).withDependencies([
7
- LoadPopulateFilesCommand
8
- ]).withProvider((...commands)=>commands)).addBinding(bind(LoadPopulateFilesCommand).withDependencies([
9
- loadAndPopulateFilesId
10
- ]).withConstructorProvider());
11
-
12
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- export type ConsoleLog = (log: unknown) => void;
2
- export declare const consoleLogId: import("haywire").HaywireId<ConsoleLog, null, "log", false, false, false, false>;
3
- export declare const consoleErrorId: import("haywire").HaywireId<ConsoleLog, null, "error", false, false, false, false>;
4
- export type ExitCode = (code: number) => void;
5
- export declare const exitCodeId: import("haywire").HaywireId<ExitCode, null, null, false, false, false, false>;
6
- export declare const dependenciesModule: import("haywire").Module<[import("haywire").NonExtendable<ConsoleLog | null | undefined, null, "log">] | [import("haywire").NonExtendable<ConsoleLog | null, null, "log">] | [import("haywire").NonExtendable<ConsoleLog | undefined, null, "log">] | [import("haywire").NonExtendable<ConsoleLog, null, "log">] | [import("haywire").NonExtendable<ConsoleLog | null | undefined, null, "error">] | [import("haywire").NonExtendable<ConsoleLog | null, null, "error">] | [import("haywire").NonExtendable<ConsoleLog | undefined, null, "error">] | [import("haywire").NonExtendable<ConsoleLog, null, "error">] | [import("haywire").NonExtendable<ExitCode | null | undefined, null, null>] | [import("haywire").NonExtendable<ExitCode | null, null, null>] | [import("haywire").NonExtendable<ExitCode | undefined, null, null>] | [import("haywire").NonExtendable<ExitCode, null, null>], never, false>;
7
- //# sourceMappingURL=dependencies.d.ts.map
@@ -1,9 +0,0 @@
1
- import { bind, createModule, identifier } from 'haywire';
2
- export const consoleLogId = identifier().named('log');
3
- export const consoleErrorId = identifier().named('error');
4
- export const exitCodeId = identifier();
5
- export const dependenciesModule = createModule(bind(consoleLogId).withInstance(console.log)).addBinding(bind(consoleErrorId).withInstance(console.error)).addBinding(bind(exitCodeId).withInstance((code)=>{
6
- process.exitCode = code;
7
- }));
8
-
9
- //# sourceMappingURL=dependencies.js.map
@@ -1,6 +0,0 @@
1
- import { type LoadAndPopulateFiles, LoadPopulateFilesFactory } from './load-populate-files.js';
2
- import { type LoadFile } from './loader.js';
3
- import { type NormalizeParams } from './normalize.js';
4
- export declare const loadAndPopulateFilesId: import("haywire").HaywireId<LoadAndPopulateFiles, null, null, false, false, false, false>;
5
- export declare const loadAndPopulateFilesModule: import("haywire").Module<[import("haywire").NonExtendable<import("./lib/dependencies.js").Importer | null | undefined, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").Importer | null, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").Importer | undefined, null, null>] | [import("haywire").NonExtendable<import("./lib/dependencies.js").Importer, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | null, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd | undefined, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | null | undefined, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | null, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles | undefined, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles, null, null>] | [import("haywire").NonExtendable<LoadPopulateFilesFactory | null | undefined, typeof LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<LoadPopulateFilesFactory | null, typeof LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<LoadPopulateFilesFactory | undefined, typeof LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<LoadPopulateFilesFactory, typeof LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<NormalizeParams, null, null>] | [import("haywire").NonExtendable<LoadFile, null, null>] | [import("haywire").NonExtendable<LoadAndPopulateFiles | null | undefined, null, null>] | [import("haywire").NonExtendable<LoadAndPopulateFiles | null, null, null>] | [import("haywire").NonExtendable<LoadAndPopulateFiles | undefined, null, null>] | [import("haywire").NonExtendable<LoadAndPopulateFiles, null, null>] | [import("haywire").NonExtendable<LoadFile | null | undefined, null, null>] | [import("haywire").NonExtendable<LoadFile | null, null, null>] | [import("haywire").NonExtendable<LoadFile | undefined, null, null>] | [import("haywire").NonExtendable<NormalizeParams | null | undefined, null, null>] | [import("haywire").NonExtendable<NormalizeParams | null, null, null>] | [import("haywire").NonExtendable<NormalizeParams | undefined, null, null>], [import("haywire").NonExtendable<import("./lib/dependencies.js").Importer, null, null>] | [import("haywire").NonExtendable<import("parse-cwd").ParseCwd, null, null>] | [import("haywire").NonExtendable<import("populate-files").PopulateFiles, null, null>] | [import("haywire").NonExtendable<LoadPopulateFilesFactory, typeof LoadPopulateFilesFactory, null>] | [import("haywire").NonExtendable<NormalizeParams, null, null>] | [import("haywire").NonExtendable<LoadFile, null, null>], false>;
6
- //# sourceMappingURL=index.d.ts.map
package/dist/lib/index.js DELETED
@@ -1,21 +0,0 @@
1
- import { bind, identifier, singletonScope } from 'haywire';
2
- import { dependencies, importerId, parseCwdId, populateFilesId } from './lib/dependencies.js';
3
- import { LoadPopulateFilesFactory } from './load-populate-files.js';
4
- import { loadFileProvider } from './loader.js';
5
- import { normalizeParamsProvider } from './normalize.js';
6
- const normalizeParamsId = identifier();
7
- const loadFileId = identifier();
8
- export const loadAndPopulateFilesId = identifier();
9
- export const loadAndPopulateFilesModule = dependencies.addBinding(bind(LoadPopulateFilesFactory).withDependencies([
10
- normalizeParamsId,
11
- loadFileId,
12
- populateFilesId
13
- ]).withConstructorProvider().scoped(singletonScope)).addBinding(bind(loadAndPopulateFilesId).withDependencies([
14
- LoadPopulateFilesFactory
15
- ]).withProvider((factory)=>factory.loadAndPopulateFiles)).addBinding(bind(loadFileId).withDependencies([
16
- importerId
17
- ]).withProvider(loadFileProvider)).addBinding(bind(normalizeParamsId).withDependencies([
18
- parseCwdId
19
- ]).withProvider(normalizeParamsProvider));
20
-
21
- //# sourceMappingURL=index.js.map
@@ -1,8 +0,0 @@
1
- import { type ParseCwd } from 'parse-cwd';
2
- import { type PopulateFiles } from 'populate-files';
3
- export type Importer = (specifier: string) => Promise<unknown>;
4
- export declare const importerId: import("haywire").HaywireId<Importer, null, null, false, false, false, false>;
5
- export declare const parseCwdId: import("haywire").HaywireId<ParseCwd, null, null, false, false, false, false>;
6
- export declare const populateFilesId: import("haywire").HaywireId<PopulateFiles, null, null, false, false, false, false>;
7
- export declare const dependencies: import("haywire").Module<[import("haywire").NonExtendable<Importer | null | undefined, null, null>] | [import("haywire").NonExtendable<Importer | null, null, null>] | [import("haywire").NonExtendable<Importer | undefined, null, null>] | [import("haywire").NonExtendable<Importer, null, null>] | [import("haywire").NonExtendable<ParseCwd | null | undefined, null, null>] | [import("haywire").NonExtendable<ParseCwd | null, null, null>] | [import("haywire").NonExtendable<ParseCwd | undefined, null, null>] | [import("haywire").NonExtendable<ParseCwd, null, null>] | [import("haywire").NonExtendable<PopulateFiles | null | undefined, null, null>] | [import("haywire").NonExtendable<PopulateFiles | null, null, null>] | [import("haywire").NonExtendable<PopulateFiles | undefined, null, null>] | [import("haywire").NonExtendable<PopulateFiles, null, null>], never, false>;
8
- //# sourceMappingURL=dependencies.d.ts.map
@@ -1,9 +0,0 @@
1
- import { bind, createModule, identifier } from 'haywire';
2
- import { parseCwd } from 'parse-cwd';
3
- import { populateFiles } from 'populate-files';
4
- export const importerId = identifier();
5
- export const parseCwdId = identifier();
6
- export const populateFilesId = identifier();
7
- export const dependencies = createModule(bind(importerId).withInstance(async (specifier)=>import(specifier))).addBinding(bind(parseCwdId).withInstance(parseCwd)).addBinding(bind(populateFilesId).withInstance(populateFiles));
8
-
9
- //# sourceMappingURL=dependencies.js.map