Compare commits

..

30 Commits

Author SHA1 Message Date
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
25 changed files with 6253 additions and 1928 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 @gitzone/tsdoc
npmci command tsdoc
continue-on-error: true

9
.gitignore vendored
View File

@ -8,12 +8,13 @@ pages/
# installs
node_modules/
# caches and builds
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -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
View File

@ -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
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,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
[![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)
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/npmextra.svg)](https://www.npmjs.com/package/@pushrocks/npmextra)
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/npmextra/badge.svg)](https://snyk.io/test/npm/@pushrocks/npmextra)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](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)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)

View File

@ -9,12 +9,13 @@
}
},
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitscope": "push.rocks",
"gitrepo": "npmextra",
"shortDescription": "do more with npm",
"npmPackagename": "@pushrocks/npmextra",
"description": "do more with npm",
"npmPackagename": "@push.rocks/npmextra",
"license": "MIT"
}
}

1585
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,14 @@
{
"name": "@pushrocks/npmextra",
"version": "3.0.3",
"name": "@push.rocks/npmextra",
"version": "4.0.3",
"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": "(tstest test/)",
"build": "(tsbuild)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -20,19 +21,34 @@
},
"homepage": "https://gitlab.com/pushrocks/npmextra#README",
"dependencies": {
"@pushrocks/smartfile": "^7.0.2",
"@pushrocks/smartlog": "^2.0.19",
"@pushrocks/smartpath": "^4.0.1",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/taskbuffer": "^2.0.7"
"@push.rocks/smartfile": "^10.0.30",
"@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/taskbuffer": "^3.1.6"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.2.6",
"@gitzone/tstest": "^1.0.20",
"@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^12.0.0",
"tslint": "^5.16.0",
"tslint-config-prettier": "^1.18.0"
}
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.44",
"@gitzone/tstest": "^1.0.77",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.5.4"
},
"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"
}

5713
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 | **©** [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"
}

View File

@ -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;
tap.test('should create a keyValueStore', async () => {
myKeyValueStore = new npmextra.KeyValueStore('custom', 'test');
expect(myKeyValueStore).to.be.instanceof(npmextra.KeyValueStore);
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 = myKeyValueStore.readAll();
// tslint:disable-next-line:no-unused-expression
expect(result).to.be.empty;
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'
myKey: 'myValue',
});
await expect(myKeyValueStore.readKey('myKey')).to.eventually.equal('myValue');
await expect(await myKeyValueStore.readKey('myKey')).toEqual('myValue');
});
tap.start();

View File

@ -1,33 +1,33 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { expect, tap } from '@push.rocks/tapbundle';
import path = require('path');
// 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 () => {
testNpmextra = new npmExtra.Npmextra('./test/');
expect(testNpmextra).be.instanceof(npmExtra.Npmextra);
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).be.true;
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).have.ownProperty('someKey2');
expect(testData).toHaveProperty('someKey2');
});
tap.test('should read a config file', async () => {
let testData = testNpmextra.dataFor<any>('testTool', {
someKey2: 'someValue2'
someKey2: 'someValue2',
});
expect(testData).have.ownProperty('someKey2');
expect(testData.testValue).equal(2);
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: '4.0.3',
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,49 @@
import * as plugins from './npmextra.plugins.js';
import * as paths from './npmextra.paths.js';
import { KeyValueStore } from './npmextra.classes.keyvaluestore.js';
export class AppData {
public static async createAndInit(pathArg: string) {
const appData = new AppData(pathArg);
await appData.init();
return appData;
}
// instance
public readyDeferred = plugins.smartpromise.defer();
public dirPathArg: string;
private kvStore: KeyValueStore;
constructor(pathArg?: string) {
this.init(pathArg);
}
private async init(pathArg?: string) {
if (pathArg) {
this.dirPathArg = pathArg;
} 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.dirPathArg = appDataDir;
} else if (dataExists) {
this.dirPathArg = dataDir;
} else {
await plugins.smartfile.fs.ensureDir(nogitAppData);
this.dirPathArg = nogitAppData;
}
}
this.kvStore = new KeyValueStore('custom', 'appkv', this.dirPathArg);
this.readyDeferred.resolve();
}
/**
* returns a kvtore that resides in appdata
*/
public async getKvStore() {
await this.readyDeferred.promise;
return this.kvStore;
}
}

View File

@ -1,119 +1,146 @@
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';
import { Task, TaskOnce } from '@pushrocks/taskbuffer';
import { Task } from '@push.rocks/taskbuffer';
export type TKeyValueStore = 'path' | 'gitProject' | 'custom';
export type TKeyValueStore = 'custom' | 'userHomeDir';
/**
* 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 {
dataObject: any;
deletedObject: any = {};
initialReadTask = new TaskOnce({
taskFunction: async () => {
this.dataObject = plugins.smartfile.fs.toObjectSync(this.filePath);
}
});
syncTask = new Task({
private dataObject: any = {};
private deletedObject: any = {};
public syncTask = new Task({
name: 'syncTask',
buffered: true,
bufferMax: 2,
execDelay: 500,
bufferMax: 1,
execDelay: 0,
taskFunction: async () => {
this.dataObject = {
...plugins.smartfile.fs.toObjectSync(this.filePath),
...this.dataObject
...this.dataObject,
};
for (const key of Object.keys(this.deletedObject)) {
delete this.dataObject[key];
}
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
);
},
name: 'syncTask'
});
type: TKeyValueStore; // the type of the kvStore
identity: string; // the identity of the kvStore
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
* @param typeArg
* @param customStringArg
* @param identityArg
* @param customPath Optional custom path for the keyValue store
*/
constructor(typeArg: TKeyValueStore, customStringArg: string) {
// set kvStoreType
constructor(typeArg: TKeyValueStore, identityArg: string, customPath?: string) {
if (customPath && typeArg !== 'custom') {
throw new Error('customPath can only be provided if typeArg is custom');
}
if (typeArg === 'custom' && !customPath) {
throw new Error('customPath must be provided if typeArg is custom');
}
this.type = typeArg;
this.identity = customStringArg;
this.identity = identityArg;
this.customPath = customPath; // Store custom path if provided
this.initFilePath();
}
/**
* reads all keyValue pairs at once and returns them
*/
async readAll() {
await this.initialReadTask.trigger();
this.syncTask.trigger();
public async readAll() {
await this.syncTask.trigger();
return this.dataObject;
}
/**
* reads a keyValueFile from disk
*/
async readKey(keyArg: string) {
let data = await this.readAll();
return data[keyArg];
public async readKey(keyArg: string) {
await this.syncTask.trigger();
return this.dataObject[keyArg];
}
/**
* writes a specific key to the keyValueStore
*/
async writeKey(keyArg: string, valueArg: any) {
let writeObject: any = {};
writeObject[keyArg] = valueArg;
this.writeAll(writeObject);
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) {
this.dataObject = {...this.dataObject, ...keyValueObject};
this.syncTask.trigger();
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() {
for (let key in this.dataObject) {
this.deletedObject[key] = this.dataObject[key];
}
this.dataObject = {};
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
*/
async update(keyObject) {}
public async reset() {
await this.syncTask.trigger(); // Sync to get the latest state
/**
* computes the identity
*/
private initFilePath() {
// 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;
// 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];
}
this.filePath = plugins.path.join(baseDir, this.identity + '.json');
plugins.smartfile.fs.ensureDirSync(paths.kvCustomDir);
plugins.smartfile.fs.ensureDirSync(paths.kvGitDir);
plugins.smartfile.fs.ensureDirSync(paths.kvPathDir);
plugins.smartfile.fs.ensureFileSync(this.filePath, '{}');
await this.syncTask.trigger(); // Sync again to reflect the deletion
}
}

View File

@ -1,5 +1,5 @@
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
@ -36,7 +36,7 @@ export class Npmextra {
}
let mergedOptions = {
...defaultOptionsArg,
...npmextraToolOptions
...npmextraToolOptions,
};
return mergedOptions;
}

View File

@ -1,8 +1,11 @@
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 packageDir = plugins.path.join(
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
'../'
);
// ----------------------
// keyValueStore specific
@ -13,22 +16,7 @@ export let home = plugins.smartpath.get.home();
/**
* keyValue base path
*/
export let kvBase = 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');
export let kvUserHomeDirBase = plugins.path.join(home, '.npmextra/kv');
// files
export let configFile = plugins.path.join(cwd, 'npmextra.json');

View File

@ -1,8 +1,9 @@
import * as beautylog from '@pushrocks/smartlog';
import * as smartlog from '@push.rocks/smartlog';
import * as path from 'path';
import * as smartfile from '@pushrocks/smartfile';
import * as smartpath from '@pushrocks/smartpath';
import * as smartpromise from '@pushrocks/smartpromise';
import * as taskbuffer from '@pushrocks/taskbuffer';
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 taskbuffer from '@push.rocks/taskbuffer';
export { beautylog, path, smartfile, smartpath, smartpromise, taskbuffer };
export { smartlog, path, smartfile, smartjson, smartpath, smartpromise, taskbuffer };

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}

View File

@ -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"
}