repository-provider-cli-support 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +12 -0
- package/package.json +57 -0
- package/src/setup-provider.mjs +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (c) 2023 by repository-provider-cli-support
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
20
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
21
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
22
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
23
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/repository-provider-cli-support)
|
|
2
|
+
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
3
|
+
[](https://bundlejs.com/?q=repository-provider-cli-support)
|
|
4
|
+
[](https://npmjs.org/package/repository-provider-cli-support)
|
|
5
|
+
[](https://github.com/arlac77/repository-provider-cli-support/issues)
|
|
6
|
+
[](https://actions-badge.atrox.dev/arlac77/repository-provider-cli-support/goto)
|
|
7
|
+
[](https://github.com/prettier/prettier)
|
|
8
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
9
|
+
[](https://snyk.io/test/github/arlac77/repository-provider-cli-support)
|
|
10
|
+
[](https://coveralls.io/github/arlac77/repository-provider-cli-support)
|
|
11
|
+
# repository-provider-cli-support
|
|
12
|
+
helper functions for cli apps
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "repository-provider-cli-support",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/setup-provider.mjs"
|
|
9
|
+
},
|
|
10
|
+
"description": "helper functions for cli apps",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"repository-provider"
|
|
13
|
+
],
|
|
14
|
+
"contributors": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Markus Felten",
|
|
17
|
+
"email": "markus.felten@gmx.de"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"license": "BSD-2-Clause",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "npm run test:ava",
|
|
23
|
+
"test:ava": "ava --timeout 2m tests/*-ava.mjs tests/*-ava-node.mjs",
|
|
24
|
+
"cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 2m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
|
|
25
|
+
"docs": "documentation readme --section=API ./src/**/*.mjs",
|
|
26
|
+
"lint": "npm run lint:docs",
|
|
27
|
+
"lint:docs": "documentation lint ./src/**/*.mjs"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"aggregation-repository-provider": "^5.3.27",
|
|
31
|
+
"etag-cache-leveldb": "^2.0.2",
|
|
32
|
+
"leveldown": "^6.1.1",
|
|
33
|
+
"levelup": "^5.1.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"ava": "^5.2.0",
|
|
37
|
+
"c8": "^7.13.0",
|
|
38
|
+
"commander": "^10.0.1",
|
|
39
|
+
"documentation": "^14.0.1",
|
|
40
|
+
"github-repository-provider": "^8.0.15",
|
|
41
|
+
"semantic-release": "^21.0.2"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/arlac77/repository-provider-cli-support"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/arlac77/repository-provider-cli-support/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/arlac77/repository-provider-cli-support#readme",
|
|
51
|
+
"template": {
|
|
52
|
+
"inheritFrom": [
|
|
53
|
+
"arlac77/template-arlac77-github",
|
|
54
|
+
"arlac77/template-esm-only"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import AggregationProvider from "aggregation-repository-provider";
|
|
2
|
+
import { ETagCacheLevelDB } from "etag-cache-leveldb";
|
|
3
|
+
import levelup from "levelup";
|
|
4
|
+
import leveldown from "leveldown";
|
|
5
|
+
import { mkdir } from "node:fs/promises";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
import { Agent } from "node:https";
|
|
9
|
+
|
|
10
|
+
process.on("uncaughtException", console.error);
|
|
11
|
+
process.on("unhandledRejection", console.error);
|
|
12
|
+
|
|
13
|
+
async function createCache() {
|
|
14
|
+
const dir = join(homedir(), ".cache/repository-provider");
|
|
15
|
+
await mkdir(dir, { recursive: true });
|
|
16
|
+
const db = await levelup(leveldown(dir));
|
|
17
|
+
return new ETagCacheLevelDB(db);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const httpsAgent = new Agent({ keepAlive: true });
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {*} program
|
|
25
|
+
* @param {Object} properties
|
|
26
|
+
* @returns {Promise<Object>} with provider, options, and cache
|
|
27
|
+
*/
|
|
28
|
+
export async function initializeRepositoryProvider(program, properties) {
|
|
29
|
+
const provider = await AggregationProvider.initialize(
|
|
30
|
+
[],
|
|
31
|
+
properties,
|
|
32
|
+
process.env
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const options = program.opts();
|
|
36
|
+
|
|
37
|
+
provider.messageDestination = {
|
|
38
|
+
...console,
|
|
39
|
+
trace: options.trace ? console.log : () => {}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let cache;
|
|
43
|
+
if (options.cache) {
|
|
44
|
+
cache = await createCache();
|
|
45
|
+
provider._providers.forEach(p => (p.cache = cache));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
provider._providers.forEach(p => (p.agent = url => httpsAgent));
|
|
49
|
+
|
|
50
|
+
return { provider, options, cache };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Add extra cli options.
|
|
55
|
+
* @param {*} program
|
|
56
|
+
*/
|
|
57
|
+
export function initializeCommandLine(program) {
|
|
58
|
+
program
|
|
59
|
+
.option("--no-cache", "cache requests")
|
|
60
|
+
.option("--statistics", "show cache statistics");
|
|
61
|
+
}
|