@qelos/plugins-cli 0.0.1
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/.nvmrc +1 -0
- package/CONTRIBUTING.md +8 -0
- package/LICENSE.md +9 -0
- package/README.md +13 -0
- package/cli.mjs +25 -0
- package/commands/create.mjs +15 -0
- package/controllers/create.mjs +56 -0
- package/jest.config.js +195 -0
- package/package.json +33 -0
- package/services/create.js +20 -0
- package/services/hashing.js +9 -0
- package/store/cli.js +20 -0
- package/store/progress-bar.js +46 -0
- package/utils/colors.mjs +22 -0
- package/utils/process-handler.js +29 -0
- package/utils/progress-bar.mjs +21 -0
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
16
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Contribute to Greenpress cli
|
|
2
|
+
## Greenpress [Contribute Guide](https://docs.greenpress.info/guide/contribute/getting-started.html)
|
|
3
|
+
|
|
4
|
+
## Greenpress [Installation Guide](https://docs.greenpress.info/guide/getting-started.html)
|
|
5
|
+
|
|
6
|
+
## greenpress-cli [README](./README.md)
|
|
7
|
+
|
|
8
|
+
## [Open Issues](https://github.com/greenpress/greenpress-cli/issues)
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 David Meir-Levy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Qelos CLI
|
|
2
|
+
|
|
3
|
+
A command-line interface to help you create and manage your Qelos plugins.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
> npm install -g @qelos/plugins-cli
|
|
7
|
+
|
|
8
|
+
## Commands
|
|
9
|
+
|
|
10
|
+
### Create a new plugin
|
|
11
|
+
|
|
12
|
+
Basic usage to create new plugin
|
|
13
|
+
> qplay create my-app
|
package/cli.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'zx/globals';
|
|
3
|
+
|
|
4
|
+
import { dirname, join } from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import yargs from 'yargs'
|
|
7
|
+
import {hideBin} from 'yargs/helpers';
|
|
8
|
+
import process from 'node:process';
|
|
9
|
+
import createCommand from './commands/create.mjs';
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
const program = yargs(hideBin(process.argv));
|
|
14
|
+
const pkg = await fs.readJSON(join(__dirname, 'package.json'));
|
|
15
|
+
program.version(pkg.version)
|
|
16
|
+
|
|
17
|
+
program.option('verbose', {
|
|
18
|
+
alias: 'V',
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
description: 'Run with verbose logging'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
createCommand(program)
|
|
24
|
+
|
|
25
|
+
program.help().argv;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import createController from "../controllers/create.mjs";
|
|
2
|
+
|
|
3
|
+
export default function createCommand(program) {
|
|
4
|
+
program
|
|
5
|
+
.command('create [name]', 'create a new plugin',
|
|
6
|
+
(yargs) => {
|
|
7
|
+
return yargs
|
|
8
|
+
.positional('name', {
|
|
9
|
+
describe: 'The name of your application. A folder with that name will be created here.',
|
|
10
|
+
default: 'qelos',
|
|
11
|
+
type: 'string'
|
|
12
|
+
})
|
|
13
|
+
},
|
|
14
|
+
createController)
|
|
15
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import follow from "follow-redirects";
|
|
2
|
+
import cliSelect from "cli-select";
|
|
3
|
+
import {blue} from "../utils/colors.mjs";
|
|
4
|
+
import DecompressZip from "decompress-zip";
|
|
5
|
+
import {join} from "path";
|
|
6
|
+
import rimraf from 'rimraf'
|
|
7
|
+
import ProgressBar from "../utils/progress-bar.mjs";
|
|
8
|
+
|
|
9
|
+
const https = follow.https;
|
|
10
|
+
|
|
11
|
+
export default async function createController({name}) {
|
|
12
|
+
console.log(blue('Choose a boilerplate:'))
|
|
13
|
+
const result = await cliSelect({
|
|
14
|
+
values: {vanilla: 'Vanilla', react: 'React', vue: 'Vue', solid: 'Solid', custom: 'Custom from Github'},
|
|
15
|
+
})
|
|
16
|
+
const tempFolder = 'ql-plugin-' + Date.now();
|
|
17
|
+
const file = fs.createWriteStream(tempFolder + '.zip')
|
|
18
|
+
|
|
19
|
+
function extract(unzipper) {
|
|
20
|
+
const progress = new ProgressBar(100);
|
|
21
|
+
return new Promise((resolve) => {
|
|
22
|
+
unzipper.on('extract', function (log) {
|
|
23
|
+
resolve(log[0].folder)
|
|
24
|
+
progress.stop();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
unzipper.on('progress', function (fileIndex, fileCount) {
|
|
28
|
+
progress.update(fileIndex / fileCount);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
unzipper.extract({
|
|
32
|
+
path: tempFolder
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const request = https.get(`https://github.com/qelos-boilerplates/${result.id}/archive/refs/heads/main.zip`, (response) => {
|
|
38
|
+
response.pipe(file);
|
|
39
|
+
response.on('end', async () => {
|
|
40
|
+
try {
|
|
41
|
+
file.close();
|
|
42
|
+
const unzipper = new DecompressZip(tempFolder + '.zip');
|
|
43
|
+
const rootFolder = await extract(unzipper);
|
|
44
|
+
|
|
45
|
+
fs.renameSync(join(tempFolder, rootFolder), name);
|
|
46
|
+
|
|
47
|
+
console.log(`Created ${name} successfully.`)
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.log('Failed');
|
|
50
|
+
} finally {
|
|
51
|
+
await rimraf(tempFolder)
|
|
52
|
+
fs.rmSync(tempFolder + '.zip');
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
};
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* For a detailed explanation regarding each configuration property, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
// All imported modules in your tests should be mocked automatically
|
|
8
|
+
// automock: false,
|
|
9
|
+
|
|
10
|
+
// Stop running tests after `n` failures
|
|
11
|
+
// bail: 0,
|
|
12
|
+
|
|
13
|
+
// The directory where Jest should store its cached dependency information
|
|
14
|
+
// cacheDirectory: "/private/var/folders/zz/q3q8dtb14s3d6g9q49fk4zbh0000gn/T/jest_dx",
|
|
15
|
+
|
|
16
|
+
// Automatically clear mock calls and instances between every test
|
|
17
|
+
clearMocks: true,
|
|
18
|
+
|
|
19
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
20
|
+
collectCoverage: true,
|
|
21
|
+
|
|
22
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
23
|
+
// collectCoverageFrom: undefined,
|
|
24
|
+
|
|
25
|
+
// The directory where Jest should output its coverage files
|
|
26
|
+
coverageDirectory: "coverage",
|
|
27
|
+
|
|
28
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
29
|
+
// coveragePathIgnorePatterns: [
|
|
30
|
+
// "/node_modules/"
|
|
31
|
+
// ],
|
|
32
|
+
|
|
33
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
34
|
+
coverageProvider: "v8",
|
|
35
|
+
|
|
36
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
37
|
+
// coverageReporters: [
|
|
38
|
+
// "json",
|
|
39
|
+
// "text",
|
|
40
|
+
// "lcov",
|
|
41
|
+
// "clover"
|
|
42
|
+
// ],
|
|
43
|
+
|
|
44
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
45
|
+
// coverageThreshold: undefined,
|
|
46
|
+
|
|
47
|
+
// A path to a custom dependency extractor
|
|
48
|
+
// dependencyExtractor: undefined,
|
|
49
|
+
|
|
50
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
51
|
+
// errorOnDeprecated: false,
|
|
52
|
+
|
|
53
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
54
|
+
// forceCoverageMatch: [],
|
|
55
|
+
|
|
56
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
57
|
+
// globalSetup: undefined,
|
|
58
|
+
|
|
59
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
60
|
+
// globalTeardown: undefined,
|
|
61
|
+
|
|
62
|
+
// A set of global variables that need to be available in all test environments
|
|
63
|
+
// globals: {},
|
|
64
|
+
|
|
65
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
66
|
+
// maxWorkers: "50%",
|
|
67
|
+
|
|
68
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
69
|
+
// moduleDirectories: [
|
|
70
|
+
// "node_modules"
|
|
71
|
+
// ],
|
|
72
|
+
|
|
73
|
+
// An array of file extensions your modules use
|
|
74
|
+
// moduleFileExtensions: [
|
|
75
|
+
// "js",
|
|
76
|
+
// "jsx",
|
|
77
|
+
// "ts",
|
|
78
|
+
// "tsx",
|
|
79
|
+
// "json",
|
|
80
|
+
// "node"
|
|
81
|
+
// ],
|
|
82
|
+
|
|
83
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
84
|
+
// moduleNameMapper: {},
|
|
85
|
+
|
|
86
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
87
|
+
// modulePathIgnorePatterns: [],
|
|
88
|
+
|
|
89
|
+
// Activates notifications for test results
|
|
90
|
+
// notify: false,
|
|
91
|
+
|
|
92
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
93
|
+
// notifyMode: "failure-change",
|
|
94
|
+
|
|
95
|
+
// A preset that is used as a base for Jest's configuration
|
|
96
|
+
// preset: undefined,
|
|
97
|
+
|
|
98
|
+
// Run tests from one or more projects
|
|
99
|
+
// projects: undefined,
|
|
100
|
+
|
|
101
|
+
// Use this configuration option to add custom reporters to Jest
|
|
102
|
+
// reporters: undefined,
|
|
103
|
+
|
|
104
|
+
// Automatically reset mock state between every test
|
|
105
|
+
// resetMocks: false,
|
|
106
|
+
|
|
107
|
+
// Reset the module registry before running each individual test
|
|
108
|
+
// resetModules: false,
|
|
109
|
+
|
|
110
|
+
// A path to a custom resolver
|
|
111
|
+
// resolver: undefined,
|
|
112
|
+
|
|
113
|
+
// Automatically restore mock state between every test
|
|
114
|
+
// restoreMocks: false,
|
|
115
|
+
|
|
116
|
+
// The root directory that Jest should scan for tests and modules within
|
|
117
|
+
// rootDir: undefined,
|
|
118
|
+
|
|
119
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
120
|
+
// roots: [
|
|
121
|
+
// "<rootDir>"
|
|
122
|
+
// ],
|
|
123
|
+
|
|
124
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
125
|
+
// runner: "jest-runner",
|
|
126
|
+
|
|
127
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
128
|
+
// setupFiles: [],
|
|
129
|
+
|
|
130
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
131
|
+
// setupFilesAfterEnv: [],
|
|
132
|
+
|
|
133
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
134
|
+
// slowTestThreshold: 5,
|
|
135
|
+
|
|
136
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
137
|
+
// snapshotSerializers: [],
|
|
138
|
+
|
|
139
|
+
// The test environment that will be used for testing
|
|
140
|
+
// testEnvironment: "jest-environment-node",
|
|
141
|
+
|
|
142
|
+
// Options that will be passed to the testEnvironment
|
|
143
|
+
// testEnvironmentOptions: {},
|
|
144
|
+
|
|
145
|
+
// Adds a location field to test results
|
|
146
|
+
// testLocationInResults: false,
|
|
147
|
+
|
|
148
|
+
// The glob patterns Jest uses to detect test files
|
|
149
|
+
// testMatch: [
|
|
150
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
151
|
+
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
152
|
+
// ],
|
|
153
|
+
|
|
154
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
155
|
+
testPathIgnorePatterns: [
|
|
156
|
+
"/node_modules/",
|
|
157
|
+
"/tmp/"
|
|
158
|
+
],
|
|
159
|
+
|
|
160
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
161
|
+
// testRegex: [],
|
|
162
|
+
|
|
163
|
+
// This option allows the use of a custom results processor
|
|
164
|
+
// testResultsProcessor: undefined,
|
|
165
|
+
|
|
166
|
+
// This option allows use of a custom test runner
|
|
167
|
+
// testRunner: "jest-circus/runner",
|
|
168
|
+
|
|
169
|
+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
170
|
+
// testURL: "http://localhost",
|
|
171
|
+
|
|
172
|
+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
173
|
+
// timers: "real",
|
|
174
|
+
|
|
175
|
+
// A map from regular expressions to paths to transformers
|
|
176
|
+
// transform: undefined,
|
|
177
|
+
|
|
178
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
179
|
+
// transformIgnorePatterns: [
|
|
180
|
+
// "/node_modules/",
|
|
181
|
+
// "\\.pnp\\.[^\\/]+$"
|
|
182
|
+
// ],
|
|
183
|
+
|
|
184
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
185
|
+
// unmockedModulePathPatterns: undefined,
|
|
186
|
+
|
|
187
|
+
// Indicates whether each individual test should be reported during the run
|
|
188
|
+
// verbose: undefined,
|
|
189
|
+
|
|
190
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
191
|
+
// watchPathIgnorePatterns: [],
|
|
192
|
+
|
|
193
|
+
// Whether to use watchman for file crawling
|
|
194
|
+
watchman: false,
|
|
195
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qelos/plugins-cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI to manage QELOS plugins",
|
|
5
|
+
"main": "cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"qplay": "cli.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"qelos",
|
|
11
|
+
"cli"
|
|
12
|
+
],
|
|
13
|
+
"author": "David Meir-Levy <davidmeirlevy@gmail.com>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"cli-progress": "^3.11.2",
|
|
17
|
+
"cli-select": "^1.1.2",
|
|
18
|
+
"decompress-zip": "^0.3.3",
|
|
19
|
+
"follow-redirects": "^1.15.2",
|
|
20
|
+
"rimraf": "^4.1.2",
|
|
21
|
+
"yargs": "^17.2.0",
|
|
22
|
+
"zx": "^7.1.1"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "jest --runInBand"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"jest": "^27.5.1"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const execute = require("../utils/execute");
|
|
3
|
+
const { red } = require("../utils/colors");
|
|
4
|
+
|
|
5
|
+
function installNodeDependencies(directoryName) {
|
|
6
|
+
console.log(process.cwd(), directoryName);
|
|
7
|
+
try {
|
|
8
|
+
execute(`npm install`, "install dependencies", {
|
|
9
|
+
cwd: directoryName,
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
});
|
|
12
|
+
} catch {
|
|
13
|
+
console.log(red(`Failed to install dependencies using \`npm install\`.`));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
installNodeDependencies,
|
|
20
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
function getRandomHash() {
|
|
4
|
+
const currentDate = new Date().valueOf().toString()
|
|
5
|
+
const random = Math.random().toString()
|
|
6
|
+
return crypto.createHash('sha1').update(currentDate + random).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
module.exports = { getRandomHash }
|
package/store/cli.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class CliStore {
|
|
2
|
+
|
|
3
|
+
isVerbose = true;
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
this.isVerbose = process.argv.includes('--verbose');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let store;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
getCliStore() {
|
|
15
|
+
if (!store) {
|
|
16
|
+
store = new CliStore();
|
|
17
|
+
}
|
|
18
|
+
return store;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const ProgressBar = require('../utils/progress-bar');
|
|
2
|
+
|
|
3
|
+
class ProgressBarStore {
|
|
4
|
+
state = {
|
|
5
|
+
progress: 0,
|
|
6
|
+
total: 0
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
start(total) {
|
|
10
|
+
this.state.total = total;
|
|
11
|
+
this.state.progress = 0;
|
|
12
|
+
if (this._progressBar) {
|
|
13
|
+
this.stop();
|
|
14
|
+
}
|
|
15
|
+
this._progressBar = new ProgressBar(total, this.state.progress);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
increment(progress = 0) {
|
|
19
|
+
this.state.progress += progress;
|
|
20
|
+
this._progressBar.increment(progress);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
isResolved() {
|
|
24
|
+
return this.state.progress >= this.state.total;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
stop() {
|
|
28
|
+
this._progressBar.stop();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let store;
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @returns {ProgressBarStore}
|
|
38
|
+
*/
|
|
39
|
+
getProgressBarStore() {
|
|
40
|
+
if (!store) {
|
|
41
|
+
store = new ProgressBarStore();
|
|
42
|
+
}
|
|
43
|
+
return store;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
package/utils/colors.mjs
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const colorMap = new Map();
|
|
2
|
+
colorMap.set("cyan", 36);
|
|
3
|
+
colorMap.set("yellow", 33);
|
|
4
|
+
colorMap.set("green", 32);
|
|
5
|
+
colorMap.set("red", 31);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* logs the text to the console with the required color
|
|
9
|
+
* @param {string} text
|
|
10
|
+
* @param {string} color
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
function logColor(text, color) {
|
|
14
|
+
if (colorMap.has(color)) {
|
|
15
|
+
return `\x1b[${colorMap.get(color)}m${text}\x1b[0m`;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const green = (text) => logColor(text, "green");
|
|
20
|
+
export const blue = (text) => logColor(text, "cyan");
|
|
21
|
+
export const yellow = (text) => logColor(text, "yellow");
|
|
22
|
+
export const red = (text) => logColor(text, "red");
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function getProcessHandler(proc) {
|
|
2
|
+
let onExit, onData, onError;
|
|
3
|
+
|
|
4
|
+
proc.stderr.on('error', (err) => {
|
|
5
|
+
console.log(err.toString());
|
|
6
|
+
onError && onError(err);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
proc.stdout.on('data', (data) => {
|
|
10
|
+
onData && onData(data);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
proc.on('close', (code) => {
|
|
14
|
+
console.log('process exited');
|
|
15
|
+
onExit && onExit(code);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
onExit: (func) => onExit = func,
|
|
20
|
+
onData: (func) => onData = func,
|
|
21
|
+
onError: (func) => onError = func,
|
|
22
|
+
exit: () => proc.kill('SIGTERM'),
|
|
23
|
+
process: proc
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
getProcessHandler
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as cliProgress from "cli-progress";
|
|
2
|
+
|
|
3
|
+
export default class ProgressBar {
|
|
4
|
+
_progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
5
|
+
|
|
6
|
+
constructor(total = 100, start = 0) {
|
|
7
|
+
this._progressBar.start(total, start);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
stop() {
|
|
11
|
+
this._progressBar.stop();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
update(progress) {
|
|
15
|
+
this._progressBar.update(progress);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
increment(progress = 0) {
|
|
19
|
+
this._progressBar.increment(progress);
|
|
20
|
+
}
|
|
21
|
+
}
|