load-populate-files 1.0.3 → 1.1.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/README.md CHANGED
@@ -8,13 +8,15 @@ 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).
12
+
11
13
  ## Contents
12
14
 
13
15
  - [Install](#install)
14
16
  - [Example](#example)
15
17
  - [Usage](#usage)
16
18
  - [API](#api)
17
- - [loadAndPopulateFiles](#loadandpopulatefilesfilepath-options)
19
+ - [loadAndPopulateFiles](#loadandpopulatefilesparams-options)
18
20
  - [Types](#types)
19
21
  - [PopulateFileParams](#populatefileparams)
20
22
  - [Also See](#also-see)
@@ -45,7 +47,7 @@ export default [
45
47
  // index.ts
46
48
  import { loadAndPopulateFiles } from 'load-populate-files';
47
49
 
48
- await loadAndPopulateFiles('./config.js');
50
+ await loadAndPopulateFiles({ filePath: './config.js' });
49
51
  ```
50
52
 
51
53
  ## Usage
@@ -63,18 +65,18 @@ pnpx load-populate-files --file-path ./config.js
63
65
 
64
66
  ## API
65
67
 
66
- ### `loadAndPopulateFiles(filePath, options?)`
68
+ ### `loadAndPopulateFiles(params, options?)`
67
69
 
68
- Loads the config exported at `filePath` and passes it to [`populateFiles()`](https://www.npmjs.com/package/populate-files#populatefilesparams-options).
70
+ Loads the config exported at `params.filePath` and passes it to [`populateFiles()`](https://www.npmjs.com/package/populate-files#populatefilesparams-options).
69
71
 
70
72
  **Parameters**
71
73
 
72
74
  | Parameter | Type | Default | Description |
73
75
  |-----------|------|---------|-------------|
74
- | `filePath` | `string` | — | Required. Path to the config module. When using the CLI, pass as `--file-path`. |
76
+ | `params.filePath` | `string` | — | Required. Path to the config module, resolved from `options.cwd`. When using the CLI, pass as `--file-path`. |
75
77
  | `options` | `object` | `{}` | Optional. See [options](#options) below. |
76
78
 
77
- **Returns** `Promise<void>`
79
+ **Returns** `Promise<PopulationResponse[]>`, from `populateFiles()`.
78
80
 
79
81
  #### `options`
80
82
 
@@ -86,7 +88,9 @@ Options are passed through to the underlying `populateFiles()` call. They are al
86
88
  | `dryRun` | `--dry-run` | `boolean` | `false` | If `true`, does not write any files regardless of changes. Can still fail if `check` is `true`. |
87
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. |
88
90
  | `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. |
91
+ | `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
+ | `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). |
93
+ | `manifest` | `--manifest` | `string` | — | Path of a manifest (relative to `cwd`) recording the generated files, to detect edits to any file type and `clean` only files it lists. See [`populate-files`](https://www.npmjs.com/package/populate-files#manifest). |
90
94
 
91
95
  ## Types
92
96
 
@@ -105,6 +109,8 @@ export default {
105
109
 
106
110
  This type can also be imported directly from [`populate-files`](https://www.npmjs.com/package/populate-files).
107
111
 
112
+ Configs may set `signed: true` (with string content) to sign the file and keep its manual sections, see [signed files](https://www.npmjs.com/package/populate-files#signed-files).
113
+
108
114
  ## Also See
109
115
 
110
116
  - [`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
@@ -4,6 +4,8 @@ interface LoadPopulateFilesCommandExtendedInput extends LoadPopulateFilesCommand
4
4
  ci: boolean;
5
5
  dryRun: boolean;
6
6
  clean: boolean;
7
+ force: boolean;
8
+ manifest: string | undefined;
7
9
  }
8
10
  /**
9
11
  * Main `load-populate-files` command
@@ -29,6 +29,15 @@ export const loadPopulateFilesCommand = {
29
29
  describe: 'Remove files in --target-dir that were not generated. In --ci mode, fail instead of removing.',
30
30
  type: 'boolean',
31
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'
32
41
  }
33
42
  }).strict(),
34
43
  handler: async (options)=>{
@@ -39,7 +48,9 @@ export const loadPopulateFilesCommand = {
39
48
  targetDir: options.targetDir,
40
49
  check: options.ci,
41
50
  dryRun: options.dryRun,
42
- clean: options.clean
51
+ clean: options.clean,
52
+ force: options.force,
53
+ manifest: options.manifest
43
54
  });
44
55
  }
45
56
  };
@@ -1,8 +1,3 @@
1
- export declare const isPopulateFileParams: (x: unknown) => x is {
2
- filePath: string;
3
- content: (Promise<import("populate-files").FileContent> | import("populate-files").FileContent | undefined) & (Promise<import("populate-files").FileContent> | import("populate-files").FileContent);
4
- }[] | {
5
- filePath: string;
6
- content: (Promise<import("populate-files").FileContent> | import("populate-files").FileContent | undefined) & (Promise<import("populate-files").FileContent> | import("populate-files").FileContent);
7
- };
1
+ import type { PopulateFileParams } from 'populate-files';
2
+ export declare const isPopulateFileParams: (x: unknown) => x is PopulateFileParams[] | PopulateFileParams;
8
3
  //# sourceMappingURL=populate-files-validator.d.ts.map
@@ -1,15 +1,16 @@
1
- import { arraySchema, mergeSchema, objectSchema, stringSchema } from 'juniper';
1
+ import { arraySchema, booleanSchema, mergeSchema, objectSchema, stringSchema } from 'juniper';
2
2
  import { makeValidator } from 'juniper-validator';
3
3
  const populateFileParam = objectSchema({
4
4
  properties: {
5
5
  filePath: stringSchema(),
6
- content: mergeSchema().cast()
6
+ content: mergeSchema().cast(),
7
+ signed: booleanSchema()
7
8
  },
8
9
  required: [
9
10
  'filePath',
10
11
  'content'
11
12
  ]
12
- });
13
+ }).cast();
13
14
  const populateFileParams = mergeSchema().oneOf([
14
15
  populateFileParam,
15
16
  arraySchema({
@@ -9,7 +9,9 @@ export const normalizeParams = async (params, options = {})=>{
9
9
  check: options.check,
10
10
  dryRun: options.dryRun,
11
11
  targetDir: options.targetDir,
12
- clean: options.clean
12
+ clean: options.clean,
13
+ force: options.force,
14
+ manifest: options.manifest
13
15
  }
14
16
  };
15
17
  };
@@ -8,6 +8,8 @@ export interface RawOptions {
8
8
  check?: boolean | null | undefined;
9
9
  dryRun?: boolean | null | undefined;
10
10
  clean?: boolean | null | undefined;
11
+ force?: boolean | null | undefined;
12
+ manifest?: string | null | undefined;
11
13
  }
12
14
  export interface NormalizedParams {
13
15
  filePath: string;
@@ -17,6 +19,8 @@ export interface NormalizedParams {
17
19
  check?: boolean | null | undefined;
18
20
  dryRun?: boolean | null | undefined;
19
21
  clean?: boolean | null | undefined;
22
+ force?: boolean | null | undefined;
23
+ manifest?: string | null | undefined;
20
24
  };
21
25
  }
22
26
  //# sourceMappingURL=types.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Load and dynamically populate file content",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -42,10 +42,10 @@
42
42
  "entry-script": "^4.1.0",
43
43
  "haywire": "^2.0.0",
44
44
  "haywire-launcher": "^1.0.2",
45
- "juniper": "^2.2.1",
45
+ "juniper": "^2.3.0",
46
46
  "juniper-validator": "^0.3.0",
47
47
  "parse-cwd": "^2.0.2",
48
- "populate-files": "^1.0.2",
48
+ "populate-files": "^1.1.0",
49
49
  "unknown-error": "^0.1.0",
50
50
  "yargs": "^18.2.0"
51
51
  },
@@ -61,8 +61,10 @@
61
61
  "@typescript/native": "npm:typescript@^7.0.2",
62
62
  "c8": "^12.0.0",
63
63
  "eslint": "^10.12.0",
64
+ "generated-signature": "^0.1.0",
64
65
  "mocha": "^12.0.2",
65
66
  "mocha-chain": "^1.0.1",
67
+ "tmp-promise": "^3.0.3",
66
68
  "typescript": "npm:@typescript/typescript6@^6.0.2"
67
69
  },
68
70
  "imports": {