nodecommons-esm-config 0.0.2

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.
@@ -0,0 +1,4 @@
1
+ import { CommonsConfigFile } from './commons-config-file.mjs';
2
+ export declare class CommonsConfigEnvironmentVariable extends CommonsConfigFile {
3
+ constructor(variable: string);
4
+ }
@@ -0,0 +1,15 @@
1
+ import { commonsEnvGetStringOrUndefined } from 'nodecommons-esm-cli';
2
+ import { commonsFileCwdRelativeOrAbsolutePath } from 'nodecommons-esm-file';
3
+ import { CommonsConfigFile } from './commons-config-file.mjs';
4
+ function assertEnvironmentVariable(variable) {
5
+ const file = commonsEnvGetStringOrUndefined(variable);
6
+ if (!file)
7
+ throw new Error(`No such environment variable exists for ${variable}`);
8
+ return commonsFileCwdRelativeOrAbsolutePath(file);
9
+ }
10
+ export class CommonsConfigEnvironmentVariable extends CommonsConfigFile {
11
+ constructor(variable) {
12
+ super(assertEnvironmentVariable(variable));
13
+ }
14
+ }
15
+ //# sourceMappingURL=commons-config-etc.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commons-config-etc.mjs","sourceRoot":"","sources":["../../src/classes/commons-config-etc.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,oCAAoC,EAAE,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAE9D,SAAS,yBAAyB,CAAC,QAAgB;IAClD,MAAM,IAAI,GAAqB,8BAA8B,CAAC,QAAQ,CAAC,CAAC;IACxE,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CAAC;IAElF,OAAO,oCAAoC,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,OAAO,gCAAiC,SAAQ,iBAAiB;IAEtE,YACE,QAAgB;QAEjB,KAAK,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5C,CAAC;CACD"}
@@ -0,0 +1,10 @@
1
+ import { TPropertyObject } from 'tscommons-esm-core';
2
+ import { CommonsConfig } from 'tscommons-esm-config';
3
+ export declare function readFileAsPropertyObject(filepath: string): TPropertyObject;
4
+ export declare class CommonsConfigFile extends CommonsConfig {
5
+ private filepath;
6
+ constructor(filepath?: string);
7
+ getFilepath(): string | undefined;
8
+ saveAs(filepath: string): void;
9
+ save(): void;
10
+ }
@@ -0,0 +1,35 @@
1
+ import { commonsTypeIsEncodedObject, commonsTypeDecodePropertyObject, commonsTypeEncodePropertyObject } from 'tscommons-esm-core';
2
+ import { CommonsConfig } from 'tscommons-esm-config';
3
+ import { commonsFileReadTextFile, commonsFileWriteTextFile, commonsFileIsFile } from 'nodecommons-esm-file';
4
+ export function readFileAsPropertyObject(filepath) {
5
+ const data = commonsFileReadTextFile(filepath);
6
+ if (data === undefined)
7
+ throw new Error(`Unable to read config file from ${filepath}`);
8
+ const parsed = JSON.parse(data);
9
+ if (!commonsTypeIsEncodedObject(parsed))
10
+ throw new Error('Config file is not JSON object');
11
+ return commonsTypeDecodePropertyObject(parsed);
12
+ }
13
+ export class CommonsConfigFile extends CommonsConfig {
14
+ filepath;
15
+ constructor(filepath) {
16
+ super((filepath && commonsFileIsFile(filepath))
17
+ ? readFileAsPropertyObject(filepath)
18
+ : {});
19
+ this.filepath = filepath;
20
+ }
21
+ getFilepath() {
22
+ return this.filepath;
23
+ }
24
+ saveAs(filepath) {
25
+ const encoded = commonsTypeEncodePropertyObject(super.getRawObject());
26
+ const stringify = JSON.stringify(encoded, null, '\t');
27
+ commonsFileWriteTextFile(filepath, stringify);
28
+ }
29
+ save() {
30
+ if (!this.filepath)
31
+ throw new Error('No filepath was supplied at the time of CommonsConfigFile creation. Cannot save.');
32
+ this.saveAs(this.filepath);
33
+ }
34
+ }
35
+ //# sourceMappingURL=commons-config-file.mjs.map
@@ -0,0 +1 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AAE,IAAI,CAAC,CAAC;QAE9D,wBAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAC/C,CAAC;IAEM,IAAI;QACV,IAAI,CAAC,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;QACxH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;CACD"}
@@ -0,0 +1,3 @@
1
+ import { CommonsConfigEnvironmentVariable } from './classes/commons-config-etc.mjs';
2
+ import { readFileAsPropertyObject, CommonsConfigFile } from './classes/commons-config-file.mjs';
3
+ export { CommonsConfigEnvironmentVariable, readFileAsPropertyObject, CommonsConfigFile };
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { CommonsConfigEnvironmentVariable } from './classes/commons-config-etc.mjs';
2
+ import { readFileAsPropertyObject, CommonsConfigFile } from './classes/commons-config-file.mjs';
3
+ export { CommonsConfigEnvironmentVariable, readFileAsPropertyObject, CommonsConfigFile };
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAChG,OAAO,EACN,gCAAgC,EAChC,wBAAwB,EACxB,iBAAiB,EACjB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "nodecommons-esm-config",
3
+ "version": "0.0.2",
4
+ "description": "",
5
+ "scripts": {
6
+ "tsc": "./node_modules/typescript/bin/tsc",
7
+ "preprepare": "rm -rf ./dist; php ~/Dev/etim.php src/ && npm run tsc",
8
+ "publish-major": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version major && npm install && npm publish && git add . && git commit -m 'publish'",
9
+ "publish-minor": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version minor && npm install && npm publish && git add . && git commit -m 'publish'",
10
+ "publish-patch": "rm -rf dist; npm run tsc && npx eslint . && npm run preprepare && npm version patch && npm install && npm publish && git add . && git commit -m 'publish'"
11
+ },
12
+ "main": "dist/index.mjs",
13
+ "types": "dist/index.d.mjs",
14
+ "type": "module",
15
+ "author": "Pete Morris",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@stylistic/eslint-plugin-ts": "^2.10.1",
19
+ "@types/node": "^22.9.0",
20
+ "eslint-plugin-import": "^2.31.0",
21
+ "eslint-plugin-prefer-arrow-functions": "^3.4.1",
22
+ "typescript": "^5.6.3",
23
+ "typescript-eslint": "^8.14.0"
24
+ },
25
+ "files": [
26
+ "dist/**/*"
27
+ ],
28
+ "dependencies": {
29
+ "nodecommons-esm-cli": "^0.0.2",
30
+ "nodecommons-esm-file": "^0.0.2",
31
+ "tscommons-esm-config": "^0.0.2",
32
+ "tscommons-esm-core": "^0.0.2"
33
+ }
34
+ }