Compare commits

...

67 Commits

Author SHA1 Message Date
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
b1f8c79b8d 2.0.1 2016-09-24 16:52:41 +02:00
b0dbb9b8a0 added back ts generics 2016-09-24 16:52:38 +02:00
83108ce02d 2.0.0 2016-09-24 16:44:52 +02:00
2911dd4972 added new NpmExtra class 2016-09-24 16:44:48 +02:00
16150541b0 update changes 2016-09-23 22:13:06 +02:00
002f3fc82d 1.0.12 2016-09-18 16:10:24 +02:00
6925c2dbd0 compiled 2016-09-18 16:10:07 +02:00
156b64b699 improve README 2016-09-18 16:09:27 +02:00
77da229633 1.0.11 2016-09-17 18:12:59 +02:00
0cbea12067 fix README 2016-09-17 18:12:32 +02:00
e6b12b2c6d 1.0.10 2016-09-16 22:29:16 +02:00
d8c37a8b95 improve README 2016-09-16 22:29:12 +02:00
3b83cfaaac now adheres to standard js 2016-09-16 22:28:38 +02:00
febc3aa164 start key Value store 2016-08-28 14:51:04 +02:00
643fb6a6b7 1.0.9 2016-08-19 11:04:12 +02:00
51b734ef96 update dependencies 2016-08-19 10:57:58 +02:00
7d700f3285 improve README 2016-07-19 00:36:19 +02:00
4ee9c46b04 updated deps 2016-07-18 20:32:15 +02:00
0357857448 1.0.8 2016-07-18 20:29:37 +02:00
ec56eb75c2 add boolean for wether configfile is present 2016-07-18 20:29:29 +02:00
540e7610af 1.0.7 2016-07-17 17:10:56 +02:00
ba822576b1 fix typo 2016-07-17 17:10:53 +02:00
a6db675040 1.0.6 2016-07-17 16:35:48 +02:00
93bbe75f37 now merges default options 2016-07-17 16:34:31 +02:00
dc53498f22 1.0.5 2016-07-17 02:11:41 +02:00
4c205381d9 add typings to package.json 2016-07-17 02:11:39 +02:00
0c32b981c4 1.0.4 2016-07-17 02:10:01 +02:00
bda3600e98 fix dpendency version 2016-07-17 02:09:58 +02:00
dc0588d5bf 1.0.3 2016-07-17 01:55:00 +02:00
3437e48202 README fix 2016-07-17 01:54:57 +02:00
e8b21fd51b 1.0.2 2016-07-17 01:42:36 +02:00
1260d9357e improve README 2016-07-17 01:42:23 +02:00
23 changed files with 2214 additions and 137 deletions

20
.gitignore vendored
View File

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

View File

@ -1,35 +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: stages:
- security
- test - test
- release - release
- metadata
testLEGACY: # ====================
stage: test # security stage
# ====================
mirror:
stage: security
script: script:
- npmci test legacy - npmci git mirror
tags: 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: testLTS:
stage: test stage: test
script: script:
- npmci test lts - npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci test stable - npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci publish - npmci node install stable
- npmci npm publish
only: only:
- tags - 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: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 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: {}

61
README.md Normal file
View File

@ -0,0 +1,61 @@
# @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)

1
dist/index.d.ts vendored
View File

@ -1 +0,0 @@
export declare let dataFor: (toolNameArg: string, cwdArg?: string) => any;

31
dist/index.js vendored
View File

@ -1,31 +0,0 @@
"use strict";
const plugins = require("./npmextra.plugins");
const paths = require("./npmextra.paths");
let allData;
exports.dataFor = (toolNameArg, cwdArg) => {
if (typeof allData == "undefined") {
let lookupPath;
if (cwdArg) {
lookupPath = plugins.path.join(cwdArg, "npmextra.json");
}
else {
lookupPath = paths.configFile;
}
;
allData = plugins.smartfile.fs.toObjectSync(plugins.path.join(lookupPath));
}
;
if (toolNameArg) {
if (allData[toolNameArg]) {
return allData[toolNameArg];
}
else {
plugins.beautylog.error(`There is no data for ${toolNameArg}`);
return undefined;
}
}
else {
return allData;
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQ3pCLENBQUMsQ0FENEM7QUFDN0MsTUFBWSxLQUFLLFdBQU0sa0JBQWtCLENBQUMsQ0FBQTtBQUMxQyxJQUFJLE9BQU8sQ0FBQztBQUVELGVBQU8sR0FBRyxDQUFDLFdBQWtCLEVBQUMsTUFBYztJQUNuRCxFQUFFLENBQUEsQ0FBQyxPQUFPLE9BQU8sSUFBSSxXQUFXLENBQUMsQ0FBQSxDQUFDO1FBQzlCLElBQUksVUFBVSxDQUFDO1FBQ2YsRUFBRSxDQUFBLENBQUMsTUFBTSxDQUFDLENBQUEsQ0FBQztZQUNQLFVBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxNQUFNLEVBQUMsZUFBZSxDQUFDLENBQUM7UUFDM0QsQ0FBQztRQUFDLElBQUksQ0FBQyxDQUFDO1lBQ0osVUFBVSxHQUFHLEtBQUssQ0FBQyxVQUFVLENBQUM7UUFDbEMsQ0FBQztRQUFBLENBQUM7UUFDRixPQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxFQUFFLENBQUMsWUFBWSxDQUN2QyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxVQUFVLENBQUMsQ0FDaEMsQ0FBQztJQUNOLENBQUM7SUFBQSxDQUFDO0lBQ0YsRUFBRSxDQUFBLENBQUMsV0FBVyxDQUFDLENBQUEsQ0FBQztRQUNaLEVBQUUsQ0FBQSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFBLENBQUM7WUFDckIsTUFBTSxDQUFDLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUNoQyxDQUFDO1FBQUMsSUFBSSxDQUFDLENBQUM7WUFDSixPQUFPLENBQUMsU0FBUyxDQUFDLEtBQUssQ0FBQyx3QkFBd0IsV0FBVyxFQUFFLENBQUMsQ0FBQztZQUMvRCxNQUFNLENBQUMsU0FBUyxDQUFDO1FBQ3JCLENBQUM7SUFDTCxDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDSixNQUFNLENBQUMsT0FBTyxDQUFDO0lBQ25CLENBQUM7QUFDTCxDQUFDLENBQUEifQ==

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, "../");
//
exports.configFile = plugins.path.join(exports.cwd, "npmextra.json");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGF0aHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9ucG1leHRyYS5wYXRocy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0sb0JBQW9CLENBQUMsQ0FBQTtBQUU5QyxjQUFjO0FBQ0gsV0FBRyxHQUFHLE9BQU8sQ0FBQyxHQUFHLEVBQUUsQ0FBQztBQUNwQixrQkFBVSxHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBQyxLQUFLLENBQUMsQ0FBQztBQUUzRCxFQUFFO0FBQ1Msa0JBQVUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxXQUFHLEVBQUMsZUFBZSxDQUFDLENBQUMifQ==

View File

@ -1,5 +0,0 @@
import "typings-global";
export import beautylog = require("beautylog");
export import path = require("path");
export import smartfile = require("smartfile");
export import q = require("q");

View File

@ -1,7 +0,0 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.path = require("path");
exports.smartfile = require("smartfile");
exports.q = require("q");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibnBtZXh0cmEucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL25wbWV4dHJhLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sZ0JBQWdCLENBQUMsQ0FBQTtBQUNWLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsWUFBSSxXQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ3ZCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUM7QUFDakMsU0FBQyxXQUFXLEdBQUcsQ0FBQyxDQUFDIn0=

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

1692
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,13 @@
{ {
"name": "npmextra", "name": "@pushrocks/npmextra",
"version": "1.0.1", "version": "3.0.6",
"private": false,
"description": "do more with npm", "description": "do more with npm",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(tstest test/)",
"build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -17,14 +20,19 @@
}, },
"homepage": "https://gitlab.com/pushrocks/npmextra#README", "homepage": "https://gitlab.com/pushrocks/npmextra#README",
"dependencies": { "dependencies": {
"@types/q": "0.0.27", "@pushrocks/smartfile": "^7.0.4",
"beautylog": "^5.0.14", "@pushrocks/smartlog": "^2.0.19",
"q": "^1.4.1", "@pushrocks/smartpath": "^4.0.1",
"smartfile": "^4.0.10", "@pushrocks/smartpromise": "^3.0.5",
"typings-global": "^1.0.6" "@pushrocks/taskbuffer": "^2.0.10"
}, },
"devDependencies": { "devDependencies": {
"should": "^9.0.2", "@gitzone/tsbuild": "^2.1.17",
"typings-test": "^1.0.1" "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.5",
"tslint": "^5.20.0",
"tslint-config-prettier": "^1.18.0"
} }
} }

2
test/test.d.ts vendored
View File

@ -1,2 +0,0 @@
import "typings-test";
import "should";

View File

@ -1,12 +0,0 @@
"use strict";
require("typings-test");
const path = require("path");
require("should");
const npmExtra = require("../dist/index");
describe("npmextra", function () {
it("should read a config file", function () {
let testData = npmExtra.dataFor("testTool", path.join(process.cwd(), "test/"));
console.log(testData);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FBYyxDQUFDLENBQUE7QUFDdEIsTUFBTyxJQUFJLFdBQVcsTUFBTSxDQUFDLENBQUM7QUFDOUIsUUFBTyxRQUFRLENBQUMsQ0FBQTtBQUVoQixNQUFPLFFBQVEsV0FBVyxlQUFlLENBQUMsQ0FBQztBQUUzQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQywyQkFBMkIsRUFBQztRQUMzQixJQUFJLFFBQVEsR0FBRyxRQUFRLENBQUMsT0FBTyxDQUFDLFVBQVUsRUFBQyxJQUFJLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLEVBQUUsRUFBQyxPQUFPLENBQUMsQ0FBQyxDQUFDO1FBQzdFLE9BQU8sQ0FBQyxHQUFHLENBQUMsUUFBUSxDQUFDLENBQUM7SUFDMUIsQ0FBQyxDQUFDLENBQUM7QUFDUCxDQUFDLENBQUMsQ0FBQyJ9

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,12 +1,33 @@
import "typings-test"; import { expect, tap } from '@pushrocks/tapbundle';
import path = require("path"); import path = require('path');
import "should";
import npmExtra = require("../dist/index"); // module to test
import npmExtra = require('../ts/index');
describe("npmextra",function(){ let testNpmextra: npmExtra.Npmextra;
it("should read a config file",function(){
let testData = npmExtra.dataFor("testTool",path.join(process.cwd(),"test/")); 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); 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,27 +1,4 @@
import * as plugins from "./npmextra.plugins" import * as plugins from './npmextra.plugins';
import * as paths from "./npmextra.paths";
let allData;
export let dataFor = (toolNameArg:string,cwdArg?:string) => { export * from './npmextra.classes.npmextra';
if(typeof allData == "undefined"){ export * from './npmextra.classes.keyvaluestore';
let lookupPath;
if(cwdArg){
lookupPath = plugins.path.join(cwdArg,"npmextra.json");
} else {
lookupPath = paths.configFile;
};
allData = plugins.smartfile.fs.toObjectSync(
plugins.path.join(lookupPath)
);
};
if(toolNameArg){
if(allData[toolNameArg]){
return allData[toolNameArg];
} else {
plugins.beautylog.error(`There is no data for ${toolNameArg}`);
return undefined;
}
} else {
return allData;
}
}

View File

@ -0,0 +1,113 @@
import * as plugins from './npmextra.plugins';
import * as paths from './npmextra.paths';
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 {
private dataObject: any = {};
private deletedObject: any = {};
public syncTask = new Task({
name: 'syncTask',
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);
},
});
/**
* 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;
}
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, '{}');
}
public type: TKeyValueStore; // the type of the kvStore
public identity: string; // the identity of the kvStore
public filePath: string; // the filePath of the kvStore
/**
* 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.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) {
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);
}
}

View File

@ -0,0 +1,72 @@
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: any;
/**
* creates instance of Npmextra
*/
constructor(cwdArg?: string) {
if (cwdArg) {
this.cwd = cwdArg;
} else {
this.cwd = paths.cwd;
}
this.checkLookupPath();
this.checkNpmextraJsonExists();
this.checkNpmextraJsonData();
}
/**
* merges the supplied options with the ones from npmextra.json
*/
dataFor<IToolConfig>(toolnameArg: string, defaultOptionsArg: any): IToolConfig {
let npmextraToolOptions;
if (this.npmextraJsonData[toolnameArg]) {
npmextraToolOptions = this.npmextraJsonData[toolnameArg];
} else {
npmextraToolOptions = {};
}
let mergedOptions = {
...defaultOptionsArg,
...npmextraToolOptions
};
return mergedOptions;
}
/**
* checks if the JSON exists
*/
private checkNpmextraJsonExists() {
this.npmextraJsonExists = plugins.smartfile.fs.fileExistsSync(this.lookupPath);
}
/**
* gets lookupPath
*/
private checkLookupPath() {
if (this.cwd) {
this.lookupPath = plugins.path.join(this.cwd, 'npmextra.json');
} else {
this.lookupPath = paths.configFile;
}
}
/**
* get npmextraJsonData
*/
private checkNpmextraJsonData() {
if (this.npmextraJsonExists) {
this.npmextraJsonData = plugins.smartfile.fs.toObjectSync(this.lookupPath);
} else {
this.npmextraJsonData = {};
}
}
}

View File

@ -1,8 +1,34 @@
import * as plugins from "./npmextra.plugins"; import * as plugins from './npmextra.plugins';
// directories // directories
export let cwd = process.cwd(); export let cwd = process.cwd();
export let packageDir = plugins.path.join(__dirname,"../"); export let packageDir = plugins.path.join(__dirname, '../');
// // ----------------------
export let configFile = plugins.path.join(cwd,"npmextra.json"); // keyValueStore specific
// ----------------------
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');

View File

@ -1,5 +1,8 @@
import "typings-global"; import * as beautylog from '@pushrocks/smartlog';
export import beautylog = require("beautylog"); import * as path from 'path';
export import path = require("path"); import * as smartfile from '@pushrocks/smartfile';
export import smartfile = require("smartfile"); import * as smartpath from '@pushrocks/smartpath';
export import q = require("q"); import * as smartpromise from '@pushrocks/smartpromise';
import * as taskbuffer from '@pushrocks/taskbuffer';
export { beautylog, path, smartfile, smartpath, smartpromise, taskbuffer };

17
tslint.json Normal file
View File

@ -0,0 +1,17 @@
{
"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"
}