load-populate-files 0.0.2 → 0.0.3

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/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # load-populate-files
2
+
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 31f81fa: Internal dependency updates
8
+ - 86a26b1: Add README
9
+ - 3e7ee18: Dependency bumps
10
+ - f6a4729: Update year in LICENSE
11
+ - 9c786d0: Update dependencies
12
+ - 329146b: Add README
13
+ - Updated dependencies [31f81fa]
14
+ - Updated dependencies [85c052c]
15
+ - Updated dependencies [86a26b1]
16
+ - Updated dependencies [3e7ee18]
17
+ - Updated dependencies [f6a4729]
18
+ - Updated dependencies [9c786d0]
19
+ - populate-files@0.0.3
20
+ - default-import@1.1.6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jacob Ley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ <div style="text-align:center">
2
+
3
+ # load-populate-files
4
+ Load and dynamically populate file content based on a single files config.
5
+
6
+ [![npm package](https://badge.fury.io/js/load-populate-files.svg)](https://www.npmjs.com/package/load-populate-files)
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
+
9
+ </div>
10
+
11
+ ## Table of Contents
12
+
13
+ - [Introduction](#introduction)
14
+ - [Installation](#installation)
15
+ - [Usage](#usage)
16
+ - [API](#api)
17
+ - [loadAndPopulateFiles](#loadandpopulatefilesfilepath-options)
18
+ - [Types](#types)
19
+ - [PopulateFileParams](#populatefileparams)
20
+ - [Also See](#also-see)
21
+
22
+ ## Introduction
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()`
39
+
40
+ Options are supported the same as `populateFiles()`.
41
+
42
+ ```ts
43
+ // config.ts
44
+ export default [
45
+ {
46
+ filePath: './foo.json',
47
+ content: { bar: 123 },
48
+ },
49
+ {
50
+ filePath: './abc.js',
51
+ content: `
52
+ console.log('Hello World!');
53
+ `,
54
+ },
55
+ ];
56
+
57
+ // index.ts
58
+ await loadAndPopulateFiles('./config.js');
59
+ ```
60
+
61
+ ## API
62
+
63
+ ### loadAndPopulateFiles(filePath, options)
64
+
65
+ Loads the config specified at `filePath`, and passes that to [populateFiles()](https://www.npmjs.com/package/populate-files#populatefilesparams-options).
66
+
67
+ The loaded file may either be a single object config, or an array of separate configs.
68
+
69
+ #### options
70
+
71
+ An optional object as the secondary parameter. Passed to underlying `populateFiles()` call.
72
+
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 |
78
+
79
+ ## Types
80
+
81
+ ### PopulateFileParams
82
+
83
+ 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.
84
+
85
+ ```ts
86
+ import type { PopulateFileParams } from 'load-populate-files';
87
+
88
+ export default {
89
+ filePath: './foo.json',
90
+ content: { bar: 123 },
91
+ } satisfies PopulateFileParams;
92
+ ```
93
+
94
+ Note this type can also be imported from [populate-files](https://www.npmjs.com/package/populate-files) directly.
95
+
96
+ ## Also See
97
+
98
+ ### [parse-cwd](https://www.npmjs.com/package/parse-cwd)
99
+
100
+ Used internally to interpret `cwd` option.
101
+
102
+ ### [populate-files](https://www.npmjs.com/package/populate-files)
103
+
104
+ Populate and format a file based on dynamic content.
105
+
106
+ ### [nx-populate-files](https://www.npmjs.com/package/nx-populate-files)
107
+
108
+ Load and populate files as an nx target.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { populateFiles } from "populate-files";
2
- import { loadFile } from "./lib/loader.js";
3
- import { normalizeParams } from "./lib/normalize.js";
1
+ import { populateFiles } from 'populate-files';
2
+ import { loadFile } from './lib/loader.js';
3
+ import { normalizeParams } from './lib/normalize.js';
4
4
  export const loadAndPopulateFiles = async (params, options)=>{
5
5
  const normalized = await normalizeParams(params, options);
6
6
  const files = await loadFile(normalized.filePath);
@@ -1,4 +1,4 @@
1
- import { defaultImport } from "default-import";
1
+ import { defaultImport } from 'default-import';
2
2
  export const loadFile = async (filePath)=>{
3
3
  const mod = await import(filePath);
4
4
  const params = defaultImport(mod);
@@ -1,9 +1,9 @@
1
- import { resolve } from "node:path";
2
- import { parseCwd } from "npm-parse-cwd";
1
+ import Path from 'node:path';
2
+ import { parseCwd } from 'npm-parse-cwd';
3
3
  export const normalizeParams = async (params, options = {})=>{
4
4
  const cwd = await parseCwd(options.cwd);
5
5
  return {
6
- filePath: resolve(cwd, params.filePath),
6
+ filePath: Path.resolve(cwd, params.filePath),
7
7
  options: {
8
8
  cwd,
9
9
  check: options.check,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "load-populate-files",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Load and dynamically populate file content",
5
5
  "engines": {
6
- "node": ">=18"
6
+ "node": ">=20"
7
7
  },
8
8
  "type": "module",
9
9
  "author": "JacobLey",
@@ -23,21 +23,21 @@
23
23
  ".": "./dist/index.js"
24
24
  },
25
25
  "dependencies": {
26
- "npm-parse-cwd": "npm:parse-cwd@^1.0.8",
27
- "populate-files": "^0.0.2",
28
- "default-import": "^1.1.5"
26
+ "npm-parse-cwd": "npm:parse-cwd@latest",
27
+ "populate-files": "^0.0.3",
28
+ "default-import": "^1.1.6"
29
29
  },
30
30
  "devDependencies": {
31
- "@biomejs/biome": "^1.6.4",
32
- "@types/chai": "^4.3.12",
33
- "@types/mocha": "^10.0.6",
34
- "@types/node": "^20.11.26",
35
- "chai": "^5.1.0",
36
- "mocha": "^10.4.0",
37
- "npm-nx-update-ts-references": "npm:nx-update-ts-references@^0.0.2",
38
- "nyc": "^15.1.0",
39
- "typescript": "^5.4.3",
40
- "@leyman/eslint-config": "^0.0.0",
41
- "nx-tsc": "^0.0.4"
31
+ "@biomejs/biome": "^1.8.3",
32
+ "@types/chai": "^4.3.17",
33
+ "@types/mocha": "^10.0.7",
34
+ "@types/node": "^22.1.0",
35
+ "chai": "^5.1.1",
36
+ "mocha": "^10.7.0",
37
+ "npm-nx-update-ts-references": "npm:nx-update-ts-references@latest",
38
+ "nyc": "^17.0.0",
39
+ "typescript": "^5.5.4",
40
+ "nx-tsc": "^0.0.7",
41
+ "@leyman/eslint-config": "^0.0.0"
42
42
  }
43
43
  }