Compare commits
83 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
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
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -8,12 +8,13 @@ pages/
|
|||||||
# installs
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
||||||
# caches and builds
|
# caches
|
||||||
.yarn/
|
.yarn/
|
||||||
.cache/
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
125
.gitlab-ci.yml
125
.gitlab-ci.yml
@ -1,125 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SOURCE_CODE="$PWD"
|
|
||||||
--volume "$PWD":/code
|
|
||||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
|
||||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
|
||||||
artifacts:
|
|
||||||
paths: [codeclimate.json]
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typedoc typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.12.0
|
|
||||||
ignore: {}
|
|
||||||
patch: {}
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
61
README.md
61
README.md
@ -1,61 +0,0 @@
|
|||||||
# @pushrocks/npmextra
|
|
||||||
do more with npm
|
|
||||||
|
|
||||||
## Availabililty and Links
|
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/npmextra)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/npmextra)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/npmextra)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/npmextra/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
[](https://gitlab.com/pushrocks/npmextra/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/npmextra/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/@pushrocks/npmextra)
|
|
||||||
[](https://snyk.io/test/npm/@pushrocks/npmextra)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
## Using npmextra for managing toolconfigs
|
|
||||||
|
|
||||||
The main purpose of npmextra is to configure different tools using one npmextra.json. This way complex setups avoid additional complexity caused by too many configuration files.
|
|
||||||
|
|
||||||
npmextra.json
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"sometool": {
|
|
||||||
"defaultKey1": "awesomeValueFromConfig"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { Npmextra } from 'npmextra';
|
|
||||||
|
|
||||||
let myNpmExtra = new Npmextra('my/path/to/cwd'); // cwd argument is optional
|
|
||||||
mergedData = myNpmExtra.dataFor('sometool', {
|
|
||||||
// gets merged with whatever is in the configfile
|
|
||||||
defaultKey1: 'defaultValue1', // so this will get overwritten with "awesomeValueFromConfig"
|
|
||||||
defaultKey2: 'defaultValue2' // this one will pass through unaltered
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Tools that already use the config feature of npmextra
|
|
||||||
|
|
||||||
- [npmts](https://www.npmjs.com/package/npmts)
|
|
||||||
- [npmci](https://www.npmjs.com/package/npmci)
|
|
||||||
- [npmdocker](https://www.npmjs.com/package/npmdocker)
|
|
||||||
|
|
||||||
## Using the KeyValueStore
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
@ -9,13 +9,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"gitzone": {
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "npmextra",
|
"gitrepo": "npmextra",
|
||||||
"shortDescription": "do more with npm",
|
"description": "do more with npm",
|
||||||
"npmPackagename": "@pushrocks/npmextra",
|
"npmPackagename": "@push.rocks/npmextra",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tsdocs": {
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
1585
package-lock.json
generated
1585
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
56
package.json
56
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/npmextra",
|
"name": "@push.rocks/npmextra",
|
||||||
"version": "3.0.4",
|
"version": "5.0.12",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do more with npm",
|
"description": "do more with npm",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web --allowimplicitany)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -20,19 +21,36 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^7.0.2",
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
"@pushrocks/smartlog": "^2.0.19",
|
"@push.rocks/smartfile": "^11.0.4",
|
||||||
"@pushrocks/smartpath": "^4.0.1",
|
"@push.rocks/smartjson": "^5.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.0.2",
|
"@push.rocks/smartlog": "^3.0.2",
|
||||||
"@pushrocks/taskbuffer": "^2.0.7"
|
"@push.rocks/smartpath": "^5.0.11",
|
||||||
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
|
"@push.rocks/smartrx": "^3.0.7",
|
||||||
|
"@push.rocks/taskbuffer": "^3.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.11",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsrun": "^1.2.6",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"@gitzone/tstest": "^1.0.20",
|
"@git.zone/tstest": "^1.0.77",
|
||||||
"@pushrocks/tapbundle": "^3.0.9",
|
"@push.rocks/tapbundle": "^5.0.15",
|
||||||
"@types/node": "^12.0.0",
|
"@types/node": "^20.11.17"
|
||||||
"tslint": "^5.16.0",
|
},
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"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"
|
||||||
}
|
}
|
||||||
|
5571
pnpm-lock.yaml
generated
Normal file
5571
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
70
readme.md
Normal file
70
readme.md
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
# @push.rocks/npmextra
|
||||||
|
do more with npm
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/npmextra)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/push.rocks/npmextra)
|
||||||
|
* [github.com (source mirror)](https://github.com/push.rocks/npmextra)
|
||||||
|
* [docs (typedoc)](https://push.rocks.gitlab.io/npmextra/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
## Using npmextra for managing toolconfigs
|
||||||
|
|
||||||
|
The main purpose of npmextra is to configure different tools using one npmextra.json. This way complex setups avoid additional complexity caused by too many configuration files.
|
||||||
|
|
||||||
|
npmextra.json
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"sometool": {
|
||||||
|
"defaultKey1": "awesomeValueFromConfig"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { Npmextra } from 'npmextra';
|
||||||
|
|
||||||
|
let myNpmExtra = new Npmextra('my/path/to/cwd'); // cwd argument is optional
|
||||||
|
mergedData = myNpmExtra.dataFor('sometool', {
|
||||||
|
// gets merged with whatever is in the configfile
|
||||||
|
defaultKey1: 'defaultValue1', // so this will get overwritten with "awesomeValueFromConfig"
|
||||||
|
defaultKey2: 'defaultValue2', // this one will pass through unaltered
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tools that already use the config feature of npmextra
|
||||||
|
|
||||||
|
- [npmts](https://www.npmjs.com/package/npmts)
|
||||||
|
- [npmci](https://www.npmjs.com/package/npmci)
|
||||||
|
- [npmdocker](https://www.npmjs.com/package/npmdocker)
|
||||||
|
|
||||||
|
## Using the KeyValueStore
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
3
test/somekv.json
Normal file
3
test/somekv.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"myKey": "myValue"
|
||||||
|
}
|
@ -1,25 +1,28 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
import * as npmextra from '../ts/index';
|
import * as npmextra from '../ts/index.js';
|
||||||
|
|
||||||
let myKeyValueStore: npmextra.KeyValueStore;
|
let myKeyValueStore: npmextra.KeyValueStore;
|
||||||
|
|
||||||
tap.test('should create a keyValueStore', async () => {
|
tap.test('should create a keyValueStore', async () => {
|
||||||
myKeyValueStore = new npmextra.KeyValueStore('custom', 'test');
|
myKeyValueStore = new npmextra.KeyValueStore('custom', 'test', 'test/somekv.json');
|
||||||
expect(myKeyValueStore).to.be.instanceof(npmextra.KeyValueStore);
|
expect(myKeyValueStore).toBeInstanceOf(npmextra.KeyValueStore);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should reset the keyValueStore', async () => {
|
||||||
|
await myKeyValueStore.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect result to be empty', async () => {
|
tap.test('expect result to be empty', async () => {
|
||||||
let result = myKeyValueStore.readAll();
|
let result = await myKeyValueStore.readAll();
|
||||||
// tslint:disable-next-line:no-unused-expression
|
expect(JSON.stringify(result)).toEqual('{}');
|
||||||
expect(result).to.be.empty;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('expect to add an object to the kv Store', async () => {
|
tap.test('expect to add an object to the kv Store', async () => {
|
||||||
await myKeyValueStore.writeAll({
|
await myKeyValueStore.writeAll({
|
||||||
myKey: 'myValue'
|
myKey: 'myValue',
|
||||||
});
|
});
|
||||||
await expect(myKeyValueStore.readKey('myKey')).to.eventually.equal('myValue');
|
await expect(await myKeyValueStore.readKey('myKey')).toEqual('myValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
20
test/test.ts
20
test/test.ts
@ -1,33 +1,33 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import path = require('path');
|
import path = require('path');
|
||||||
|
|
||||||
// module to test
|
// module to test
|
||||||
import npmExtra = require('../ts/index');
|
import * as npmextra from '../ts/index.js';
|
||||||
|
|
||||||
let testNpmextra: npmExtra.Npmextra;
|
let testNpmextra: npmextra.Npmextra;
|
||||||
|
|
||||||
tap.test('should create a new Npmtextra instance', async () => {
|
tap.test('should create a new Npmtextra instance', async () => {
|
||||||
testNpmextra = new npmExtra.Npmextra('./test/');
|
testNpmextra = new npmextra.Npmextra('./test/');
|
||||||
expect(testNpmextra).be.instanceof(npmExtra.Npmextra);
|
expect(testNpmextra).toBeInstanceOf(npmextra.Npmextra);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should state wether a npmextra.json exists', async () => {
|
tap.test('should state wether a npmextra.json exists', async () => {
|
||||||
// tslint:disable-next-line:no-unused-expression
|
// tslint:disable-next-line:no-unused-expression
|
||||||
expect(testNpmextra.npmextraJsonExists).be.true;
|
expect(testNpmextra.npmextraJsonExists).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should pass through default value, if not overriden by config from file', async () => {
|
tap.test('should pass through default value, if not overriden by config from file', async () => {
|
||||||
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
|
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
|
||||||
console.log(testData);
|
console.log(testData);
|
||||||
expect(testData).have.ownProperty('someKey2');
|
expect(testData).toHaveProperty('someKey2');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should read a config file', async () => {
|
tap.test('should read a config file', async () => {
|
||||||
let testData = testNpmextra.dataFor<any>('testTool', {
|
let testData = testNpmextra.dataFor<any>('testTool', {
|
||||||
someKey2: 'someValue2'
|
someKey2: 'someValue2',
|
||||||
});
|
});
|
||||||
expect(testData).have.ownProperty('someKey2');
|
expect(testData).toHaveProperty('someKey2');
|
||||||
expect(testData.testValue).equal(2);
|
expect(testData.testValue).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
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 @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/npmextra',
|
||||||
|
version: '5.0.12',
|
||||||
|
description: 'do more with npm'
|
||||||
|
}
|
@ -1,4 +1,3 @@
|
|||||||
import * as plugins from './npmextra.plugins';
|
export * from './npmextra.classes.appdata.js';
|
||||||
|
export * from './npmextra.classes.keyvaluestore.js';
|
||||||
export * from './npmextra.classes.npmextra';
|
export * from './npmextra.classes.npmextra.js';
|
||||||
export * from './npmextra.classes.keyvaluestore';
|
|
||||||
|
149
ts/npmextra.classes.appdata.ts
Normal file
149
ts/npmextra.classes.appdata.ts
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
import * as plugins from './npmextra.plugins.js';
|
||||||
|
import * as paths from './npmextra.paths.js';
|
||||||
|
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
|
||||||
|
import { env } from 'process';
|
||||||
|
|
||||||
|
export interface IAppDataOptions {
|
||||||
|
dirPath?: string;
|
||||||
|
requiredKeys?: string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kvStoreKey: 'MY_ENV_VAR'
|
||||||
|
*/
|
||||||
|
envMapping?: {
|
||||||
|
[key: string]: string | object;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = {}): Promise<AppData<T>> {
|
||||||
|
const appData = new AppData<T>(optionsArg);
|
||||||
|
await appData.readyDeferred.promise;
|
||||||
|
return appData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// instance
|
||||||
|
public readyDeferred = plugins.smartpromise.defer();
|
||||||
|
public options: IAppDataOptions;
|
||||||
|
private kvStore: KeyValueStore<T>;
|
||||||
|
constructor(optionsArg: IAppDataOptions = {}) {
|
||||||
|
this.options = optionsArg;
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inits app data
|
||||||
|
* @param pathArg
|
||||||
|
*/
|
||||||
|
private async init(pathArg?: string) {
|
||||||
|
if (this.options.dirPath) {
|
||||||
|
// 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({
|
||||||
|
typeArg: 'custom',
|
||||||
|
identityArg: 'appkv',
|
||||||
|
customPath: this.options.dirPath,
|
||||||
|
mandatoryKeys: this.options.requiredKeys
|
||||||
|
});
|
||||||
|
|
||||||
|
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: string, mappingValue: any, parentKey: string = ''): Promise<any> => {
|
||||||
|
if (typeof mappingValue === 'string') {
|
||||||
|
let envValue: string;
|
||||||
|
if (mappingValue.startsWith('hard:')) {
|
||||||
|
envValue = mappingValue.replace('hard:', '');
|
||||||
|
} else {
|
||||||
|
envValue = await qenvInstance.getEnvVarOnDemand(mappingValue);
|
||||||
|
}
|
||||||
|
if (envValue) {
|
||||||
|
if (mappingValue.endsWith('_JSON')) {
|
||||||
|
envValue = JSON.parse(envValue);
|
||||||
|
}
|
||||||
|
if (!parentKey) {
|
||||||
|
await this.kvStore.writeKey(key, envValue);
|
||||||
|
} else {
|
||||||
|
return envValue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} else if (typeof mappingValue === 'object' && mappingValue !== null) {
|
||||||
|
const resultObject = {};
|
||||||
|
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, nestedValue, key);
|
||||||
|
resultObject[innerKey] = nestedResult;
|
||||||
|
}
|
||||||
|
if (parentKey === '') {
|
||||||
|
// Only write to kvStore if at the top level
|
||||||
|
await this.kvStore.writeKey(key, resultObject);
|
||||||
|
} 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, this.options.envMapping[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
this.readyDeferred.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a kvtore that resides in appdata
|
||||||
|
*/
|
||||||
|
public async getKvStore() {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
return this.kvStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async logMissingKeys() {
|
||||||
|
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(keyArg: string) {
|
||||||
|
await this.readyDeferred.promise;
|
||||||
|
await this.kvStore.waitForKeysPresent([keyArg]);
|
||||||
|
return this.kvStore.readKey[keyArg];
|
||||||
|
}
|
||||||
|
}
|
@ -1,60 +1,115 @@
|
|||||||
import * as plugins from './npmextra.plugins';
|
import * as plugins from './npmextra.plugins.js';
|
||||||
import * as paths from './npmextra.paths';
|
import * as paths from './npmextra.paths.js';
|
||||||
|
|
||||||
import { Task, TaskOnce } from '@pushrocks/taskbuffer';
|
import { Task } from '@push.rocks/taskbuffer';
|
||||||
|
|
||||||
export type TKeyValueStore = 'path' | 'gitProject' | 'custom';
|
export type TKeyValueStore = 'custom' | 'userHomeDir';
|
||||||
|
|
||||||
|
export interface IKvStoreConstructorOptions {
|
||||||
|
typeArg: TKeyValueStore;
|
||||||
|
identityArg: string;
|
||||||
|
customPath?: string;
|
||||||
|
mandatoryKeys?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kvStore is a simple key vlaue store to store data about projects between runs
|
* kvStore is a simple key value store to store data about projects between runs
|
||||||
*/
|
*/
|
||||||
export class KeyValueStore {
|
export class KeyValueStore<T = any> {
|
||||||
public dataObject: any;
|
private dataObject: Partial<T> = {};
|
||||||
public deletedObject: any = {};
|
private deletedObject: any = {};
|
||||||
public initialReadTask = new TaskOnce({
|
private mandatoryKeys: Set<string> = new Set();
|
||||||
taskFunction: async () => {
|
public changeSubject = new plugins.smartrx.rxjs.Subject();
|
||||||
this.dataObject = plugins.smartfile.fs.toObjectSync(this.filePath);
|
|
||||||
}
|
private storedStateString: string = '';
|
||||||
});
|
|
||||||
public syncTask = new Task({
|
public syncTask = new Task({
|
||||||
|
name: 'syncTask',
|
||||||
buffered: true,
|
buffered: true,
|
||||||
bufferMax: 2,
|
bufferMax: 1,
|
||||||
execDelay: 500,
|
execDelay: 0,
|
||||||
taskFunction: async () => {
|
taskFunction: async () => {
|
||||||
|
|
||||||
this.dataObject = {
|
this.dataObject = {
|
||||||
...plugins.smartfile.fs.toObjectSync(this.filePath),
|
...plugins.smartfile.fs.toObjectSync(this.filePath),
|
||||||
...this.dataObject
|
...this.dataObject,
|
||||||
};
|
};
|
||||||
for (const key of Object.keys(this.deletedObject)) {
|
for (const key of Object.keys(this.deletedObject)) {
|
||||||
delete this.dataObject[key];
|
delete this.dataObject[key];
|
||||||
}
|
}
|
||||||
this.deletedObject = {};
|
this.deletedObject = {};
|
||||||
await plugins.smartfile.memory.toFs(JSON.stringify(this.dataObject), this.filePath);
|
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);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
name: 'syncTask'
|
|
||||||
});
|
});
|
||||||
public type: TKeyValueStore; // the type of the kvStore
|
|
||||||
public identity: string; // the identity of the kvStore
|
/**
|
||||||
public filePath: string; // the filePath of the kvStore
|
* computes the identity and filePath
|
||||||
|
*/
|
||||||
|
private initFilePath = () => {
|
||||||
|
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
|
* the constructor of keyvalue store
|
||||||
* @param typeArg
|
* @param typeArg
|
||||||
* @param customStringArg
|
* @param identityArg
|
||||||
|
* @param customPath Optional custom path for the keyValue store
|
||||||
*/
|
*/
|
||||||
constructor(typeArg: TKeyValueStore, customStringArg: string) {
|
constructor(optionsArg: IKvStoreConstructorOptions) {
|
||||||
// set kvStoreType
|
if (optionsArg.customPath && optionsArg.typeArg !== 'custom') {
|
||||||
this.type = typeArg;
|
throw new Error('customPath can only be provided if typeArg is custom');
|
||||||
this.identity = customStringArg;
|
}
|
||||||
|
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();
|
this.initFilePath();
|
||||||
|
if (optionsArg.mandatoryKeys) {
|
||||||
|
this.setMandatoryKeys(optionsArg.mandatoryKeys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads all keyValue pairs at once and returns them
|
* reads all keyValue pairs at once and returns them
|
||||||
*/
|
*/
|
||||||
public async readAll() {
|
public async readAll() {
|
||||||
await this.initialReadTask.trigger();
|
await this.syncTask.trigger();
|
||||||
this.syncTask.trigger();
|
|
||||||
return this.dataObject;
|
return this.dataObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,58 +117,77 @@ export class KeyValueStore {
|
|||||||
* reads a keyValueFile from disk
|
* reads a keyValueFile from disk
|
||||||
*/
|
*/
|
||||||
public async readKey(keyArg: string) {
|
public async readKey(keyArg: string) {
|
||||||
let data = await this.readAll();
|
await this.syncTask.trigger();
|
||||||
return data[keyArg];
|
return this.dataObject[keyArg];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* writes a specific key to the keyValueStore
|
* writes a specific key to the keyValueStore
|
||||||
*/
|
*/
|
||||||
async writeKey(keyArg: string, valueArg: any) {
|
public async writeKey(keyArg: string, valueArg: any) {
|
||||||
let writeObject: any = {};
|
await this.writeAll({
|
||||||
writeObject[keyArg] = valueArg;
|
[keyArg]: valueArg,
|
||||||
this.writeAll(writeObject);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteKey(keyArg: string) {
|
||||||
|
this.deletedObject[keyArg] = this.dataObject[keyArg];
|
||||||
|
await this.syncTask.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* writes all keyValue pairs in the object argument
|
* writes all keyValue pairs in the object argument
|
||||||
*/
|
*/
|
||||||
public async writeAll(keyValueObject) {
|
public async writeAll(keyValueObject: { [key: string]: any }) {
|
||||||
this.dataObject = {...this.dataObject, ...keyValueObject};
|
this.dataObject = { ...this.dataObject, ...keyValueObject };
|
||||||
this.syncTask.trigger();
|
await this.syncTask.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wipes a key value store from disk
|
* wipes a key value store from disk
|
||||||
*/
|
*/
|
||||||
public async wipe() {
|
public async wipe() {
|
||||||
for (let key in this.dataObject) {
|
this.dataObject = {};
|
||||||
this.deletedObject[key] = this.dataObject[key];
|
await plugins.smartfile.fs.remove(this.filePath);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updates a value
|
* resets the KeyValueStore to the initial state by syncing first, deleting all keys, and then triggering a sync again
|
||||||
*/
|
*/
|
||||||
public async update(keyObject) {};
|
public async reset() {
|
||||||
|
await this.syncTask.trigger(); // Sync to get the latest state
|
||||||
|
|
||||||
/**
|
// Delete all keys from the dataObject and add them to deletedObject
|
||||||
* computes the identity
|
for (const key of Object.keys(this.dataObject)) {
|
||||||
*/
|
this.deletedObject[key] = this.dataObject[key];
|
||||||
private initFilePath() {
|
delete this.dataObject[key];
|
||||||
// determine the right base directory
|
|
||||||
let baseDir: string;
|
|
||||||
if (this.type === 'custom') {
|
|
||||||
baseDir = paths.kvCustomDir;
|
|
||||||
} else if (this.type === 'gitProject') {
|
|
||||||
baseDir = paths.kvGitDir;
|
|
||||||
} else if (this.type === 'path') {
|
|
||||||
baseDir = paths.kvPathDir;
|
|
||||||
}
|
}
|
||||||
this.filePath = plugins.path.join(baseDir, this.identity + '.json');
|
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.kvCustomDir);
|
await this.syncTask.trigger(); // Sync again to reflect the deletion
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.kvGitDir);
|
}
|
||||||
plugins.smartfile.fs.ensureDirSync(paths.kvPathDir);
|
|
||||||
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}');
|
private setMandatoryKeys(keys: string[]) {
|
||||||
|
keys.forEach(key => this.mandatoryKeys.add(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getMissingMandatoryKeys(): Promise<string[]> {
|
||||||
|
await this.readAll();
|
||||||
|
return Array.from(this.mandatoryKeys).filter(key => !(key in this.dataObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async waitForKeysPresent(keysArg: string[]): Promise<void> {
|
||||||
|
const missingKeys = keysArg.filter(keyArg => !this.dataObject[keyArg]);
|
||||||
|
if (missingKeys.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const subscription = this.changeSubject.subscribe(() => {
|
||||||
|
const missingKeys = keysArg.filter(keyArg => !this.dataObject[keyArg]);
|
||||||
|
if (missingKeys.length === 0) {
|
||||||
|
subscription.unsubscribe();
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as plugins from './npmextra.plugins';
|
import * as plugins from './npmextra.plugins.js';
|
||||||
import * as paths from './npmextra.paths';
|
import * as paths from './npmextra.paths.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Npmextra class allows easy configuration of tools
|
* Npmextra class allows easy configuration of tools
|
||||||
@ -36,7 +36,7 @@ export class Npmextra {
|
|||||||
}
|
}
|
||||||
let mergedOptions = {
|
let mergedOptions = {
|
||||||
...defaultOptionsArg,
|
...defaultOptionsArg,
|
||||||
...npmextraToolOptions
|
...npmextraToolOptions,
|
||||||
};
|
};
|
||||||
return mergedOptions;
|
return mergedOptions;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
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),
|
||||||
|
'../'
|
||||||
|
);
|
||||||
|
|
||||||
// ----------------------
|
// ----------------------
|
||||||
// keyValueStore specific
|
// keyValueStore specific
|
||||||
@ -13,22 +16,7 @@ export let home = plugins.smartpath.get.home();
|
|||||||
/**
|
/**
|
||||||
* keyValue base path
|
* keyValue base path
|
||||||
*/
|
*/
|
||||||
export let kvBase = plugins.path.join(home, '.npmextra/kv');
|
export let kvUserHomeDirBase = plugins.path.join(home, '.npmextra/kv');
|
||||||
|
|
||||||
/**
|
|
||||||
* the base directory for custom string based key value store
|
|
||||||
*/
|
|
||||||
export let kvCustomDir = plugins.path.join(kvBase, 'custom');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the subdir for git based keyValue
|
|
||||||
*/
|
|
||||||
export let kvGitDir = plugins.path.join(kvBase, 'git');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* keyValue for path based keyValue store
|
|
||||||
*/
|
|
||||||
export let kvPathDir = plugins.path.join(kvBase, 'path');
|
|
||||||
|
|
||||||
// files
|
// files
|
||||||
export let configFile = plugins.path.join(cwd, 'npmextra.json');
|
export let configFile = plugins.path.join(cwd, 'npmextra.json');
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import * as beautylog from '@pushrocks/smartlog';
|
import * as qenv from '@push.rocks/qenv';
|
||||||
|
import * as smartlog from '@push.rocks/smartlog';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartfile from '@pushrocks/smartfile';
|
import * as smartfile from '@push.rocks/smartfile';
|
||||||
import * as smartpath from '@pushrocks/smartpath';
|
import * as smartjson from '@push.rocks/smartjson';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import * as smartpath from '@push.rocks/smartpath';
|
||||||
import * as taskbuffer from '@pushrocks/taskbuffer';
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||||
|
|
||||||
export { beautylog, path, smartfile, smartpath, smartpromise, 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"
|
||||||
|
]
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user