Compare commits
161 Commits
Author | SHA1 | Date | |
---|---|---|---|
5e0edecf18 | |||
70cefc00fa | |||
6f14c73b5f | |||
1e6f636608 | |||
eff77f8976 | |||
b5f109d320 | |||
3a53938e8e | |||
db90714a81 | |||
b81ab9d9b2 | |||
5ec9124d29 | |||
f7f035e878 | |||
3caf300544 | |||
6a70af9b6f | |||
2ad3da85a9 | |||
09e8b8b94c | |||
265f4df8b3 | |||
5461ec0636 | |||
937252f99e | |||
6f19c3cc71 | |||
4be54f6dcc | |||
5c6702b898 | |||
f1ecda411a | |||
267d2c392d | |||
2ca82fb28b | |||
b342602ca0 | |||
bb72e1c2c0 | |||
40ad00e75a | |||
de1db395cd | |||
83968d578c | |||
155cd8bd6a | |||
5eebd0fd02 | |||
686aa0d2e7 | |||
f97d72da28 | |||
78d1540ce0 | |||
916dd116c1 | |||
5fd57cb56b | |||
1a106e322c | |||
36ded40032 | |||
44f5f84195 | |||
72655a6a0e | |||
961df11121 | |||
ee6f5e63ee | |||
a40b6adeef | |||
6ee324a0ef | |||
215a48a409 | |||
aeaa6149e4 | |||
75059dfca8 | |||
90c0f30ce1 | |||
9a55303978 | |||
224125fb8e | |||
df9d197508 | |||
ae33716af4 | |||
31b64eda5e | |||
7f3437e3cd | |||
8903bee78d | |||
a02b45a673 | |||
e7883f5997 | |||
39ab01b4af | |||
bb9de1b13b | |||
080e133e9f | |||
a284c58a68 | |||
18bb54831d | |||
141c7ed8a7 | |||
037481f195 | |||
e414e392d3 | |||
4f7e382bc9 | |||
1c0b428606 | |||
90e8625771 | |||
abbce0d4a1 | |||
93c65acc95 | |||
a68d59a4d2 | |||
0133dca698 | |||
6174490e8e | |||
d952a761b2 | |||
05909f776e | |||
779883fbab | |||
349f074bb9 | |||
d209661586 | |||
3ce6036478 | |||
54bf310403 | |||
2ec485048b | |||
caca370e77 | |||
45deb1a8d2 | |||
4c9d3c7148 | |||
320c627d4f | |||
d834e0a220 | |||
86427ac05d | |||
dc59682c15 | |||
45ebf0944c | |||
677aa4f0ea | |||
7f0985f24d | |||
5f2f7e2b39 | |||
26a6ac9651 | |||
072ee31c3f | |||
8fa3fd8ac1 | |||
102422c9c7 | |||
2e95824ff4 | |||
c85c0d3035 | |||
68da8c7841 | |||
a12418ba9c | |||
1664eee3fe | |||
6112f430c9 | |||
3d486c76a9 | |||
2634bb282b | |||
fedc4c5f5b | |||
39ef242615 | |||
211529ffff | |||
d4f5d19231 | |||
80d6a5103a | |||
c22bbe2daf | |||
82af55fae9 | |||
90f8ee4e9d | |||
4fe85134c4 | |||
c307b7c7b0 | |||
e4f608f7eb | |||
0689e33ae6 | |||
7109b666f5 | |||
11bb21e0e0 | |||
4fdc985461 | |||
bd4de83e83 | |||
545e792751 | |||
4fa25477ad | |||
95de67fe17 | |||
2ec33a118a | |||
bb1293c764 | |||
344f144c2c | |||
07cdcb074d | |||
09d9fd45cf | |||
9883067d8b | |||
854dac5732 | |||
73c37d8bf8 | |||
f0664d4c7d | |||
3dff5dbbc6 | |||
15e3497c55 | |||
4184e8f20f | |||
5ebee20a7a | |||
a6aa1b06da | |||
07610c007c | |||
f056e062b3 | |||
00855e3d63 | |||
d5fea19831 | |||
4c3715f655 | |||
513bb686ef | |||
b1f8c79b8d | |||
b0dbb9b8a0 | |||
83108ce02d | |||
2911dd4972 | |||
16150541b0 | |||
002f3fc82d | |||
6925c2dbd0 | |||
156b64b699 | |||
77da229633 | |||
0cbea12067 | |||
e6b12b2c6d | |||
d8c37a8b95 | |||
3b83cfaaac | |||
febc3aa164 | |||
643fb6a6b7 | |||
51b734ef96 | |||
7d700f3285 | |||
|
4ee9c46b04 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
21
.gitignore
vendored
21
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
docs/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
@ -1,35 +0,0 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -1,4 +0,0 @@
|
|||||||
# npmextra
|
|
||||||
do more with npm
|
|
||||||
|
|
||||||
npmextra is a hub for a series of js tools that help writing, documenting and maintaining npm modules.
|
|
57
changelog.md
Normal file
57
changelog.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-11-06 - 5.1.2 - fix(appdata)
|
||||||
|
Fix iteration over overwriteObject in AppData class
|
||||||
|
|
||||||
|
- Corrected the for loop from in to of inside the AppData class for iterating over overwriteObject keys.
|
||||||
|
|
||||||
|
## 2024-11-05 - 5.1.1 - fix(AppData)
|
||||||
|
Fix issue with overwrite object handling in AppData class
|
||||||
|
|
||||||
|
- Corrected logic to handle cases when overwriteObject is undefined.
|
||||||
|
|
||||||
|
## 2024-11-05 - 5.1.0 - feat(appdata)
|
||||||
|
Add support for overwriting keys using the overwriteObject option in AppData
|
||||||
|
|
||||||
|
- Introduced the overwriteObject option in IAppDataOptions to allow overwriting specific keys in the AppData class.
|
||||||
|
|
||||||
|
## 2024-06-19 - 5.0.17 - 5.0.23 - Core Updates
|
||||||
|
Routine maintenance and updates to the core components.
|
||||||
|
|
||||||
|
- Multiple core updates and fixes improving stability
|
||||||
|
|
||||||
|
## 2024-06-12 - 5.0.13 - 5.0.16 - Core Updates
|
||||||
|
Maintenance focus on core systems with enhancements and problem resolutions.
|
||||||
|
|
||||||
|
- Enhancements and updates in the core functionality
|
||||||
|
|
||||||
|
## 2024-05-29 - 5.0.13 - Documentation Update
|
||||||
|
Descriptive improvements aligned with current features.
|
||||||
|
|
||||||
|
- Updated core description for better clarity in documentation
|
||||||
|
|
||||||
|
## 2024-04-01 - 5.0.10 - Configuration Update
|
||||||
|
Improved configuration management for build processes.
|
||||||
|
|
||||||
|
- Updated `npmextra.json` to reflect changes in git repository management
|
||||||
|
|
||||||
|
## 2024-02-12 - 5.0.0 - 5.0.9 - Major Core Enhancements
|
||||||
|
A series of critical updates with resolved issues in the core components.
|
||||||
|
|
||||||
|
- Introduction of new core features
|
||||||
|
- Several core system updates
|
||||||
|
|
||||||
|
## 2024-02-12 - 4.0.16 - Major Version Transition
|
||||||
|
Migration to the new major version with impactful changes.
|
||||||
|
|
||||||
|
- BREAKING CHANGE: Significant updates requiring attention for smooth transition
|
||||||
|
|
||||||
|
## 2023-08-24 - 3.0.9 - 4.0.16 - Organization Updates
|
||||||
|
Formatted updates with attention to organizational standards and practice.
|
||||||
|
|
||||||
|
- SWITCH to a new organizational scheme
|
||||||
|
|
||||||
|
## 2023-07-11 - 3.0.9 - Organizational Enhancement
|
||||||
|
Shifts aligning with contemporary structuring and logistics.
|
||||||
|
|
||||||
|
- Strategic realignment with organizational principles
|
7
dist/index.d.ts
vendored
7
dist/index.d.ts
vendored
@ -1,7 +0,0 @@
|
|||||||
export interface IDataFor {
|
|
||||||
toolName: string;
|
|
||||||
defaultSettings?: any;
|
|
||||||
cwd?: string;
|
|
||||||
}
|
|
||||||
export declare let dataFor: (optionsArg: IDataFor) => any;
|
|
||||||
export declare let configFilePresent: () => boolean;
|
|
50
dist/index.js
vendored
50
dist/index.js
vendored
@ -1,50 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./npmextra.plugins");
|
|
||||||
const paths = require("./npmextra.paths");
|
|
||||||
exports.dataFor = (optionsArg) => {
|
|
||||||
// handle default settings
|
|
||||||
if (typeof optionsArg.toolName != undefined
|
|
||||||
&& typeof optionsArg.defaultSettings != undefined) {
|
|
||||||
let newDefaultOptions = {};
|
|
||||||
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
|
|
||||||
optionsArg.defaultSettings = newDefaultOptions;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
// set lookup path
|
|
||||||
let lookupPath;
|
|
||||||
if (optionsArg.cwd) {
|
|
||||||
lookupPath = plugins.path.join(optionsArg.cwd, "npmextra.json");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lookupPath = paths.configFile;
|
|
||||||
}
|
|
||||||
;
|
|
||||||
// get allData
|
|
||||||
let allData;
|
|
||||||
if (plugins.smartfile.fs.fileExistsSync(lookupPath)) {
|
|
||||||
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
plugins.beautylog.warn(`${lookupPath} is missing!`);
|
|
||||||
allData = {};
|
|
||||||
}
|
|
||||||
;
|
|
||||||
//assign all data
|
|
||||||
allData = plugins.lodash.merge({}, optionsArg.defaultSettings, allData);
|
|
||||||
if (optionsArg.toolName) {
|
|
||||||
if (allData[optionsArg.toolName]) {
|
|
||||||
return allData[optionsArg.toolName];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return allData;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
exports.configFilePresent = () => {
|
|
||||||
return plugins.smartfile.fs.fileExistsSync(paths.configFile);
|
|
||||||
};
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQ3pCLENBQUMsQ0FENEM7QUFDN0MsTUFBWSxLQUFLLFdBQU0sa0JBQWtCLENBQUMsQ0FBQTtBQVEvQixlQUFPLEdBQUcsQ0FBQyxVQUFtQjtJQUVyQywwQkFBMEI7SUFDMUIsRUFBRSxDQUFBLENBQ0UsT0FBTyxVQUFVLENBQUMsUUFBUSxJQUFJLFNBQVM7V0FDcEMsT0FBTyxVQUFVLENBQUMsZUFBZSxJQUFJLFNBQzVDLENBQUMsQ0FBQSxDQUFDO1FBQ0UsSUFBSSxpQkFBaUIsR0FBRyxFQUFFLENBQUM7UUFDM0IsaUJBQWlCLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxHQUFHLFVBQVUsQ0FBQyxlQUFlLENBQUM7UUFDcEUsVUFBVSxDQUFDLGVBQWUsR0FBRyxpQkFBaUIsQ0FBQztJQUNuRCxDQUFDO0lBQUEsQ0FBQztJQUVGLGtCQUFrQjtJQUNsQixJQUFJLFVBQWlCLENBQUM7SUFDdEIsRUFBRSxDQUFBLENBQUMsVUFBVSxDQUFDLEdBQUcsQ0FBQyxDQUFBLENBQUM7UUFDZixVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLEdBQUcsRUFBQyxlQUFlLENBQUMsQ0FBQztJQUNuRSxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixVQUFVLEdBQUcsS0FBSyxDQUFDLFVBQVUsQ0FBQztJQUNsQyxDQUFDO0lBQUEsQ0FBQztJQUVGLGNBQWM7SUFDZCxJQUFJLE9BQU8sQ0FBQztJQUNaLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLGNBQWMsQ0FBQyxVQUFVLENBQUMsQ0FBQyxDQUFBLENBQUM7UUFDaEQsT0FBTyxHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxVQUFVLENBQUMsQ0FBQztJQUM1RCxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxHQUFHLFVBQVUsY0FBYyxDQUFDLENBQUM7UUFDcEQsT0FBTyxHQUFHLEVBQUUsQ0FBQztJQUNqQixDQUFDO0lBQUEsQ0FBQztJQUVGLGlCQUFpQjtJQUNqQixPQUFPLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxFQUFDLFVBQVUsQ0FBQyxlQUFlLEVBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEUsRUFBRSxDQUFBLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxDQUFBLENBQUM7UUFDcEIsRUFBRSxDQUFBLENBQUMsT0FBTyxDQUFDLFVBQVUsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDN0IsTUFBTSxDQUFDLE9BQU8sQ0FBQyxVQUFVLENBQUMsUUFBUSxDQUFDLENBQUM7UUFDeEMsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osT0FBTyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsd0JBQXdCLFVBQVUsQ0FBQyxRQUFRLEVBQUUsQ0FBQyxDQUFDO1lBQ3ZFLE1BQU0sQ0FBQyxTQUFTLENBQUM7UUFDckIsQ0FBQztJQUNMLENBQUM7SUFBQyxJQUFJLENBQUMsQ0FBQztRQUNKLE1BQU0sQ0FBQyxPQUFPLENBQUM7SUFDbkIsQ0FBQztBQUNMLENBQUMsQ0FBQztBQUVTLHlCQUFpQixHQUFHO0lBQzNCLE1BQU0sQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0FBQ2pFLENBQUMsQ0FBQSJ9
|
|
3
dist/npmextra.paths.d.ts
vendored
3
dist/npmextra.paths.d.ts
vendored
@ -1,3 +0,0 @@
|
|||||||
export declare let cwd: string;
|
|
||||||
export declare let packageDir: string;
|
|
||||||
export declare let configFile: string;
|
|
8
dist/npmextra.paths.js
vendored
8
dist/npmextra.paths.js
vendored
@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
const plugins = require("./npmextra.plugins");
|
|
||||||
// directories
|
|
||||||
exports.cwd = process.cwd();
|
|
||||||
exports.packageDir = plugins.path.join(__dirname, "../");
|
|
||||||
//
|
|
||||||
exports.configFile = plugins.path.join(exports.cwd, "npmextra.json");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1leHRyYS5wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUU5QyxjQUFjO0FBQ0gsV0FBRyxHQUFHLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQztBQUNwQixrQkFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUUzRCxFQUFFO0FBQ1Msa0JBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxXQUFHLEVBQUMsZUFBZSxDQUFDLENBQUMifQ==
|
|
6
dist/npmextra.plugins.d.ts
vendored
6
dist/npmextra.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
|||||||
import "typings-global";
|
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export import lodash = require("lodash");
|
|
||||||
export import path = require("path");
|
|
||||||
export import smartfile = require("smartfile");
|
|
||||||
export import q = require("q");
|
|
8
dist/npmextra.plugins.js
vendored
8
dist/npmextra.plugins.js
vendored
@ -1,8 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-global");
|
|
||||||
exports.beautylog = require("beautylog");
|
|
||||||
exports.lodash = require("lodash");
|
|
||||||
exports.path = require("path");
|
|
||||||
exports.smartfile = require("smartfile");
|
|
||||||
exports.q = require("q");
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsY0FBTSxXQUFXLFFBQVEsQ0FBQyxDQUFDO0FBQzNCLFlBQUksV0FBVyxNQUFNLENBQUMsQ0FBQztBQUN2QixpQkFBUyxXQUFXLFdBQVcsQ0FBQyxDQUFDO0FBQ2pDLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQyJ9
|
|
42
npmextra.json
Normal file
42
npmextra.json
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"npmci": {
|
||||||
|
"globalNpmTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"npmts": {
|
||||||
|
"testConfig": {
|
||||||
|
"parallel": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "npmextra",
|
||||||
|
"description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.",
|
||||||
|
"npmPackagename": "@push.rocks/npmextra",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"npm",
|
||||||
|
"configuration management",
|
||||||
|
"tool management",
|
||||||
|
"key-value store",
|
||||||
|
"project setup",
|
||||||
|
"typescript",
|
||||||
|
"environment setup",
|
||||||
|
"dependencies management",
|
||||||
|
"npm package enhancement",
|
||||||
|
"automation",
|
||||||
|
"async operations",
|
||||||
|
"app configuration",
|
||||||
|
"smart file handling",
|
||||||
|
"workflow improvement",
|
||||||
|
"persistent storage"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
|
}
|
||||||
|
}
|
77
package.json
77
package.json
@ -1,33 +1,74 @@
|
|||||||
{
|
{
|
||||||
"name": "npmextra",
|
"name": "@push.rocks/npmextra",
|
||||||
"version": "1.0.8",
|
"version": "5.1.2",
|
||||||
"description": "do more with npm",
|
"private": false,
|
||||||
"main": "dist/index.js",
|
"description": "A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.",
|
||||||
"typings": "dist/index.d.ts",
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)"
|
"test": "(tstest test/ --web)",
|
||||||
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/npmextra.git"
|
"url": "https://code.foss.global/push.rocks/npmextra.git"
|
||||||
},
|
},
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/npmextra/issues"
|
"url": "https://gitlab.com/pushrocks/npmextra/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
"homepage": "https://code.foss.global/push.rocks/npmextra",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/q": "^0.0.27",
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
"beautylog": "^5.0.14",
|
"@push.rocks/smartfile": "^11.0.20",
|
||||||
"lodash": "^4.13.1",
|
"@push.rocks/smartjson": "^5.0.20",
|
||||||
"q": "^1.4.1",
|
"@push.rocks/smartlog": "^3.0.7",
|
||||||
"smartfile": "^4.0.10",
|
"@push.rocks/smartpath": "^5.0.18",
|
||||||
"typings-global": "^1.0.6"
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
|
"@push.rocks/smartrx": "^3.0.7",
|
||||||
|
"@push.rocks/taskbuffer": "^3.1.7",
|
||||||
|
"@tsclass/tsclass": "^4.0.59"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.26",
|
"@git.zone/tsbuild": "^2.1.80",
|
||||||
"should": "^9.0.2",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"typings-test": "^1.0.1"
|
"@git.zone/tstest": "^1.0.90",
|
||||||
}
|
"@push.rocks/tapbundle": "^5.0.23",
|
||||||
|
"@types/node": "^20.14.5"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"keywords": [
|
||||||
|
"npm",
|
||||||
|
"configuration management",
|
||||||
|
"tool management",
|
||||||
|
"key-value store",
|
||||||
|
"project setup",
|
||||||
|
"typescript",
|
||||||
|
"environment setup",
|
||||||
|
"dependencies management",
|
||||||
|
"npm package enhancement",
|
||||||
|
"automation",
|
||||||
|
"async operations",
|
||||||
|
"app configuration",
|
||||||
|
"smart file handling",
|
||||||
|
"workflow improvement",
|
||||||
|
"persistent storage"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
6757
pnpm-lock.yaml
generated
Normal file
6757
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
0
readme.hints.md
Normal file
0
readme.hints.md
Normal file
311
readme.md
Normal file
311
readme.md
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
# @push.rocks/npmextra
|
||||||
|
A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.
|
||||||
|
|
||||||
|
## Install
|
||||||
|
To install `@push.rocks/npmextra`, use the following npm command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install @push.rocks/npmextra --save
|
||||||
|
```
|
||||||
|
|
||||||
|
This package is available on [npm](https://www.npmjs.com/package/@push.rocks/npmextra) and can be installed into your project as a dependency to enhance npm with additional configuration and tool management capabilities.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
`@push.rocks/npmextra` is designed to supplement npm functionalities with enhanced configuration and tool management. It facilitates the management of project configurations and tool setups in a consolidated manner, enabling a smoother workflow and maintenance process. Below are detailed use cases and examples implemented with ESM syntax and TypeScript.
|
||||||
|
|
||||||
|
### Initial Setup and Configuration
|
||||||
|
To start using `npmextra` in your project, first include it with an import statement:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Npmextra } from '@push.rocks/npmextra';
|
||||||
|
```
|
||||||
|
|
||||||
|
Instantiate the `Npmextra` class optionally with a custom path to your project's working directory. If no path is provided, the current working directory (`process.cwd()`) is used.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const npmExtraInstance = new Npmextra('/path/to/your/project');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Managing Tool Configurations with `npmextra.json`
|
||||||
|
`@push.rocks/npmextra` excels in unifying tool configurations through a single `npmextra.json` file. Instead of scattering configurations across multiple files, `npmextra` enables you to define tool-specific settings within this centralized configuration file, which can then be accessed programmatically.
|
||||||
|
|
||||||
|
#### Creating and Utilizing `npmextra.json`
|
||||||
|
|
||||||
|
Create a `npmextra.json` in your project root with the following structure:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"toolname": {
|
||||||
|
"setting1": "value1",
|
||||||
|
"setting2": "value2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For example, to configure a hypothetical tool named `toolname`, define its settings as shown above.
|
||||||
|
|
||||||
|
#### Accessing Configuration in Your Project
|
||||||
|
|
||||||
|
With the configuration defined, you can easily access these settings in your TypeScript code as follows:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Import the npmextra module
|
||||||
|
import { Npmextra } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
// Create an instance pointing at the current directory
|
||||||
|
const npmExtraInstance = new Npmextra();
|
||||||
|
|
||||||
|
// Retrieve the configuration for 'toolname', merging defaults with any found in npmextra.json
|
||||||
|
const toolConfig = npmExtraInstance.dataFor<{ setting1: string, setting2: string }>('toolname', {
|
||||||
|
setting1: 'defaultValue1',
|
||||||
|
setting2: 'defaultValue2'
|
||||||
|
});
|
||||||
|
|
||||||
|
// toolConfig now contains the merged settings from npmextra.json and provided defaults
|
||||||
|
console.log(toolConfig);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Key-Value Store Management
|
||||||
|
`@push.rocks/npmextra` also includes a Key-Value Store (KeyValueStore) functionality enabling persistent storage of key-value pairs between script executions.
|
||||||
|
|
||||||
|
#### Setting Up KeyValueStore
|
||||||
|
|
||||||
|
To utilize the KeyValueStore, create an instance specifying its scope (e.g., 'userHomeDir') and a unique identity for your application or tool:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { KeyValueStore } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
const kvStore = new KeyValueStore<'userHomeDir'>({
|
||||||
|
typeArg: 'userHomeDir',
|
||||||
|
identityArg: 'myUniqueAppName'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
You can then use the `writeKey`, `readKey`, `writeAll`, and `readAll` methods to manage your store respectively.
|
||||||
|
|
||||||
|
#### Example: Storing and Retrieving Data
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Write a single key-value pair
|
||||||
|
await kvStore.writeKey('username', 'johnDoe');
|
||||||
|
|
||||||
|
// Read a single key
|
||||||
|
const username = await kvStore.readKey('username');
|
||||||
|
console.log(username); // Outputs: johnDoe
|
||||||
|
|
||||||
|
// Write multiple key-value pairs
|
||||||
|
await kvStore.writeAll({
|
||||||
|
email: 'john@example.com',
|
||||||
|
isAdmin: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Read all key-value pairs
|
||||||
|
const allData = await kvStore.readAll();
|
||||||
|
console.log(allData); // Outputs the entire store's contents
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Key-Value Store Management
|
||||||
|
|
||||||
|
In addition to basic read/write operations, `npmextra`’s `KeyValueStore` supports advanced scenarios like mandatory keys and custom file paths.
|
||||||
|
|
||||||
|
#### Example: Mandatory Keys and Custom Paths
|
||||||
|
|
||||||
|
Consider a scenario where your application requires specific keys to be present in the KeyValueStore. You can define mandatory keys and use a custom path for your store like this:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { KeyValueStore } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
interface CustomData {
|
||||||
|
key1: string;
|
||||||
|
key2: number;
|
||||||
|
key3?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const kvStore = new KeyValueStore<CustomData>({
|
||||||
|
typeArg: 'custom',
|
||||||
|
identityArg: 'customApp',
|
||||||
|
customPath: '/custom/path/to/store.json',
|
||||||
|
mandatoryKeys: ['key1', 'key2']
|
||||||
|
});
|
||||||
|
|
||||||
|
// Ensure all mandatory keys are present
|
||||||
|
const missingKeys = await kvStore.getMissingMandatoryKeys();
|
||||||
|
if (missingKeys.length) {
|
||||||
|
console.log(`Missing mandatory keys: ${missingKeys.join(', ')}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the KeyValueStore
|
||||||
|
await kvStore.writeKey('key1', 'value1');
|
||||||
|
await kvStore.writeKey('key2', 123);
|
||||||
|
|
||||||
|
const key1Value = await kvStore.readKey('key1');
|
||||||
|
const allData = await kvStore.readAll();
|
||||||
|
|
||||||
|
console.log(key1Value); // Outputs: value1
|
||||||
|
console.log(allData); // Outputs: { key1: 'value1', key2: 123 }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Combining AppData and KeyValueStore
|
||||||
|
|
||||||
|
The `AppData` class extends the functionality of `KeyValueStore` by integrating environmental variables, specifying additional configurations, and providing a more structured approach to data management.
|
||||||
|
|
||||||
|
#### Example: AppData Usage
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { AppData } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
interface AppSettings {
|
||||||
|
settingA: string;
|
||||||
|
settingB: number;
|
||||||
|
nestedSetting: {
|
||||||
|
innerSetting: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const appDataInstance = await AppData.createAndInit<AppSettings>({
|
||||||
|
dirPath: '/custom/path/to/appdata',
|
||||||
|
requiredKeys: ['settingA', 'settingB'],
|
||||||
|
envMapping: {
|
||||||
|
settingA: 'MY_ENV_A',
|
||||||
|
settingB: 'hard:42',
|
||||||
|
nestedSetting: {
|
||||||
|
innerSetting: 'MY_ENV_INNER'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const appDataKvStore = await appDataInstance.getKvStore();
|
||||||
|
|
||||||
|
// Writing values
|
||||||
|
await appDataKvStore.writeKey('settingA', 'exampleValue');
|
||||||
|
await appDataKvStore.writeKey('settingB', 100);
|
||||||
|
await appDataKvStore.writeKey('nestedSetting', { innerSetting: true });
|
||||||
|
|
||||||
|
// Reading values
|
||||||
|
const settingA = await appDataKvStore.readKey('settingA');
|
||||||
|
const allSettings = await appDataKvStore.readAll();
|
||||||
|
|
||||||
|
console.log(settingA); // Outputs: 'exampleValue'
|
||||||
|
console.log(allSettings); // Outputs: { settingA: 'exampleValue', settingB: 100, nestedSetting: { innerSetting: true } }
|
||||||
|
```
|
||||||
|
|
||||||
|
### Error Handling and Debugging
|
||||||
|
|
||||||
|
Proper error handling ensures your integrations with `npmextra` are robust and stable. Below are some strategies for error handling and debugging potential issues.
|
||||||
|
|
||||||
|
#### Example: Error Handling in KeyValueStore
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { KeyValueStore } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
const kvStore = new KeyValueStore('userHomeDir', 'errorHandlingApp');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await kvStore.writeKey('importantKey', 'importantValue');
|
||||||
|
const value = await kvStore.readKey('importantKey');
|
||||||
|
console.log(value); // Outputs: importantValue
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error managing key-value store:', error);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Debugging Configuration Issues in `npmextra.json`
|
||||||
|
|
||||||
|
To debug configuration issues, you can utilize conditional logging and checks:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Npmextra } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
const npmExtraInstance = new Npmextra();
|
||||||
|
const toolConfig = npmExtraInstance.dataFor('toolname', {
|
||||||
|
configKey1: 'defaultValue1',
|
||||||
|
configKey2: 'defaultValue2'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!toolConfig.configKey1) {
|
||||||
|
console.error('configKey1 is missing in npmextra.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(toolConfig);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Integration Tests
|
||||||
|
|
||||||
|
Writing tests ensures that your integration with `npmextra` works as expected. Below are examples of integration tests for both `Npmextra` and `KeyValueStore`.
|
||||||
|
|
||||||
|
#### Example: Testing `Npmextra` Class
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
import { Npmextra } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
let npmExtraInstance: Npmextra;
|
||||||
|
|
||||||
|
tap.test('should create an instance of Npmextra', async () => {
|
||||||
|
npmExtraInstance = new Npmextra();
|
||||||
|
expect(npmExtraInstance).toBeInstanceOf(Npmextra);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should load configuration from npmextra.json', async () => {
|
||||||
|
const config = npmExtraInstance.dataFor('toolname', {
|
||||||
|
defaultKey1: 'defaultValue1',
|
||||||
|
});
|
||||||
|
expect(config).toHaveProperty('defaultKey1');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Example: Testing `KeyValueStore` Class
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
import { KeyValueStore } from '@push.rocks/npmextra';
|
||||||
|
|
||||||
|
let kvStore: KeyValueStore<{ key1: string, key2: number }>;
|
||||||
|
|
||||||
|
tap.test('should create a KeyValueStore instance', async () => {
|
||||||
|
kvStore = new KeyValueStore({
|
||||||
|
typeArg: 'userHomeDir',
|
||||||
|
identityArg: 'testApp'
|
||||||
|
});
|
||||||
|
expect(kvStore).toBeInstanceOf(KeyValueStore);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should write and read back a value', async () => {
|
||||||
|
await kvStore.writeKey('key1', 'value1');
|
||||||
|
const result = await kvStore.readKey('key1');
|
||||||
|
expect(result).toEqual('value1');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should write and read back multiple values', async () => {
|
||||||
|
await kvStore.writeAll({ key1: 'updatedValue1', key2: 2 });
|
||||||
|
const result = await kvStore.readAll();
|
||||||
|
expect(result).toEqual({ key1: 'updatedValue1', key2: 2 });
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Summary
|
||||||
|
|
||||||
|
By centralizing configuration management and offering a versatile key-value store, `@push.rocks/npmextra` significantly simplifies the setup and management of tools and settings in modern JavaScript and TypeScript projects. Whether you're managing project-wide configurations or need persistent storage for key-value pairs, `npmextra` provides an efficient and streamlined solution. Leveraging these robust features will ensure your project is well-configured and maintainable.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
3
test/somekv.json
Normal file
3
test/somekv.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"myKey": "myValue"
|
||||||
|
}
|
27
test/test.appdata.ts
Normal file
27
test/test.appdata.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
import path = require('path');
|
||||||
|
|
||||||
|
// module to test
|
||||||
|
import * as npmextra from '../ts/index.js';
|
||||||
|
|
||||||
|
interface ITestOptions {
|
||||||
|
hi: string;
|
||||||
|
deep: {
|
||||||
|
deep1: string;
|
||||||
|
deep2: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let testAppdata: npmextra.AppData<ITestOptions>;
|
||||||
|
|
||||||
|
tap.test('should create a valid AppData', async () => {
|
||||||
|
testAppdata = new npmextra.AppData<ITestOptions>({
|
||||||
|
envMapping: {
|
||||||
|
deep: {
|
||||||
|
deep1: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
2
test/test.d.ts
vendored
2
test/test.d.ts
vendored
@ -1,2 +0,0 @@
|
|||||||
import "typings-test";
|
|
||||||
import "should";
|
|
25
test/test.js
25
test/test.js
@ -1,25 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
require("typings-test");
|
|
||||||
const path = require("path");
|
|
||||||
require("should");
|
|
||||||
const npmExtra = require("../dist/index");
|
|
||||||
describe("npmextra", function () {
|
|
||||||
it("should read a config file", function () {
|
|
||||||
let testData = npmExtra.dataFor({
|
|
||||||
toolName: "testTool",
|
|
||||||
defaultSettings: { someKey2: "someValue2" },
|
|
||||||
cwd: path.join(process.cwd(), "test/")
|
|
||||||
});
|
|
||||||
testData.should.have.ownProperty("someKey2");
|
|
||||||
});
|
|
||||||
it("should read a config file", function () {
|
|
||||||
let testData = npmExtra.dataFor({
|
|
||||||
toolName: "testTool",
|
|
||||||
defaultSettings: { someKey2: "someValue2" },
|
|
||||||
cwd: path.join(process.cwd(), "test/")
|
|
||||||
});
|
|
||||||
testData.should.have.ownProperty("someKey2");
|
|
||||||
testData.testValue.should.equal(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFFBQVEsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUUzQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixJQUFJLFFBQVEsR0FBRyxRQUFRLENBQUMsT0FBTyxDQUFDO1lBQzVCLFFBQVEsRUFBQyxVQUFVO1lBQ25CLGVBQWUsRUFBQyxFQUFDLFFBQVEsRUFBQyxZQUFZLEVBQUM7WUFDdkMsR0FBRyxFQUFFLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLEdBQUcsRUFBRSxFQUFDLE9BQU8sQ0FBQztTQUN4QyxDQUFDLENBQUM7UUFDSCxRQUFRLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxXQUFXLENBQUMsVUFBVSxDQUFDLENBQUM7SUFDakQsQ0FBQyxDQUFDLENBQUM7SUFDSCxFQUFFLENBQUMsMkJBQTJCLEVBQUM7UUFDM0IsSUFBSSxRQUFRLEdBQUcsUUFBUSxDQUFDLE9BQU8sQ0FBQztZQUM1QixRQUFRLEVBQUMsVUFBVTtZQUNuQixlQUFlLEVBQUMsRUFBQyxRQUFRLEVBQUMsWUFBWSxFQUFDO1lBQ3ZDLEdBQUcsRUFBRSxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxPQUFPLENBQUM7U0FDeEMsQ0FBQyxDQUFDO1FBQ0gsUUFBUSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFDO1FBQzdDLFFBQVEsQ0FBQyxTQUFTLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUN2QyxDQUFDLENBQUMsQ0FBQztBQUNQLENBQUMsQ0FBQyxDQUFDIn0=
|
|
32
test/test.kvstore.ts
Normal file
32
test/test.kvstore.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
|
import * as npmextra from '../ts/index.js';
|
||||||
|
|
||||||
|
let myKeyValueStore: npmextra.KeyValueStore<any>;
|
||||||
|
|
||||||
|
tap.test('should create a keyValueStore', async () => {
|
||||||
|
myKeyValueStore = new npmextra.KeyValueStore<any>({
|
||||||
|
typeArg: 'custom',
|
||||||
|
identityArg: 'test',
|
||||||
|
customPath: 'test/somekv.json',
|
||||||
|
});
|
||||||
|
expect(myKeyValueStore).toBeInstanceOf(npmextra.KeyValueStore);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should reset the keyValueStore', async () => {
|
||||||
|
await myKeyValueStore.reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('expect result to be empty', async () => {
|
||||||
|
let result = await myKeyValueStore.readAll();
|
||||||
|
expect(JSON.stringify(result)).toEqual('{}');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('expect to add an object to the kv Store', async () => {
|
||||||
|
await myKeyValueStore.writeAll({
|
||||||
|
myKey: 'myValue',
|
||||||
|
});
|
||||||
|
await expect(await myKeyValueStore.readKey('myKey')).toEqual('myValue');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
54
test/test.ts
54
test/test.ts
@ -1,25 +1,33 @@
|
|||||||
import "typings-test";
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import path = require("path");
|
import path = require('path');
|
||||||
import "should";
|
|
||||||
|
|
||||||
import npmExtra = require("../dist/index");
|
// module to test
|
||||||
|
import * as npmextra from '../ts/index.js';
|
||||||
|
|
||||||
describe("npmextra",function(){
|
let testNpmextra: npmextra.Npmextra;
|
||||||
it("should read a config file",function(){
|
|
||||||
let testData = npmExtra.dataFor({
|
tap.test('should create a new Npmtextra instance', async () => {
|
||||||
toolName:"testTool",
|
testNpmextra = new npmextra.Npmextra('./test/');
|
||||||
defaultSettings:{someKey2:"someValue2"},
|
expect(testNpmextra).toBeInstanceOf(npmextra.Npmextra);
|
||||||
cwd: path.join(process.cwd(),"test/")
|
});
|
||||||
});
|
|
||||||
testData.should.have.ownProperty("someKey2");
|
tap.test('should state wether a npmextra.json exists', async () => {
|
||||||
});
|
// tslint:disable-next-line:no-unused-expression
|
||||||
it("should read a config file",function(){
|
expect(testNpmextra.npmextraJsonExists).toBeTrue();
|
||||||
let testData = npmExtra.dataFor({
|
});
|
||||||
toolName:"testTool",
|
|
||||||
defaultSettings:{someKey2:"someValue2"},
|
tap.test('should pass through default value, if not overriden by config from file', async () => {
|
||||||
cwd: path.join(process.cwd(),"test/")
|
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
|
||||||
});
|
console.log(testData);
|
||||||
testData.should.have.ownProperty("someKey2");
|
expect(testData).toHaveProperty('someKey2');
|
||||||
testData.testValue.should.equal(2);
|
});
|
||||||
});
|
|
||||||
});
|
tap.test('should read a config file', async () => {
|
||||||
|
let testData = testNpmextra.dataFor<any>('testTool', {
|
||||||
|
someKey2: 'someValue2',
|
||||||
|
});
|
||||||
|
expect(testData).toHaveProperty('someKey2');
|
||||||
|
expect(testData.testValue).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/npmextra',
|
||||||
|
version: '5.1.2',
|
||||||
|
description: 'A utility to enhance npm with additional configuration, tool management capabilities, and a key-value store for project setups.'
|
||||||
|
}
|
58
ts/index.ts
58
ts/index.ts
@ -1,55 +1,3 @@
|
|||||||
import * as plugins from "./npmextra.plugins"
|
export * from './npmextra.classes.appdata.js';
|
||||||
import * as paths from "./npmextra.paths";
|
export * from './npmextra.classes.keyvaluestore.js';
|
||||||
|
export * from './npmextra.classes.npmextra.js';
|
||||||
export interface IDataFor {
|
|
||||||
toolName:string;
|
|
||||||
defaultSettings?;
|
|
||||||
cwd?:string
|
|
||||||
}
|
|
||||||
|
|
||||||
export let dataFor = (optionsArg:IDataFor) => {
|
|
||||||
|
|
||||||
// handle default settings
|
|
||||||
if(
|
|
||||||
typeof optionsArg.toolName != undefined
|
|
||||||
&& typeof optionsArg.defaultSettings != undefined
|
|
||||||
){
|
|
||||||
let newDefaultOptions = {};
|
|
||||||
newDefaultOptions[optionsArg.toolName] = optionsArg.defaultSettings;
|
|
||||||
optionsArg.defaultSettings = newDefaultOptions;
|
|
||||||
};
|
|
||||||
|
|
||||||
// set lookup path
|
|
||||||
let lookupPath:string;
|
|
||||||
if(optionsArg.cwd){
|
|
||||||
lookupPath = plugins.path.join(optionsArg.cwd,"npmextra.json");
|
|
||||||
} else {
|
|
||||||
lookupPath = paths.configFile;
|
|
||||||
};
|
|
||||||
|
|
||||||
// get allData
|
|
||||||
let allData;
|
|
||||||
if(plugins.smartfile.fs.fileExistsSync(lookupPath)){
|
|
||||||
allData = plugins.smartfile.fs.toObjectSync(lookupPath);
|
|
||||||
} else {
|
|
||||||
plugins.beautylog.warn(`${lookupPath} is missing!`);
|
|
||||||
allData = {};
|
|
||||||
};
|
|
||||||
|
|
||||||
//assign all data
|
|
||||||
allData = plugins.lodash.merge({},optionsArg.defaultSettings,allData);
|
|
||||||
if(optionsArg.toolName){
|
|
||||||
if(allData[optionsArg.toolName]){
|
|
||||||
return allData[optionsArg.toolName];
|
|
||||||
} else {
|
|
||||||
plugins.beautylog.error(`There is no data for ${optionsArg.toolName}`);
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return allData;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export let configFilePresent = ():boolean => {
|
|
||||||
return plugins.smartfile.fs.fileExistsSync(paths.configFile);
|
|
||||||
}
|
|
||||||
|
219
ts/npmextra.classes.appdata.ts
Normal file
219
ts/npmextra.classes.appdata.ts
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
import * as plugins from './npmextra.plugins.js';
|
||||||
|
import * as paths from './npmextra.paths.js';
|
||||||
|
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
|
||||||
|
|
||||||
|
export interface IAppDataOptions<T = any> {
|
||||||
|
dirPath?: string;
|
||||||
|
requiredKeys?: Array<keyof T>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wether keys should be persisted on disk or not
|
||||||
|
*/
|
||||||
|
ephermal?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kvStoreKey: 'MY_ENV_VAR'
|
||||||
|
*/
|
||||||
|
envMapping?: plugins.tsclass.typeFest.PartialDeep<T>;
|
||||||
|
overwriteObject?: plugins.tsclass.typeFest.PartialDeep<T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AppData<T = any> {
|
||||||
|
/**
|
||||||
|
* creates appdata. If no pathArg is given, data will be stored here:
|
||||||
|
* ${PWD}/.nogit/appdata
|
||||||
|
* @param pathArg
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public static async createAndInit<T = any>(
|
||||||
|
optionsArg: IAppDataOptions<T> = {}
|
||||||
|
): Promise<AppData<T>> {
|
||||||
|
const appData = new AppData<T>(optionsArg);
|
||||||
|
await appData.readyDeferred.promise;
|
||||||
|
return appData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// instance
|
||||||
|
public readyDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
public options: IAppDataOptions<T>;
|
||||||
|
private kvStore: KeyValueStore<T>;
|
||||||
|
|
||||||
|
constructor(optionsArg: IAppDataOptions<T> = {}) {
|
||||||
|
this.options = optionsArg;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inits app data
|
||||||
|
* @param pathArg
|
||||||
|
*/
|
||||||
|
private async init(pathArg?: string) {
|
||||||
|
if (this.options.dirPath || this.options.ephermal) {
|
||||||
|
// ok, nothing to do here;
|
||||||
|
} else {
|
||||||
|
const appDataDir = '/app/data';
|
||||||
|
const dataDir = '/data';
|
||||||
|
const nogitAppData = '.nogit/appdata';
|
||||||
|
const appDataExists = plugins.smartfile.fs.isDirectory(appDataDir);
|
||||||
|
const dataExists = plugins.smartfile.fs.isDirectory(dataDir);
|
||||||
|
if (appDataExists) {
|
||||||
|
this.options.dirPath = appDataDir;
|
||||||
|
} else if (dataExists) {
|
||||||
|
this.options.dirPath = dataDir;
|
||||||
|
} else {
|
||||||
|
await plugins.smartfile.fs.ensureDir(nogitAppData);
|
||||||
|
this.options.dirPath = nogitAppData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.kvStore = new KeyValueStore<T>({
|
||||||
|
typeArg: this.options.ephermal ? 'ephemeral' : 'custom',
|
||||||
|
identityArg: 'appkv',
|
||||||
|
customPath: this.options.dirPath,
|
||||||
|
mandatoryKeys: this.options.requiredKeys as Array<keyof T>,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.options.envMapping) {
|
||||||
|
const qenvInstance = new plugins.qenv.Qenv(
|
||||||
|
process.cwd(),
|
||||||
|
plugins.path.join(process.cwd(), '.nogit')
|
||||||
|
);
|
||||||
|
|
||||||
|
// Recursive function to handle nested objects, now includes key parameter
|
||||||
|
const processEnvMapping = async (
|
||||||
|
key: keyof T,
|
||||||
|
mappingValue: any,
|
||||||
|
parentKey: keyof T | '' = ''
|
||||||
|
): Promise<any> => {
|
||||||
|
if (typeof mappingValue === 'string') {
|
||||||
|
let envValue: string | boolean | T[keyof T];
|
||||||
|
let convert: 'none' | 'json' | 'base64' | 'boolean' = 'none';
|
||||||
|
switch (true) {
|
||||||
|
case mappingValue.startsWith('hard:'):
|
||||||
|
envValue = mappingValue.replace('hard:', '') as T[keyof T];
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('hard_boolean:'):
|
||||||
|
envValue = mappingValue.replace('hard_boolean:', '') === 'true';
|
||||||
|
convert = 'boolean';
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('hard_json:'):
|
||||||
|
envValue = JSON.parse(mappingValue.replace('hard_json:', '')) as T[keyof T];
|
||||||
|
convert = 'json';
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('hard_base64:'):
|
||||||
|
envValue = Buffer.from(
|
||||||
|
mappingValue.replace('hard_base64:', ''),
|
||||||
|
'base64'
|
||||||
|
).toString() as T[keyof T];
|
||||||
|
convert = 'base64';
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('boolean:'):
|
||||||
|
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||||
|
mappingValue.replace('boolean:', '')
|
||||||
|
)) as T[keyof T];
|
||||||
|
convert = 'boolean';
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('json:'):
|
||||||
|
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||||
|
mappingValue.replace('json:', '')
|
||||||
|
)) as T[keyof T];
|
||||||
|
convert = 'json';
|
||||||
|
break;
|
||||||
|
case mappingValue.startsWith('base64:'):
|
||||||
|
envValue = (await qenvInstance.getEnvVarOnDemand(
|
||||||
|
mappingValue.replace('base64:', '')
|
||||||
|
)) as T[keyof T];
|
||||||
|
convert = 'base64';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
envValue = (await qenvInstance.getEnvVarOnDemand(mappingValue)) as T[keyof T];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// lets format the env value
|
||||||
|
if (envValue) {
|
||||||
|
if (typeof envValue === 'string' && convert === 'boolean') {
|
||||||
|
envValue = envValue === 'true';
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
typeof envValue === 'string' &&
|
||||||
|
(mappingValue.endsWith('_JSON') || convert === 'json')
|
||||||
|
) {
|
||||||
|
envValue = JSON.parse(envValue as string) as T[keyof T];
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
typeof envValue === 'string' &&
|
||||||
|
(mappingValue.endsWith('_BASE64') || convert === 'base64')
|
||||||
|
) {
|
||||||
|
envValue = Buffer.from(envValue as string, 'base64').toString();
|
||||||
|
}
|
||||||
|
if (!parentKey) {
|
||||||
|
await this.kvStore.writeKey(key, envValue as any);
|
||||||
|
} else {
|
||||||
|
return envValue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} else if (typeof mappingValue === 'object' && mappingValue !== null) {
|
||||||
|
const resultObject: Partial<T> = {};
|
||||||
|
for (const innerKey in mappingValue) {
|
||||||
|
const nestedValue = mappingValue[innerKey];
|
||||||
|
// For nested objects, call recursively but do not immediately write to kvStore
|
||||||
|
const nestedResult = await processEnvMapping(innerKey as keyof T, nestedValue, key);
|
||||||
|
resultObject[innerKey as keyof T] = nestedResult;
|
||||||
|
}
|
||||||
|
if (parentKey === '') {
|
||||||
|
// Only write to kvStore if at the top level
|
||||||
|
await this.kvStore.writeKey(key, resultObject as T[keyof T]);
|
||||||
|
} else {
|
||||||
|
// For nested objects, return the constructed object instead of writing to kvStore
|
||||||
|
return resultObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const key in this.options.envMapping) {
|
||||||
|
await processEnvMapping(key as keyof T, this.options.envMapping[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.overwriteObject) {
|
||||||
|
for (const key of Object.keys(this.options.overwriteObject)) {
|
||||||
|
console.log(`-> heads up: overwriting key ${key} from options.overwriteObject`);
|
||||||
|
await this.kvStore.writeKey(key as keyof T, this.options.overwriteObject[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a kvstore that resides in appdata
|
||||||
|
*/
|
||||||
|
public async getKvStore(): Promise<KeyValueStore<T>> {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
return this.kvStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async logMissingKeys(): Promise<Array<keyof T>> {
|
||||||
|
const kvStore = await this.getKvStore();
|
||||||
|
const missingMandatoryKeys = await kvStore.getMissingMandatoryKeys();
|
||||||
|
if (missingMandatoryKeys.length > 0) {
|
||||||
|
console.log(
|
||||||
|
`The following mandatory keys are missing in the appdata:\n -> ${missingMandatoryKeys.join(
|
||||||
|
',\n -> '
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.log('All mandatory keys are present in the appdata');
|
||||||
|
}
|
||||||
|
return missingMandatoryKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async waitForAndGetKey<K extends keyof T>(keyArg: K): Promise<T[K] | undefined> {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
await this.kvStore.waitForKeysPresent([keyArg]);
|
||||||
|
return this.kvStore.readKey(keyArg);
|
||||||
|
}
|
||||||
|
}
|
205
ts/npmextra.classes.keyvaluestore.ts
Normal file
205
ts/npmextra.classes.keyvaluestore.ts
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
import * as plugins from './npmextra.plugins.js';
|
||||||
|
import * as paths from './npmextra.paths.js';
|
||||||
|
|
||||||
|
import { Task } from '@push.rocks/taskbuffer';
|
||||||
|
|
||||||
|
export type TKeyValueStore = 'custom' | 'userHomeDir' | 'ephemeral';
|
||||||
|
|
||||||
|
export interface IKvStoreConstructorOptions<T> {
|
||||||
|
typeArg: TKeyValueStore;
|
||||||
|
identityArg: string;
|
||||||
|
customPath?: string;
|
||||||
|
mandatoryKeys?: Array<keyof T>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kvStore is a simple key value store to store data about projects between runs
|
||||||
|
*/
|
||||||
|
export class KeyValueStore<T = any> {
|
||||||
|
private dataObject: Partial<T> = {};
|
||||||
|
private deletedObject: Partial<T> = {};
|
||||||
|
private mandatoryKeys: Set<keyof T> = new Set();
|
||||||
|
public changeSubject = new plugins.smartrx.rxjs.Subject<Partial<T>>();
|
||||||
|
|
||||||
|
private storedStateString: string = '';
|
||||||
|
public syncTask = new Task({
|
||||||
|
name: 'syncTask',
|
||||||
|
buffered: true,
|
||||||
|
bufferMax: 1,
|
||||||
|
execDelay: 0,
|
||||||
|
taskFunction: async () => {
|
||||||
|
if (this.type !== 'ephemeral') {
|
||||||
|
this.dataObject = {
|
||||||
|
...plugins.smartfile.fs.toObjectSync(this.filePath),
|
||||||
|
...this.dataObject,
|
||||||
|
};
|
||||||
|
for (const key of Object.keys(this.deletedObject) as Array<keyof T>) {
|
||||||
|
delete this.dataObject[key];
|
||||||
|
}
|
||||||
|
this.deletedObject = {};
|
||||||
|
await plugins.smartfile.memory.toFs(
|
||||||
|
plugins.smartjson.stringifyPretty(this.dataObject),
|
||||||
|
this.filePath
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const newStateString = plugins.smartjson.stringify(this.dataObject);
|
||||||
|
|
||||||
|
// change detection
|
||||||
|
if (newStateString !== this.storedStateString) {
|
||||||
|
this.storedStateString = newStateString;
|
||||||
|
this.changeSubject.next(this.dataObject);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* computes the identity and filePath
|
||||||
|
*/
|
||||||
|
private initFilePath = () => {
|
||||||
|
if (this.type === 'ephemeral') {
|
||||||
|
// No file path is needed for ephemeral type
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.customPath) {
|
||||||
|
// Use custom path if provided
|
||||||
|
const absolutePath = plugins.smartpath.transform.makeAbsolute(this.customPath, paths.cwd);
|
||||||
|
this.filePath = absolutePath;
|
||||||
|
if (plugins.smartfile.fs.isDirectorySync(this.filePath)) {
|
||||||
|
this.filePath = plugins.path.join(this.filePath, this.identity + '.json');
|
||||||
|
}
|
||||||
|
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let baseDir: string;
|
||||||
|
if (this.type === 'userHomeDir') {
|
||||||
|
baseDir = paths.kvUserHomeDirBase;
|
||||||
|
} else {
|
||||||
|
throw new Error('kv type not supported');
|
||||||
|
}
|
||||||
|
this.filePath = plugins.path.join(baseDir, this.identity + '.json');
|
||||||
|
plugins.smartfile.fs.ensureDirSync(baseDir);
|
||||||
|
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}');
|
||||||
|
};
|
||||||
|
|
||||||
|
// if no custom path is provided, try to store at home directory
|
||||||
|
public type: TKeyValueStore;
|
||||||
|
public identity: string;
|
||||||
|
public filePath?: string;
|
||||||
|
private customPath?: string; // Optionally allow custom path
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the constructor of keyvalue store
|
||||||
|
* @param typeArg
|
||||||
|
* @param identityArg
|
||||||
|
* @param customPath Optional custom path for the keyValue store
|
||||||
|
*/
|
||||||
|
constructor(optionsArg: IKvStoreConstructorOptions<T>) {
|
||||||
|
if (optionsArg.customPath && optionsArg.typeArg !== 'custom') {
|
||||||
|
throw new Error('customPath can only be provided if typeArg is custom');
|
||||||
|
}
|
||||||
|
if (optionsArg.typeArg === 'custom' && !optionsArg.customPath) {
|
||||||
|
throw new Error('customPath must be provided if typeArg is custom');
|
||||||
|
}
|
||||||
|
this.type = optionsArg.typeArg;
|
||||||
|
this.identity = optionsArg.identityArg;
|
||||||
|
this.customPath = optionsArg.customPath; // Store custom path if provided
|
||||||
|
this.initFilePath();
|
||||||
|
if (optionsArg.mandatoryKeys) {
|
||||||
|
this.setMandatoryKeys(optionsArg.mandatoryKeys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reads all keyValue pairs at once and returns them
|
||||||
|
*/
|
||||||
|
public async readAll(): Promise<Partial<T>> {
|
||||||
|
await this.syncTask.trigger();
|
||||||
|
return this.dataObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* reads a keyValueFile from disk
|
||||||
|
*/
|
||||||
|
public async readKey<K extends keyof T>(keyArg: K): Promise<T[K]> {
|
||||||
|
await this.syncTask.trigger();
|
||||||
|
return this.dataObject[keyArg] as T[K];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes a specific key to the keyValueStore
|
||||||
|
*/
|
||||||
|
public async writeKey<K extends keyof T>(keyArg: K, valueArg: T[K]): Promise<void> {
|
||||||
|
await this.writeAll({
|
||||||
|
[keyArg]: valueArg,
|
||||||
|
} as unknown as Partial<T>);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteKey<K extends keyof T>(keyArg: K): Promise<void> {
|
||||||
|
this.deletedObject[keyArg] = this.dataObject[keyArg];
|
||||||
|
await this.syncTask.trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes all keyValue pairs in the object argument
|
||||||
|
*/
|
||||||
|
public async writeAll(keyValueObject: Partial<T>): Promise<void> {
|
||||||
|
this.dataObject = { ...this.dataObject, ...keyValueObject };
|
||||||
|
await this.syncTask.trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wipes a key value store from disk
|
||||||
|
*/
|
||||||
|
public async wipe(): Promise<void> {
|
||||||
|
this.dataObject = {};
|
||||||
|
if (this.type !== 'ephemeral') {
|
||||||
|
await plugins.smartfile.fs.remove(this.filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets the KeyValueStore to the initial state by syncing first, deleting all keys, and then triggering a sync again
|
||||||
|
*/
|
||||||
|
public async reset(): Promise<void> {
|
||||||
|
await this.syncTask.trigger(); // Sync to get the latest state
|
||||||
|
|
||||||
|
// Delete all keys from the dataObject and add them to deletedObject
|
||||||
|
for (const key of Object.keys(this.dataObject) as Array<keyof T>) {
|
||||||
|
this.deletedObject[key] = this.dataObject[key];
|
||||||
|
delete this.dataObject[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.syncTask.trigger(); // Sync again to reflect the deletion
|
||||||
|
}
|
||||||
|
|
||||||
|
private setMandatoryKeys(keys: Array<keyof T>) {
|
||||||
|
keys.forEach(key => this.mandatoryKeys.add(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getMissingMandatoryKeys(): Promise<Array<keyof T>> {
|
||||||
|
await this.readAll();
|
||||||
|
return Array.from(this.mandatoryKeys).filter(key => !(key in this.dataObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async waitForKeysPresent<K extends keyof T>(keysArg: K[]): Promise<void> {
|
||||||
|
const missingKeys = keysArg.filter(keyArg => !this.dataObject[keyArg]);
|
||||||
|
if (missingKeys.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
const subscription = this.changeSubject.subscribe(() => {
|
||||||
|
const missingKeys = keysArg.filter(keyArg => !this.dataObject[keyArg]);
|
||||||
|
if (missingKeys.length === 0) {
|
||||||
|
subscription.unsubscribe();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async waitForAndGetKey<K extends keyof T>(keyArg: K): Promise<T[K] | undefined> {
|
||||||
|
await this.waitForKeysPresent([keyArg]);
|
||||||
|
return this.readKey(keyArg);
|
||||||
|
}
|
||||||
|
}
|
72
ts/npmextra.classes.npmextra.ts
Normal file
72
ts/npmextra.classes.npmextra.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import * as plugins from './npmextra.plugins.js';
|
||||||
|
import * as paths from './npmextra.paths.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Npmextra class allows easy configuration of tools
|
||||||
|
*/
|
||||||
|
export class Npmextra {
|
||||||
|
cwd: string;
|
||||||
|
lookupPath: string;
|
||||||
|
npmextraJsonExists: boolean;
|
||||||
|
npmextraJsonData: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates instance of Npmextra
|
||||||
|
*/
|
||||||
|
constructor(cwdArg?: string) {
|
||||||
|
if (cwdArg) {
|
||||||
|
this.cwd = cwdArg;
|
||||||
|
} else {
|
||||||
|
this.cwd = paths.cwd;
|
||||||
|
}
|
||||||
|
this.checkLookupPath();
|
||||||
|
this.checkNpmextraJsonExists();
|
||||||
|
this.checkNpmextraJsonData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merges the supplied options with the ones from npmextra.json
|
||||||
|
*/
|
||||||
|
dataFor<IToolConfig>(toolnameArg: string, defaultOptionsArg: any): IToolConfig {
|
||||||
|
let npmextraToolOptions;
|
||||||
|
if (this.npmextraJsonData[toolnameArg]) {
|
||||||
|
npmextraToolOptions = this.npmextraJsonData[toolnameArg];
|
||||||
|
} else {
|
||||||
|
npmextraToolOptions = {};
|
||||||
|
}
|
||||||
|
let mergedOptions = {
|
||||||
|
...defaultOptionsArg,
|
||||||
|
...npmextraToolOptions,
|
||||||
|
};
|
||||||
|
return mergedOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if the JSON exists
|
||||||
|
*/
|
||||||
|
private checkNpmextraJsonExists() {
|
||||||
|
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets lookupPath
|
||||||
|
*/
|
||||||
|
private checkLookupPath() {
|
||||||
|
if (this.cwd) {
|
||||||
|
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json');
|
||||||
|
} else {
|
||||||
|
this.lookupPath = paths.configFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get npmextraJsonData
|
||||||
|
*/
|
||||||
|
private checkNpmextraJsonData() {
|
||||||
|
if (this.npmextraJsonExists) {
|
||||||
|
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath);
|
||||||
|
} else {
|
||||||
|
this.npmextraJsonData = {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,22 @@
|
|||||||
import * as plugins from "./npmextra.plugins";
|
import * as plugins from './npmextra.plugins.js';
|
||||||
|
|
||||||
// directories
|
// directories
|
||||||
export let cwd = process.cwd();
|
export let cwd = process.cwd();
|
||||||
export let packageDir = plugins.path.join(__dirname,"../");
|
export let packageDir = plugins.path.join(
|
||||||
|
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||||
|
'../'
|
||||||
|
);
|
||||||
|
|
||||||
//
|
// ----------------------
|
||||||
export let configFile = plugins.path.join(cwd,"npmextra.json");
|
// keyValueStore specific
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
export let home = plugins.smartpath.get.home();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* keyValue base path
|
||||||
|
*/
|
||||||
|
export let kvUserHomeDirBase = plugins.path.join(home, '.npmextra/kv');
|
||||||
|
|
||||||
|
// files
|
||||||
|
export let configFile = plugins.path.join(cwd, 'npmextra.json');
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
import "typings-global";
|
import * as tsclass from '@tsclass/tsclass';
|
||||||
export import beautylog = require("beautylog");
|
|
||||||
export import lodash = require("lodash");
|
export {
|
||||||
export import path = require("path");
|
tsclass
|
||||||
export import smartfile = require("smartfile");
|
}
|
||||||
export import q = require("q");
|
|
||||||
|
import * as qenv from '@push.rocks/qenv';
|
||||||
|
import * as smartlog from '@push.rocks/smartlog';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
|
import * as smartjson from '@push.rocks/smartjson';
|
||||||
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||||
|
|
||||||
|
export { qenv, smartlog, path, smartfile, smartjson, smartpath, smartpromise, smartrx, taskbuffer };
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user