Compare commits

...

87 Commits

Author SHA1 Message Date
e7883f5997 5.0.0 2024-02-12 19:16:44 +01:00
39ab01b4af BREAKING CHANGE(core): update 2024-02-12 19:16:43 +01:00
bb9de1b13b 4.0.16 2024-02-12 18:40:01 +01:00
080e133e9f fix(core): update 2024-02-12 18:40:01 +01:00
a284c58a68 4.0.15 2024-02-10 04:55:51 +01:00
18bb54831d fix(core): update 2024-02-10 04:55:50 +01:00
141c7ed8a7 4.0.14 2024-02-10 04:54:01 +01:00
037481f195 fix(core): update 2024-02-10 04:54:00 +01:00
e414e392d3 4.0.13 2024-02-09 15:57:32 +01:00
4f7e382bc9 fix(core): update 2024-02-09 15:57:32 +01:00
1c0b428606 4.0.12 2024-02-09 13:47:52 +01:00
90e8625771 fix(core): update 2024-02-09 13:47:51 +01:00
abbce0d4a1 4.0.11 2024-02-09 11:52:31 +01:00
93c65acc95 fix(core): update 2024-02-09 11:52:30 +01:00
a68d59a4d2 4.0.10 2024-02-09 05:16:02 +01:00
0133dca698 fix(core): update 2024-02-09 05:16:02 +01:00
6174490e8e 4.0.9 2024-02-08 14:09:20 +01:00
d952a761b2 fix(core): update 2024-02-08 14:09:20 +01:00
05909f776e 4.0.8 2024-02-07 21:44:00 +01:00
779883fbab fix(core): update 2024-02-07 21:44:00 +01:00
349f074bb9 4.0.7 2024-02-07 18:16:41 +01:00
d209661586 fix(core): update 2024-02-07 18:16:40 +01:00
3ce6036478 4.0.6 2024-01-27 19:03:06 +01:00
54bf310403 fix(core): update 2024-01-27 19:03:06 +01:00
2ec485048b 4.0.5 2024-01-25 13:57:55 +01:00
caca370e77 fix(core): update 2024-01-25 13:57:55 +01:00
45deb1a8d2 4.0.4 2023-08-26 10:56:21 +02:00
4c9d3c7148 fix(core): update 2023-08-26 10:56:20 +02:00
320c627d4f 4.0.3 2023-08-26 09:56:21 +02:00
d834e0a220 fix(core): update 2023-08-26 09:56:20 +02:00
86427ac05d 4.0.2 2023-08-24 22:59:44 +02:00
dc59682c15 fix(core): update 2023-08-24 22:59:43 +02:00
45ebf0944c 4.0.1 2023-08-24 12:06:47 +02:00
677aa4f0ea fix(core): update 2023-08-24 12:06:46 +02:00
7f0985f24d 4.0.0 2023-08-24 12:02:25 +02:00
5f2f7e2b39 BREAKING CHANGE(core): update 2023-08-24 12:02:24 +02:00
26a6ac9651 3.0.13 2023-08-24 10:44:43 +02:00
072ee31c3f fix(core): update 2023-08-24 10:44:42 +02:00
8fa3fd8ac1 3.0.12 2023-08-24 10:39:47 +02:00
102422c9c7 fix(core): update 2023-08-24 10:39:47 +02:00
2e95824ff4 3.0.11 2023-08-03 19:28:11 +02:00
c85c0d3035 fix(core): update 2023-08-03 19:28:10 +02:00
68da8c7841 3.0.10 2023-08-03 19:22:35 +02:00
a12418ba9c fix(core): update 2023-08-03 19:22:34 +02:00
1664eee3fe switch to new org scheme 2023-07-11 00:04:21 +02:00
6112f430c9 switch to new org scheme 2023-07-10 02:41:42 +02:00
3d486c76a9 3.0.9 2021-01-27 21:10:32 +00:00
2634bb282b fix(core): update 2021-01-27 21:10:31 +00:00
fedc4c5f5b 3.0.8 2021-01-27 21:00:49 +00:00
39ef242615 fix(core): update 2021-01-27 21:00:49 +00:00
211529ffff 3.0.7 2019-09-16 13:19:42 +02:00
d4f5d19231 fix(core): update 2019-09-16 13:19:42 +02:00
80d6a5103a 3.0.6 2019-09-16 13:18:45 +02:00
c22bbe2daf fix(core): update 2019-09-16 13:18:45 +02:00
82af55fae9 3.0.5 2019-05-10 17:07:26 +02:00
90f8ee4e9d fix(core): update 2019-05-10 17:07:25 +02:00
4fe85134c4 3.0.4 2019-05-10 17:05:04 +02:00
c307b7c7b0 fix(core): update 2019-05-10 17:05:04 +02:00
e4f608f7eb 3.0.3 2019-05-10 17:03:07 +02:00
0689e33ae6 fix(core): update 2019-05-10 17:03:07 +02:00
7109b666f5 3.0.2 2019-05-10 16:55:40 +02:00
11bb21e0e0 fix(core): update 2019-05-10 16:55:39 +02:00
4fdc985461 3.0.1 2018-08-31 01:14:46 +02:00
bd4de83e83 fix(package): npm access level is now public 2018-08-31 01:14:46 +02:00
545e792751 3.0.0 2018-08-31 01:11:09 +02:00
4fa25477ad BREAKING CHANGE(scope): change to @pushrocks scope 2018-08-31 01:11:09 +02:00
95de67fe17 2.0.9 2017-08-16 18:25:48 +02:00
2ec33a118a update keyValueStore 2017-08-16 18:25:45 +02:00
bb1293c764 add KeyValueStore to docs 2017-07-20 17:38:47 +02:00
344f144c2c 2.0.8 2017-07-20 17:13:04 +02:00
07cdcb074d update dependencies and readme 2017-07-20 17:13:01 +02:00
09d9fd45cf 2.0.7 2017-07-12 17:22:27 +02:00
9883067d8b add delete functionality 2017-07-12 17:22:22 +02:00
854dac5732 kvStore now working as intended 2017-07-12 17:13:29 +02:00
73c37d8bf8 update 2017-07-12 15:30:49 +02:00
f0664d4c7d 2.0.6 2017-07-09 19:05:07 +02:00
3dff5dbbc6 update to use tapbundle 2017-07-09 19:05:03 +02:00
15e3497c55 add docs 2017-04-02 11:55:45 +02:00
4184e8f20f 2.0.5 2017-03-18 16:28:17 +01:00
5ebee20a7a update npmextra.json 2017-03-18 16:28:14 +01:00
a6aa1b06da 2.0.4 2017-03-18 16:23:50 +01:00
07610c007c update to latest standards 2017-03-18 16:23:47 +01:00
f056e062b3 2.0.3 2016-09-25 13:12:24 +02:00
00855e3d63 fix npmextra.json not present error 2016-09-25 13:12:16 +02:00
d5fea19831 2.0.2 2016-09-24 21:53:50 +02:00
4c3715f655 fix compiled filenames 2016-09-24 21:53:44 +02:00
513bb686ef update 2016-09-24 21:49:53 +02:00
35 changed files with 6419 additions and 435 deletions

View 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

View 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

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/
.nogit/
# artifacts
coverage/
pages/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,48 +0,0 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- page
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
pages:
image: hosttoday/ht-docker-node:npmpage
stage: page
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public

11
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

View File

@ -1,47 +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.
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/npmextra)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/npmextra)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/npmextra)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/npmextra/)
## Status for master
[![build status](https://gitlab.com/pushrocks/npmextra/badges/master/build.svg)](https://gitlab.com/pushrocks/npmextra/commits/master)
[![coverage report](https://gitlab.com/pushrocks/npmextra/badges/master/coverage.svg)](https://gitlab.com/pushrocks/npmextra/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/npmextra.svg)](https://david-dm.org/pushrocks/npmextra)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/npmextra/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/npmextra/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/npmextra/badges/code.svg)](https://www.bithound.io/github/pushrocks/npmextra)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
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
}
)
```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

2
dist/index.d.ts vendored
View File

@ -1,2 +0,0 @@
export * from './npmextra.classes.npmextra';
export * from './npmextra.classes.keyvaluestore';

7
dist/index.js vendored
View File

@ -1,7 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./npmextra.classes.npmextra"));
__export(require("./npmextra.classes.keyvaluestore"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaURBQTJDO0FBQzNDLHNEQUFnRCJ9

View File

@ -1,18 +0,0 @@
export declare type keyValueStoreTypes = 'path' | 'gitProject';
export declare class KeyValueStore {
constructor(optionsArg: {
type: keyValueStoreTypes;
});
/**
* reads a keyValueFile from disk
*/
kvRead(): void;
/**
* writes a key value file to disk
*/
kvWrite(): void;
/**
* wipes a key value store from disk
*/
kevWipe(): void;
}

View File

@ -1,22 +0,0 @@
"use strict";
class KeyValueStore {
constructor(optionsArg) {
}
/**
* reads a keyValueFile from disk
*/
kvRead() {
}
/**
* writes a key value file to disk
*/
kvWrite() {
}
/**
* wipes a key value store from disk
*/
kevWipe() {
}
}
exports.KeyValueStore = KeyValueStore;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFLQTtJQUNJLFlBQVksVUFFWDtJQUVELENBQUM7SUFDRDs7R0FFRDtJQUNDLE1BQU07SUFFTixDQUFDO0lBRUQ7O09BRUc7SUFDSCxPQUFPO0lBRVAsQ0FBQztJQUVEOztPQUVHO0lBQ0gsT0FBTztJQUVQLENBQUM7Q0FDSjtBQTFCRCxzQ0EwQkMifQ==

View File

@ -1,29 +0,0 @@
/**
* Npmextra class allows easy configuration of tools
*/
export declare class Npmextra {
cwd: string;
lookupPath: string;
npmextraJsonExists: boolean;
npmextraJsonData: boolean;
/**
* creates instance of Npmextra
*/
constructor(cwdArg?: string);
/**
* merges the supplied options with the ones from npmextra.json
*/
dataFor<IToolConfig>(toolnameArg: string, defaultOptionsArg: any): IToolConfig;
/**
* checks if the JSON exists
*/
private checkNpmextraJsonExists();
/**
* gets lookupPath
*/
private checkLookupPath();
/**
* get npmextraJsonData
*/
private checkNpmextraJsonData();
}

View File

@ -1,64 +0,0 @@
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
/**
* Npmextra class allows easy configuration of tools
*/
class Npmextra {
/**
* creates instance of Npmextra
*/
constructor(cwdArg) {
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(toolnameArg, defaultOptionsArg) {
let npmextraToolOptions;
if (this.npmextraJsonData[toolnameArg]) {
npmextraToolOptions = this.npmextraJsonData[toolnameArg];
}
else {
npmextraToolOptions = {};
}
let mergedOptions = plugins.lodash.merge({}, defaultOptionsArg, npmextraToolOptions);
return mergedOptions;
}
/**
* checks if the JSON exists
*/
checkNpmextraJsonExists() {
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath);
}
/**
* gets lookupPath
*/
checkLookupPath() {
if (this.cwd) {
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json');
}
else {
this.lookupPath = paths.configFile;
}
;
}
/**
* get npmextraJsonData
*/
checkNpmextraJsonData() {
if (this.npmextraJsonExists) {
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath);
}
}
}
exports.Npmextra = Npmextra;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5ucG1leHRyYS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLmNsYXNzZXMubnBtZXh0cmEudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDhDQUE2QztBQUM3QywwQ0FBeUM7QUFFekM7O0dBRUc7QUFDSDtJQU1JOztPQUVHO0lBQ0gsWUFBWSxNQUFlO1FBQ3ZCLEVBQUUsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUM7WUFDVCxJQUFJLENBQUMsR0FBRyxHQUFHLE1BQU0sQ0FBQTtRQUNyQixDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixJQUFJLENBQUMsR0FBRyxHQUFHLEtBQUssQ0FBQyxHQUFHLENBQUE7UUFDeEIsQ0FBQztRQUNELElBQUksQ0FBQyxlQUFlLEVBQUUsQ0FBQTtRQUN0QixJQUFJLENBQUMsdUJBQXVCLEVBQUUsQ0FBQTtRQUM5QixJQUFJLENBQUMscUJBQXFCLEVBQUUsQ0FBQTtJQUNoQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxPQUFPLENBQWMsV0FBbUIsRUFBRSxpQkFBc0I7UUFDNUQsSUFBSSxtQkFBbUIsQ0FBQTtRQUN2QixFQUFFLENBQUMsQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLENBQUMsV0FBVyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQ3JDLG1CQUFtQixHQUFHLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxXQUFXLENBQUMsQ0FBQTtRQUM1RCxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixtQkFBbUIsR0FBRyxFQUFFLENBQUE7UUFDNUIsQ0FBQztRQUNELElBQUksYUFBYSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsRUFBRSxpQkFBaUIsRUFBRSxtQkFBbUIsQ0FBQyxDQUFBO1FBQ3BGLE1BQU0sQ0FBQyxhQUFhLENBQUE7SUFDeEIsQ0FBQztJQUVEOztPQUVHO0lBQ0ssdUJBQXVCO1FBQzNCLElBQUksQ0FBQyxrQkFBa0IsR0FBRyxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDLFVBQVUsQ0FBQyxDQUFBO0lBQ2xGLENBQUM7SUFFRDs7T0FFRztJQUNLLGVBQWU7UUFDbkIsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUM7WUFDWCxJQUFJLENBQUMsVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUUsZUFBZSxDQUFDLENBQUE7UUFDbEUsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osSUFBSSxDQUFDLFVBQVUsR0FBRyxLQUFLLENBQUMsVUFBVSxDQUFBO1FBQ3RDLENBQUM7UUFBQSxDQUFDO0lBQ04sQ0FBQztJQUVEOztPQUVHO0lBQ0sscUJBQXFCO1FBQ3pCLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxrQkFBa0IsQ0FBQyxDQUFDLENBQUM7WUFDMUIsSUFBSSxDQUFDLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxTQUFTLENBQUMsRUFBRSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsVUFBVSxDQUFDLENBQUE7UUFDOUUsQ0FBQztJQUNMLENBQUM7Q0FFSjtBQTdERCw0QkE2REMifQ==

View File

@ -1,3 +0,0 @@
export declare let cwd: string;
export declare let packageDir: string;
export declare let configFile: string;

View File

@ -1,8 +0,0 @@
"use strict";
const plugins = require("./npmextra.plugins");
// directories
exports.cwd = process.cwd();
exports.packageDir = plugins.path.join(__dirname, '../');
// files
exports.configFile = plugins.path.join(exports.cwd, 'npmextra.json');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1leHRyYS5wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBRTdDLGNBQWM7QUFDSCxRQUFBLEdBQUcsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUE7QUFDbkIsUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFBO0FBRTFELFFBQVE7QUFDRyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxXQUFHLEVBQUMsZUFBZSxDQUFDLENBQUEifQ==

View File

@ -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');

View File

@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBOEM7QUFDOUMsbUNBQXdDO0FBQ3hDLCtCQUFvQztBQUNwQyx5Q0FBOEM7QUFDOUMseUJBQThCIn0=

22
npmextra.json Normal file
View File

@ -0,0 +1,22 @@
{
"npmci": {
"globalNpmTools": [],
"npmAccessLevel": "public"
},
"npmts": {
"testConfig": {
"parallel": false
}
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "push.rocks",
"gitrepo": "npmextra",
"description": "do more with npm",
"npmPackagename": "@push.rocks/npmextra",
"license": "MIT"
}
}
}

View File

@ -1,11 +1,14 @@
{
"name": "npmextra",
"version": "2.0.1",
"name": "@push.rocks/npmextra",
"version": "5.0.0",
"private": false,
"description": "do more with npm",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -18,16 +21,36 @@
},
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
"dependencies": {
"@types/q": "^0.x.x",
"beautylog": "^5.0.23",
"lodash": "^4.16.1",
"q": "^1.4.1",
"smartfile": "^4.0.20",
"typings-global": "^1.0.14"
"@push.rocks/qenv": "^6.0.5",
"@push.rocks/smartfile": "^11.0.4",
"@push.rocks/smartjson": "^5.0.10",
"@push.rocks/smartlog": "^3.0.2",
"@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": {
"@types/should": "^8.1.30",
"should": "^11.1.0",
"typings-test": "^1.0.3"
}
"@git.zone/tsbuild": "^2.1.66",
"@git.zone/tsrun": "^1.2.44",
"@git.zone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.11.17"
},
"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

File diff suppressed because it is too large Load Diff

70
readme.md Normal file
View 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 | [![pipeline status](https://gitlab.com/push.rocks/npmextra/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/npmextra/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/npmextra)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/npmextra)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/npmextra)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/npmextra)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/npmextra)](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 | **&copy;** [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
View File

@ -0,0 +1,3 @@
{
"myKey": "myValue"
}

1
test/test.d.ts vendored
View File

@ -1 +0,0 @@
import 'typings-test';

View File

@ -1,27 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const npmExtra = require("../dist/index");
let testNpmextra;
describe('npmextra', function () {
it('should create a new Npmtextra instance', function () {
testNpmextra = new npmExtra.Npmextra('./test/');
should(testNpmextra).be.instanceof(npmExtra.Npmextra);
});
it('should state wether a npmextra.json exists', function () {
should(testNpmextra.npmextraJsonExists).be.true();
});
it('should pass through default value, if not overriden by config from file', function () {
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
console.log(testData);
should(testData).have.ownProperty('someKey2');
});
it('should read a config file', function () {
let testData = testNpmextra.dataFor('testTool', {
someKey2: 'someValue2'
});
should(testData).have.ownProperty('someKey2');
should(testData.testValue).equal(2);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUVyQixpQ0FBZ0M7QUFFaEMsMENBQTBDO0FBRTFDLElBQUksWUFBK0IsQ0FBQTtBQUVuQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQyx3Q0FBd0MsRUFBRTtRQUN6QyxZQUFZLEdBQUcsSUFBSSxRQUFRLENBQUMsUUFBUSxDQUFDLFNBQVMsQ0FBQyxDQUFBO1FBQy9DLE1BQU0sQ0FBQyxZQUFZLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxRQUFRLENBQUMsQ0FBQTtJQUN6RCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyw0Q0FBNEMsRUFBRTtRQUM3QyxNQUFNLENBQUMsWUFBWSxDQUFDLGtCQUFrQixDQUFDLENBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxDQUFBO0lBQ3JELENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLHlFQUF5RSxFQUFDO1FBQ3pFLElBQUksUUFBUSxHQUFHLFlBQVksQ0FBQyxPQUFPLENBQUMsVUFBVSxFQUFFLEVBQUMsUUFBUSxFQUFFLFlBQVksRUFBQyxDQUFDLENBQUE7UUFDekUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxRQUFRLENBQUMsQ0FBQTtRQUNyQixNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUNqRCxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixJQUFJLFFBQVEsR0FBRyxZQUFZLENBQUMsT0FBTyxDQUMvQixVQUFVLEVBQ1Y7WUFDSSxRQUFRLEVBQUUsWUFBWTtTQUN6QixDQUNKLENBQUE7UUFDRCxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxVQUFVLENBQUMsQ0FBQTtRQUM3QyxNQUFNLENBQUMsUUFBUSxDQUFDLFNBQVMsQ0FBQyxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUMsQ0FBQTtJQUN2QyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

28
test/test.kvstore.ts Normal file
View File

@ -0,0 +1,28 @@
import { expect, tap } from '@push.rocks/tapbundle';
import * as npmextra from '../ts/index.js';
let myKeyValueStore: npmextra.KeyValueStore;
tap.test('should create a keyValueStore', async () => {
myKeyValueStore = new npmextra.KeyValueStore('custom', 'test', '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();

View File

@ -1,32 +1,33 @@
import 'typings-test'
import path = require('path')
import * as should from 'should'
import { expect, tap } from '@push.rocks/tapbundle';
import path = require('path');
import npmExtra = require('../dist/index')
// module to test
import * as npmextra from '../ts/index.js';
let testNpmextra: npmExtra.Npmextra
let testNpmextra: npmextra.Npmextra;
describe('npmextra',function(){
it('should create a new Npmtextra instance', function(){
testNpmextra = new npmExtra.Npmextra('./test/')
should(testNpmextra).be.instanceof(npmExtra.Npmextra)
})
it('should state wether a npmextra.json exists', function() {
should(testNpmextra.npmextraJsonExists).be.true()
})
it('should pass through default value, if not overriden by config from file',function(){
let testData = testNpmextra.dataFor('testTool', {someKey2: 'someValue2'})
console.log(testData)
should(testData).have.ownProperty('someKey2')
})
it('should read a config file',function(){
let testData = testNpmextra.dataFor(
'testTool',
{
someKey2: 'someValue2'
}
)
should(testData).have.ownProperty('someKey2')
should(testData.testValue).equal(2)
})
})
tap.test('should create a new Npmtextra instance', async () => {
testNpmextra = new npmextra.Npmextra('./test/');
expect(testNpmextra).toBeInstanceOf(npmextra.Npmextra);
});
tap.test('should state wether a npmextra.json exists', async () => {
// tslint:disable-next-line:no-unused-expression
expect(testNpmextra.npmextraJsonExists).toBeTrue();
});
tap.test('should pass through default value, if not overriden by config from file', async () => {
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
console.log(testData);
expect(testData).toHaveProperty('someKey2');
});
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
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/npmextra',
version: '5.0.0',
description: 'do more with npm'
}

View File

@ -1,4 +1,3 @@
import * as plugins from './npmextra.plugins'
export * from './npmextra.classes.npmextra'
export * from './npmextra.classes.keyvaluestore'
export * from './npmextra.classes.appdata.js';
export * from './npmextra.classes.keyvaluestore.js';
export * from './npmextra.classes.npmextra.js';

View File

@ -0,0 +1,112 @@
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;
};
}
export class AppData {
/**
* creates appdata. If no pathArg is given, data will be stored here:
* ${PWD}/.nogit/appdata
* @param pathArg
* @returns
*/
public static async createAndInit(optionsArg: IAppDataOptions = {}) {
const appData = new AppData(optionsArg);
await appData.readyDeferred.promise;
return appData;
}
// instance
public readyDeferred = plugins.smartpromise.defer();
public options: IAppDataOptions;
private kvStore: KeyValueStore;
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(), '~/.cloudlyrc');
for (const key in this.options.envMapping) {
let envValue = await qenvInstance.getEnvVarOnDemand(key);
if (envValue) {
if (key.endsWith('_JSON')) {
envValue = JSON.parse(envValue);
}
await this.kvStore.writeKey(key, envValue);
}
}
}
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 = 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');
}
}
public async waitForAndGetKey(keyArg: string) {
await this.readyDeferred.promise;
await this.kvStore.waitForKeysPresent([keyArg]);
return this.kvStore.readKey[keyArg];
}
}

View File

@ -1,32 +1,192 @@
import * as plugins from './npmextra.plugins'
import * as plugins from './npmextra.plugins.js';
import * as paths from './npmextra.paths.js';
export type keyValueStoreTypes = 'path' | 'gitProject'
import { Task } from '@push.rocks/taskbuffer';
export type TKeyValueStore = 'custom' | 'userHomeDir';
export class KeyValueStore {
constructor(optionsArg: {
type: keyValueStoreTypes
}) {
}
/**
* reads a keyValueFile from disk
*/
kvRead() {
}
/**
* writes a key value file to disk
*/
kvWrite() {
}
/**
* wipes a key value store from disk
*/
kevWipe() {
}
export interface IKvStoreConstructorOptions {
typeArg: TKeyValueStore;
identityArg: string;
customPath?: string;
mandatoryKeys?: string[];
}
/**
* 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: any = {};
private mandatoryKeys: Set<string> = new Set();
public changeSubject = new plugins.smartrx.rxjs.Subject();
private storedStateString: string = '';
public syncTask = new Task({
name: 'syncTask',
buffered: true,
bufferMax: 1,
execDelay: 0,
taskFunction: async () => {
this.dataObject = {
...plugins.smartfile.fs.toObjectSync(this.filePath),
...this.dataObject,
};
for (const key of Object.keys(this.deletedObject)) {
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.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) {
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() {
await this.syncTask.trigger();
return this.dataObject;
}
/**
* reads a keyValueFile from disk
*/
public async readKey(keyArg: string) {
await this.syncTask.trigger();
return this.dataObject[keyArg];
}
/**
* writes a specific key to the keyValueStore
*/
public async writeKey(keyArg: string, valueArg: any) {
await this.writeAll({
[keyArg]: valueArg,
});
}
public async deleteKey(keyArg: string) {
this.deletedObject[keyArg] = this.dataObject[keyArg];
await this.syncTask.trigger();
}
/**
* writes all keyValue pairs in the object argument
*/
public async writeAll(keyValueObject: { [key: string]: any }) {
this.dataObject = { ...this.dataObject, ...keyValueObject };
await this.syncTask.trigger();
}
/**
* wipes a key value store from disk
*/
public async wipe() {
this.dataObject = {};
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() {
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)) {
this.deletedObject[key] = this.dataObject[key];
delete this.dataObject[key];
}
await this.syncTask.trigger(); // Sync again to reflect the deletion
}
private setMandatoryKeys(keys: string[]) {
keys.forEach(key => this.mandatoryKeys.add(key));
}
public getMissingMandatoryKeys(): string[] {
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();
}
});
});
}
}

View File

@ -1,68 +1,72 @@
import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
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: boolean
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()
/**
* 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 = plugins.lodash.merge({}, defaultOptionsArg, npmextraToolOptions)
return mergedOptions
/**
* 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)
/**
* 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;
}
}
/**
* 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 = {};
}
/**
* get npmextraJsonData
*/
private checkNpmextraJsonData() {
if (this.npmextraJsonExists) {
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath)
}
}
}
}

View File

@ -1,8 +1,22 @@
import * as plugins from './npmextra.plugins'
import * as plugins from './npmextra.plugins.js';
// directories
export let cwd = process.cwd()
export let packageDir = plugins.path.join(__dirname,'../')
export let cwd = process.cwd();
export let packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../'
);
// ----------------------
// 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')
export let configFile = plugins.path.join(cwd, 'npmextra.json');

View File

@ -1,6 +1,11 @@
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')
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
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}