load-populate-files 0.0.11 → 0.1.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Jacob Ley
3
+ Copyright (c) 2025 Jacob Ley
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -58,6 +58,11 @@ export default [
58
58
  await loadAndPopulateFiles('./config.js');
59
59
  ```
60
60
 
61
+ This is also exposed as a CLI:
62
+
63
+ `pnpx load-populate-files --help`
64
+ `pnpx load-populate-files --file-path ./config.js`
65
+
61
66
  ## API
62
67
 
63
68
  ### loadAndPopulateFiles(filePath, options)
@@ -66,15 +71,19 @@ Loads the config specified at `filePath`, and passes that to [populateFiles()](h
66
71
 
67
72
  The loaded file may either be a single object config, or an array of separate configs.
68
73
 
74
+ If using the CLI, the `--file-path` parameter is required.
75
+
69
76
  #### options
70
77
 
71
78
  An optional object as the secondary parameter. Passed to underlying `populateFiles()` call.
72
79
 
73
- | property | type | default | description |
74
- |----------|------|---------|-------------|
75
- | check | `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. |
76
- | dryRun | `boolean` | `false` | If `true`, will not write file regardless of changes. Can still fail if `check` is `true`. |
77
- | 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 |
80
+ They are also available as optional flags in the CLI.
81
+
82
+ | property | CLI flag | type | default | description |
83
+ |----------|----------|------|---------|-------------|
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 |
78
87
 
79
88
  ## Types
80
89
 
package/bin.mjs ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ export { default } from './dist/bin.js';
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const _default: import("haywire-launcher").WrapperMain;
2
+ export default _default;
3
+ //# sourceMappingURL=bin.d.ts.map
package/dist/bin.js ADDED
@@ -0,0 +1,16 @@
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());
15
+
16
+ //# sourceMappingURL=bin.js.map
package/dist/cli.d.ts ADDED
@@ -0,0 +1,22 @@
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
+ /**
6
+ * LoadPopulateFiles CLI. Run `./bin.mjs --help` for options.
7
+ *
8
+ * Uses `yargs` package for command line parsing and logic flow.
9
+ */
10
+ export declare class LoadPopulateFilesCli extends EntryScript {
11
+ #private;
12
+ constructor(getCommands: Supplier<AbstractCommand[]>, logger: ConsoleLog, errorLogger: ConsoleLog, exitCode: ExitCode);
13
+ /**
14
+ * Entry point to CLI script.
15
+ *
16
+ * Sets high level Yargs settings. Command/options logic is implemented in individual command modules.
17
+ *
18
+ * @param argv - process arguments
19
+ */
20
+ main(argv: string[]): Promise<void>;
21
+ }
22
+ //# sourceMappingURL=cli.d.ts.map
package/dist/cli.js ADDED
@@ -0,0 +1,45 @@
1
+ import yargs from 'yargs';
2
+ import { EntryScript } from "entry-script";
3
+ 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) {
16
+ const packageJson = await import('../package.json', {
17
+ with: {
18
+ type: 'json'
19
+ }
20
+ });
21
+ const yarg = yargs().scriptName('load-populate-files').option({
22
+ cwd: {
23
+ type: 'string',
24
+ default: '.',
25
+ describe: 'Relative working directory for all paths'
26
+ }
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));
32
+ }
33
+ #yargsOutput(e, _argv, log) {
34
+ if (e) {
35
+ this.#exitCode(1);
36
+ if (log) {
37
+ this.#errorLogger(log);
38
+ }
39
+ } else if (log) {
40
+ this.#logger(log);
41
+ }
42
+ }
43
+ }
44
+
45
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,9 @@
1
+ import type { CommandModule } from 'yargs';
2
+ export interface LoadPopulateFilesCommandInput {
3
+ cwd: string;
4
+ }
5
+ 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
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,21 @@
1
+ import type { Argv } from 'yargs';
2
+ import type { LoadAndPopulateFiles } from 'load-populate-files';
3
+ import type { Command, LoadPopulateFilesCommandInput } from './lib/types.js';
4
+ interface LoadPopulateFilesCommandExtendedInput extends LoadPopulateFilesCommandInput {
5
+ filePath: string;
6
+ ci: boolean;
7
+ dryRun: boolean;
8
+ }
9
+ /**
10
+ * Main `load-populate-files` command
11
+ */
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
+ }
20
+ export {};
21
+ //# sourceMappingURL=load-populate-files-command.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { isCI } from 'ci-info';
2
+ export class LoadPopulateFilesCommand {
3
+ command = [
4
+ '$0',
5
+ '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({
15
+ filePath: {
16
+ describe: 'File that exports data content to populate',
17
+ type: 'string',
18
+ required: true
19
+ },
20
+ ci: {
21
+ describe: 'Fail if file is not up to date. Implies --dry-run',
22
+ type: 'boolean',
23
+ default: isCI,
24
+ alias: 'check'
25
+ },
26
+ dryRun: {
27
+ describe: 'Do not write file',
28
+ type: 'boolean',
29
+ default: false
30
+ }
31
+ }).strict();
32
+ }
33
+ async handler(options) {
34
+ await this.#loadPopulateFiles({
35
+ filePath: options.filePath
36
+ }, {
37
+ cwd: options.cwd,
38
+ check: options.ci,
39
+ dryRun: options.dryRun
40
+ });
41
+ }
42
+ }
43
+
44
+ //# sourceMappingURL=load-populate-files-command.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { type PopulationResponse } from 'populate-files';
2
- import type { RawOptions, RawParams } from './lib/types.js';
3
- export type { FileContent, PopulateFileParams } from 'populate-files';
4
- export declare const loadAndPopulateFiles: (params: RawParams, options?: RawOptions) => Promise<PopulationResponse[]>;
1
+ export type { PopulateFileParams } from 'populate-files';
2
+ export type { LoadAndPopulateFiles } from './lib/load-populate-files.js';
3
+ export declare const loadAndPopulateFiles: import("./lib/load-populate-files.js").LoadAndPopulateFiles;
5
4
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,9 +1,5 @@
1
- import { populateFiles } from 'populate-files';
2
- import { loadFile } from './lib/loader.js';
3
- import { normalizeParams } from './lib/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
- };
9
- //# sourceMappingURL=index.js.map
1
+ import { createContainer } from 'haywire';
2
+ import { loadAndPopulateFilesId, loadAndPopulateFilesModule } from './lib/index.js';
3
+ export const loadAndPopulateFiles = createContainer(loadAndPopulateFilesModule).get(loadAndPopulateFilesId);
4
+
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,21 @@
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
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,15 @@
1
+ import AjvDefault from 'ajv/dist/2020.js';
2
+ export declare const isPopulateFileParams: AjvDefault.ValidateFunction<(Partial<{
3
+ filePath: string;
4
+ content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
5
+ }> & Required<Pick<{
6
+ filePath: string;
7
+ content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
8
+ }, "content" | "filePath">>) | (Partial<{
9
+ filePath: string;
10
+ content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
11
+ }> & Required<Pick<{
12
+ filePath: string;
13
+ content: import("populate-files").FileContent | Promise<import("populate-files").FileContent>;
14
+ }, "content" | "filePath">>)[]>;
15
+ //# sourceMappingURL=populate-files-validator.d.ts.map
@@ -0,0 +1,25 @@
1
+ import AjvDefault from 'ajv/dist/2020.js';
2
+ import { defaultImport } from 'default-import';
3
+ import { arraySchema, mergeSchema, objectSchema, stringSchema } from 'juniper';
4
+ const Ajv = defaultImport(AjvDefault);
5
+ const populateFileParam = objectSchema({
6
+ properties: {
7
+ filePath: stringSchema(),
8
+ content: mergeSchema().cast()
9
+ },
10
+ required: [
11
+ 'filePath',
12
+ 'content'
13
+ ]
14
+ });
15
+ const populateFileParams = mergeSchema().oneOf([
16
+ populateFileParam,
17
+ arraySchema({
18
+ items: populateFileParam
19
+ })
20
+ ]);
21
+ export const isPopulateFileParams = new Ajv({
22
+ strict: true
23
+ }).compile(populateFileParams.toJSON());
24
+
25
+ //# sourceMappingURL=populate-files-validator.js.map
@@ -0,0 +1,14 @@
1
+ import type { PopulateFiles, PopulationResponse } from 'populate-files';
2
+ import type { LoadFile } from './loader.js';
3
+ import type { NormalizeParams } from './normalize.js';
4
+ import type { RawOptions, RawParams } from './types.js';
5
+ 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
+ }
14
+ //# sourceMappingURL=load-populate-files.d.ts.map
@@ -0,0 +1,19 @@
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
+ }
18
+
19
+ //# sourceMappingURL=load-populate-files.js.map
@@ -1,3 +1,5 @@
1
1
  import type { PopulateFileParams } from 'populate-files';
2
- export declare const loadFile: (filePath: string) => Promise<PopulateFileParams[]>;
2
+ import type { Importer } from './lib/dependencies.js';
3
+ export type LoadFile = (filePath: string) => Promise<PopulateFileParams[]>;
4
+ export declare const loadFileProvider: (importer: Importer) => LoadFile;
3
5
  //# sourceMappingURL=loader.d.ts.map
@@ -1,9 +1,19 @@
1
1
  import { defaultImport } from 'default-import';
2
- export const loadFile = async (filePath)=>{
3
- const mod = await import(filePath);
4
- const params = defaultImport(mod);
5
- return [
6
- params
7
- ].flat();
8
- };
9
- //# sourceMappingURL=loader.js.map
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();
15
+ }
16
+ throw new Error(`File content does not fulfill populate-file input at: ${filePath}`);
17
+ };
18
+
19
+ //# sourceMappingURL=loader.js.map
@@ -1,3 +1,5 @@
1
+ import type { ParseCwd } from 'parse-cwd';
1
2
  import type { NormalizedParams, RawOptions, RawParams } from './types.js';
2
- export declare const normalizeParams: (params: RawParams, options?: RawOptions) => Promise<NormalizedParams>;
3
+ export type NormalizeParams = (params: RawParams, options?: RawOptions) => Promise<NormalizedParams>;
4
+ export declare const normalizeParamsProvider: (parseCwd: ParseCwd) => NormalizeParams;
3
5
  //# sourceMappingURL=normalize.d.ts.map
@@ -1,14 +1,14 @@
1
1
  import Path from 'node:path';
2
- import { parseCwd } from 'npm-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
- }
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
+ };
12
12
  };
13
- };
14
- //# sourceMappingURL=normalize.js.map
13
+
14
+ //# sourceMappingURL=normalize.js.map
@@ -1,4 +1,4 @@
1
- import type { Directory } from 'npm-parse-cwd';
1
+ import type { Directory } from 'parse-cwd';
2
2
  export interface RawParams {
3
3
  filePath: string;
4
4
  }
package/dist/lib/types.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { };
2
- //# sourceMappingURL=types.js.map
2
+
3
+ //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "0.0.11",
3
+ "version": "0.1.1",
4
4
  "description": "Load and dynamically populate file content",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -16,27 +16,46 @@
16
16
  "keywords": [
17
17
  "content",
18
18
  "write",
19
- "build"
19
+ "build",
20
+ "cli"
20
21
  ],
21
22
  "sideEffects": false,
22
23
  "exports": {
23
24
  ".": "./dist/index.js"
24
25
  },
26
+ "bin": {
27
+ "load-populate-files": "./bin.mjs"
28
+ },
25
29
  "dependencies": {
26
- "npm-parse-cwd": "npm:parse-cwd@latest",
27
- "populate-files": "^0.1.2",
28
- "default-import": "^2.0.4"
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"
29
40
  },
30
41
  "devDependencies": {
31
42
  "@biomejs/biome": "^1.9.4",
43
+ "@swc/cli": "^0.5.2",
44
+ "@swc/core": "^1.10.4",
32
45
  "@types/chai": "^5.0.1",
33
- "@types/mocha": "^10.0.9",
34
- "@types/node": "^22.8.6",
46
+ "@types/chai-as-promised": "^8.0.1",
47
+ "@types/mocha": "^10.0.10",
48
+ "@types/node": "^22.10.2",
49
+ "@types/yargs": "^17.0.33",
50
+ "c8": "^10.1.3",
35
51
  "chai": "^5.1.2",
36
- "mocha": "^10.8.2",
37
- "npm-nx-update-ts-references": "npm:nx-update-ts-references@latest",
38
- "typescript": "^5.6.3",
39
- "@leyman/eslint-config": "^0.0.4",
40
- "nx-tsc": "^0.0.13"
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"
41
60
  }
42
61
  }