Compare commits

...

28 Commits

Author SHA1 Message Date
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
27 changed files with 2056 additions and 468 deletions

19
.gitignore vendored
View File

@ -1,4 +1,19 @@
node_modules/
.nogit/
# artifacts
coverage/
pages/
public/
pages/
# installs
node_modules/
# caches and builds
.yarn/
.cache/
dist/
dist_web/
dist_serve/
dist_ts_web/
# custom

View File

@ -1,48 +1,125 @@
image: hosttoday/ht-docker-node:npmts
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- page
- metadata
testLEGACY:
stage: test
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci test legacy
- npmci git mirror
tags:
- docker
- 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 test lts
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci test stable
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- docker
- notpriv
release:
stage: release
script:
- npmci publish
- npmci node install stable
- npmci npm publish
only:
- tags
- tags
tags:
- docker
- 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:npmpage
stage: page
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npmpage --host gitlab
- 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
- public
allow_failure: true

4
.snyk Normal file
View File

@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.12.0
ignore: {}
patch: {}

View File

@ -1,47 +1,61 @@
# npmextra
do more with npm.
# @pushrocks/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/)
## 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)
[![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/)
[![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"
}
"sometool": {
"defaultKey1": "awesomeValueFromConfig"
}
}
```
```typescript
import { Npmextra } from 'npmextra'
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
}
)
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)
### 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)

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,31 +0,0 @@
export declare type keyValueStoreTypes = 'path' | 'gitProject' | 'customString';
export declare class KeyValueStore {
type: string;
identity: string;
filePath: string;
constructor(typeArg: keyValueStoreTypes, identityStringArg?: string);
/**
* reads a keyValueFile from disk
*/
read(): void;
/**
* writes a key value file to disk
*/
write(): void;
/**
* wipes a key value store from disk
*/
wipe(): void;
/**
* updates a value
*/
update(): void;
/**
* computes the identity
*/
private initIdentity(identityStringArg);
/**
* computes the filePath
*/
private initFilePath();
}

View File

@ -1,55 +0,0 @@
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
class KeyValueStore {
constructor(typeArg, identityStringArg) {
// set kvStoreType
this.type = typeArg;
this.initIdentity(identityStringArg);
this.initFilePath();
}
/**
* reads a keyValueFile from disk
*/
read() {
}
/**
* writes a key value file to disk
*/
write() {
}
/**
* wipes a key value store from disk
*/
wipe() {
}
/**
* updates a value
*/
update() {
}
/**
* computes the identity
*/
initIdentity(identityStringArg) {
}
/**
* computes the filePath
*/
initFilePath() {
let baseDir;
if (this.type === 'customString') {
baseDir = paths.kvCusomDir;
}
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.ensureFileSync(this.filePath, '{}');
}
}
exports.KeyValueStore = KeyValueStore;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvbnBtZXh0cmEuY2xhc3Nlcy5rZXl2YWx1ZXN0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSw4Q0FBNkM7QUFDN0MsMENBQXlDO0FBS3pDO0lBSUksWUFBWSxPQUEyQixFQUFFLGlCQUEwQjtRQUMvRCxrQkFBa0I7UUFDbEIsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUE7UUFDbkIsSUFBSSxDQUFDLFlBQVksQ0FBQyxpQkFBaUIsQ0FBQyxDQUFBO1FBQ3BDLElBQUksQ0FBQyxZQUFZLEVBQUUsQ0FBQTtJQUN2QixDQUFDO0lBRUQ7O09BRUc7SUFDSCxJQUFJO0lBRUosQ0FBQztJQUVEOztPQUVHO0lBQ0gsS0FBSztJQUVMLENBQUM7SUFFRDs7T0FFRztJQUNILElBQUk7SUFFSixDQUFDO0lBRUQ7O09BRUc7SUFDSCxNQUFNO0lBRU4sQ0FBQztJQUVEOztPQUVHO0lBQ0ssWUFBWSxDQUFDLGlCQUF5QjtJQUU5QyxDQUFDO0lBRUQ7O09BRUc7SUFDSyxZQUFZO1FBQ2hCLElBQUksT0FBZSxDQUFBO1FBQ25CLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxJQUFJLEtBQUssY0FBYyxDQUFDLENBQUMsQ0FBQztZQUMvQixPQUFPLEdBQUcsS0FBSyxDQUFDLFVBQVUsQ0FBQTtRQUM5QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxJQUFJLEtBQUssWUFBWSxDQUFDLENBQUMsQ0FBQztZQUNwQyxPQUFPLEdBQUcsS0FBSyxDQUFDLFFBQVEsQ0FBQTtRQUM1QixDQUFDO1FBQUMsSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxJQUFJLEtBQUssTUFBTSxDQUFDLENBQUMsQ0FBQztZQUM5QixPQUFPLEdBQUcsS0FBSyxDQUFDLFNBQVMsQ0FBQTtRQUM3QixDQUFDO1FBQ0QsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxPQUFPLEVBQUUsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsQ0FBQTtRQUNuRSxPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxjQUFjLENBQUMsSUFBSSxDQUFDLFFBQVEsRUFBQyxJQUFJLENBQUMsQ0FBQTtJQUMzRCxDQUFDO0NBQ0o7QUE3REQsc0NBNkRDIn0=

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,7 +0,0 @@
export declare let cwd: string;
export declare let packageDir: string;
export declare let kvBase: string;
export declare let kvCusomDir: string;
export declare let kvGitDir: string;
export declare let kvPathDir: string;
export declare let configFile: string;

View File

@ -1,13 +0,0 @@
"use strict";
const plugins = require("./npmextra.plugins");
// directories
exports.cwd = process.cwd();
exports.packageDir = plugins.path.join(__dirname, '../');
// keyValueStore specific
exports.kvBase = '~/.npmextra/kv';
exports.kvCusomDir = plugins.path.join(exports.kvBase, 'custom');
exports.kvGitDir = plugins.path.join(exports.kvBase, 'git');
exports.kvPathDir = plugins.path.join(exports.kvBase, 'path');
// files
exports.configFile = plugins.path.join(exports.cwd, 'npmextra.json');
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1leHRyYS5wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBRTdDLGNBQWM7QUFDSCxRQUFBLEdBQUcsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUE7QUFDbkIsUUFBQSxVQUFVLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsU0FBUyxFQUFDLEtBQUssQ0FBQyxDQUFBO0FBRTFELHlCQUF5QjtBQUNkLFFBQUEsTUFBTSxHQUFHLGdCQUFnQixDQUFBO0FBQ3pCLFFBQUEsVUFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLGNBQU0sRUFBRSxRQUFRLENBQUMsQ0FBQTtBQUNoRCxRQUFBLFFBQVEsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxjQUFNLEVBQUUsS0FBSyxDQUFDLENBQUE7QUFDM0MsUUFBQSxTQUFTLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsY0FBTSxFQUFFLE1BQU0sQ0FBQyxDQUFBO0FBRXhELFFBQVE7QUFDRyxRQUFBLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxXQUFHLEVBQUMsZUFBZSxDQUFDLENBQUEifQ==

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=

21
npmextra.json Normal file
View File

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

1585
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,13 @@
{
"name": "npmextra",
"version": "2.0.2",
"name": "@pushrocks/npmextra",
"version": "3.0.4",
"private": false,
"description": "do more with npm",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},
"repository": {
"type": "git",
@ -18,16 +20,19 @@
},
"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.21",
"typings-global": "^1.0.14"
"@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"
},
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.1.0",
"typings-test": "^1.0.3"
"@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"
}
}

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=

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

@ -0,0 +1,25 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as npmextra from '../ts/index';
let myKeyValueStore: npmextra.KeyValueStore;
tap.test('should create a keyValueStore', async () => {
myKeyValueStore = new npmextra.KeyValueStore('custom', 'test');
expect(myKeyValueStore).to.be.instanceof(npmextra.KeyValueStore);
});
tap.test('expect result to be empty', async () => {
let result = myKeyValueStore.readAll();
// tslint:disable-next-line:no-unused-expression
expect(result).to.be.empty;
});
tap.test('expect to add an object to the kv Store', async () => {
await myKeyValueStore.writeAll({
myKey: 'myValue'
});
await expect(myKeyValueStore.readKey('myKey')).to.eventually.equal('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 '@pushrocks/tapbundle';
import path = require('path');
import npmExtra = require('../dist/index')
// module to test
import npmExtra = require('../ts/index');
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).be.instanceof(npmExtra.Npmextra);
});
tap.test('should state wether a npmextra.json exists', async () => {
// tslint:disable-next-line:no-unused-expression
expect(testNpmextra.npmextraJsonExists).be.true;
});
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');
});
tap.test('should read a config file', async () => {
let testData = testNpmextra.dataFor<any>('testTool', {
someKey2: 'someValue2'
});
expect(testData).have.ownProperty('someKey2');
expect(testData.testValue).equal(2);
});
tap.start();

View File

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

View File

@ -1,68 +1,119 @@
import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
import * as plugins from './npmextra.plugins';
import * as paths from './npmextra.paths';
export type keyValueStoreTypes = 'path' | 'gitProject' | 'customString'
import { Task, TaskOnce } from '@pushrocks/taskbuffer';
export type TKeyValueStore = 'path' | 'gitProject' | 'custom';
/**
* kvStore is a simple key vlaue store to store data about projects between runs
*/
export class KeyValueStore {
type: string // the type of the kvStore
identity: string // the identity of the kvStore
filePath: string // the filePath of the kvStore
constructor(typeArg: keyValueStoreTypes, identityStringArg?: string) {
// set kvStoreType
this.type = typeArg
this.initIdentity(identityStringArg)
this.initFilePath()
public dataObject: any;
public deletedObject: any = {};
public initialReadTask = new TaskOnce({
taskFunction: async () => {
this.dataObject = plugins.smartfile.fs.toObjectSync(this.filePath);
}
});
public syncTask = new Task({
buffered: true,
bufferMax: 2,
execDelay: 500,
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(JSON.stringify(this.dataObject), this.filePath);
},
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
/**
* reads a keyValueFile from disk
*/
read() {
/**
* the constructor of keyvalue store
* @param typeArg
* @param customStringArg
*/
constructor(typeArg: TKeyValueStore, customStringArg: string) {
// set kvStoreType
this.type = typeArg;
this.identity = customStringArg;
this.initFilePath();
}
/**
* reads all keyValue pairs at once and returns them
*/
public async readAll() {
await this.initialReadTask.trigger();
this.syncTask.trigger();
return this.dataObject;
}
/**
* reads a keyValueFile from disk
*/
public async readKey(keyArg: string) {
let data = await this.readAll();
return data[keyArg];
}
/**
* writes a specific key to the keyValueStore
*/
async writeKey(keyArg: string, valueArg: any) {
let writeObject: any = {};
writeObject[keyArg] = valueArg;
this.writeAll(writeObject);
}
/**
* writes all keyValue pairs in the object argument
*/
public async writeAll(keyValueObject) {
this.dataObject = {...this.dataObject, ...keyValueObject};
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];
}
}
/**
* writes a key value file to disk
*/
write() {
/**
* updates a value
*/
public async update(keyObject) {};
/**
* 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;
}
/**
* wipes a key value store from disk
*/
wipe() {
}
/**
* updates a value
*/
update() {
}
/**
* computes the identity
*/
private initIdentity(identityStringArg: string) {
}
/**
* computes the filePath
*/
private initFilePath() {
let baseDir: string
if (this.type === 'customString') {
baseDir = paths.kvCusomDir
} 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.ensureFileSync(this.filePath,'{}')
}
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, '{}');
}
}

View File

@ -1,68 +1,72 @@
import * as plugins from './npmextra.plugins'
import * as paths from './npmextra.paths'
import * as plugins from './npmextra.plugins';
import * as paths from './npmextra.paths';
/**
* 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,14 +1,34 @@
import * as plugins from './npmextra.plugins'
import * as plugins from './npmextra.plugins';
// directories
export let cwd = process.cwd()
export let packageDir = plugins.path.join(__dirname,'../')
export let cwd = process.cwd();
export let packageDir = plugins.path.join(__dirname, '../');
// ----------------------
// keyValueStore specific
export let kvBase = '~/.npmextra/kv'
export let kvCusomDir = plugins.path.join(kvBase, 'custom')
export let kvGitDir = plugins.path.join(kvBase, 'git')
export let kvPathDir = plugins.path.join(kvBase, 'path')
// ----------------------
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');
// files
export let configFile = plugins.path.join(cwd,'npmextra.json')
export let configFile = plugins.path.join(cwd, 'npmextra.json');

View File

@ -1,6 +1,8 @@
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 beautylog from '@pushrocks/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';
export { beautylog, path, smartfile, smartpath, smartpromise, taskbuffer };

View File

@ -1,3 +1,17 @@
{
"extends": "tslint-config-standard"
}
"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"
}