@digigov/cli 2.0.0-d4fe516b → 2.0.0-e20fed09
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/index.js +3 -3
- package/lib/command.js +24 -22
- package/lib/index.js +3 -3
- package/lib/logger.js +10 -10
- package/lib/project-utils.cjs +34 -34
- package/load-commands.js +11 -12
- package/package.json +5 -4
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { DigigovCommand } from
|
|
4
|
-
import { loadCommands } from
|
|
3
|
+
import { DigigovCommand } from './lib/command.js';
|
|
4
|
+
import { loadCommands } from './load-commands.js';
|
|
5
5
|
|
|
6
|
-
const program = new DigigovCommand(
|
|
6
|
+
const program = new DigigovCommand('digigov', import.meta.url);
|
|
7
7
|
|
|
8
8
|
await loadCommands(program);
|
|
9
9
|
|
package/lib/command.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import * as execa from
|
|
4
|
-
import * as commander from
|
|
5
|
-
import { fileURLToPath } from
|
|
6
|
-
import { logger } from
|
|
7
|
-
import { findPackageJson } from
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as execa from 'execa';
|
|
4
|
+
import * as commander from 'commander';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { logger } from './logger.js';
|
|
7
|
+
import { findPackageJson } from './project-utils.cjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A class that extends the Commander Command class with additional
|
|
@@ -33,14 +33,14 @@ export class DigigovCommand extends commander.Command {
|
|
|
33
33
|
? path.dirname(fileURLToPath(importMetaUrl))
|
|
34
34
|
: null;
|
|
35
35
|
|
|
36
|
-
this.option(
|
|
36
|
+
this.option('-d, --debug', 'display debug information');
|
|
37
37
|
|
|
38
38
|
this.configureOutput({
|
|
39
|
-
writeErr: (str) => logger.error(str.replace(/^error: /i,
|
|
39
|
+
writeErr: (str) => logger.error(str.replace(/^error: /i, '')),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
if (this.context) {
|
|
43
|
-
if (this.context.endsWith(
|
|
43
|
+
if (this.context.endsWith('dist')) {
|
|
44
44
|
this.context = path.dirname(this.context);
|
|
45
45
|
}
|
|
46
46
|
const pkgPath = findPackageJson(this.context);
|
|
@@ -91,23 +91,23 @@ export class DigigovCommand extends commander.Command {
|
|
|
91
91
|
const __dirname =
|
|
92
92
|
this.context ?? path.dirname(fileURLToPath(import.meta.url));
|
|
93
93
|
const binLocation = [process.cwd(), __dirname].find((location) => {
|
|
94
|
-
return fs.existsSync(path.join(location,
|
|
94
|
+
return fs.existsSync(path.join(location, 'node_modules', '.bin', script));
|
|
95
95
|
});
|
|
96
96
|
if (!binLocation || !fs.existsSync(binLocation)) {
|
|
97
97
|
this.#throwError(`Executable ${script} not installed`);
|
|
98
98
|
}
|
|
99
99
|
const executablePath = path.join(
|
|
100
100
|
binLocation,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
script
|
|
101
|
+
'node_modules',
|
|
102
|
+
'.bin',
|
|
103
|
+
script
|
|
104
104
|
);
|
|
105
105
|
const executableName = path.basename(executablePath);
|
|
106
|
-
logger.log(`Running: ${executableName} ${args.join(
|
|
106
|
+
logger.log(`Running: ${executableName} ${args.join(' ')}`);
|
|
107
107
|
try {
|
|
108
108
|
return execa.execa(executablePath, args, {
|
|
109
109
|
...config,
|
|
110
|
-
stdio:
|
|
110
|
+
stdio: 'inherit',
|
|
111
111
|
});
|
|
112
112
|
} catch (error) {
|
|
113
113
|
this.#throwError(error);
|
|
@@ -119,12 +119,14 @@ export class DigigovCommand extends commander.Command {
|
|
|
119
119
|
* @returns {never}
|
|
120
120
|
*/
|
|
121
121
|
#throwError(error) {
|
|
122
|
-
if (typeof error ===
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
if (typeof error === 'string') logger.error(error);
|
|
123
|
+
if (
|
|
124
|
+
typeof error === 'object' &&
|
|
125
|
+
error &&
|
|
126
|
+
'exitCode' in error &&
|
|
127
|
+
typeof error.exitCode === 'number'
|
|
128
|
+
) {
|
|
129
|
+
process.exit(error.exitCode);
|
|
128
130
|
}
|
|
129
131
|
process.exit(1);
|
|
130
132
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
1
|
+
export * from './command.js';
|
|
2
|
+
export * from './project-utils.cjs';
|
|
3
|
+
export * from './logger.js';
|
package/lib/logger.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import chalk from
|
|
1
|
+
import chalk from 'chalk';
|
|
2
2
|
|
|
3
3
|
const args = process.argv.slice(2);
|
|
4
|
-
const IS_DEBUG = args.includes(
|
|
4
|
+
const IS_DEBUG = args.includes('--debug') || args.includes('-d');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @param {any[]} data - The data to log
|
|
8
8
|
*/
|
|
9
9
|
function log(...data) {
|
|
10
|
-
console.log(chalk.bgWhite.black(
|
|
10
|
+
console.log(chalk.bgWhite.black(' LOG '), ...data);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @param {any[]} data - The data to log
|
|
15
15
|
*/
|
|
16
16
|
function info(...data) {
|
|
17
|
-
console.log(chalk.bgBlue(
|
|
17
|
+
console.log(chalk.bgBlue(' INFO '), chalk.blue(...data));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @param {any[]} data - The data to log
|
|
22
22
|
*/
|
|
23
23
|
function error(...data) {
|
|
24
|
-
console.error(chalk.bgRed(
|
|
24
|
+
console.error(chalk.bgRed(' ERROR '), chalk.red(...data));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @param {any[]} data - The data to log
|
|
29
29
|
*/
|
|
30
30
|
function success(...data) {
|
|
31
|
-
console.log(
|
|
31
|
+
console.log('✅ ', chalk.green(...data));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* @param {any[]} data - The data to log
|
|
36
36
|
*/
|
|
37
37
|
function warn(...data) {
|
|
38
|
-
console.log(chalk.bgYellow.black(
|
|
38
|
+
console.log(chalk.bgYellow.black(' WARN '), chalk.yellow(...data));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -43,21 +43,21 @@ function warn(...data) {
|
|
|
43
43
|
*/
|
|
44
44
|
function debug(...data) {
|
|
45
45
|
if (IS_DEBUG)
|
|
46
|
-
console.log(chalk.dim.bgWhite.black(
|
|
46
|
+
console.log(chalk.dim.bgWhite.black(' DEBUG '), chalk.dim(...data));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* @param {string} label - The label for the timer
|
|
51
51
|
*/
|
|
52
52
|
function time(label) {
|
|
53
|
-
console.time(chalk.bgMagenta(
|
|
53
|
+
console.time(chalk.bgMagenta('⏱️ ' + label));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* @param {string} label - The label for the timer
|
|
58
58
|
*/
|
|
59
59
|
function timeEnd(label) {
|
|
60
|
-
console.timeEnd(chalk.bgMagenta(
|
|
60
|
+
console.timeEnd(chalk.bgMagenta('⏱️ ' + label));
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export const logger = {
|
package/lib/project-utils.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const fs = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const merge = require(
|
|
4
|
-
const rushLib = require(
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const merge = require('deepmerge');
|
|
4
|
+
const rushLib = require('@microsoft/rush-lib');
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Resolve the project configuration from the nearest package.json
|
|
@@ -10,21 +10,21 @@ const rushLib = require("@microsoft/rush-lib");
|
|
|
10
10
|
*/
|
|
11
11
|
function resolveProject(dir) {
|
|
12
12
|
const pkg = findPackageJson(dir);
|
|
13
|
-
if (!pkg) throw new Error(
|
|
13
|
+
if (!pkg) throw new Error('No package.json found'); // TODO: reconsider this
|
|
14
14
|
const root = path.dirname(pkg);
|
|
15
15
|
let externalLockFile = false;
|
|
16
16
|
if (
|
|
17
|
-
fs.existsSync(path.join(root,
|
|
18
|
-
fs.existsSync(path.join(root,
|
|
17
|
+
fs.existsSync(path.join(root, 'yarn.lock')) ||
|
|
18
|
+
fs.existsSync(path.join(root, 'package-lock.json'))
|
|
19
19
|
) {
|
|
20
20
|
externalLockFile = true;
|
|
21
21
|
}
|
|
22
|
-
let distDir =
|
|
23
|
-
let src =
|
|
22
|
+
let distDir = 'dist';
|
|
23
|
+
let src = 'src';
|
|
24
24
|
|
|
25
25
|
if (!fs.existsSync(path.join(root, src))) {
|
|
26
|
-
src =
|
|
27
|
-
distDir =
|
|
26
|
+
src = '.';
|
|
27
|
+
distDir = '.';
|
|
28
28
|
}
|
|
29
29
|
// project type heuristics
|
|
30
30
|
let isLib = false;
|
|
@@ -33,18 +33,18 @@ function resolveProject(dir) {
|
|
|
33
33
|
let isDocs = false;
|
|
34
34
|
|
|
35
35
|
if (
|
|
36
|
-
fs.existsSync(path.join(root,
|
|
37
|
-
fs.existsSync(path.join(root,
|
|
36
|
+
fs.existsSync(path.join(root, 'next.config.js')) ||
|
|
37
|
+
fs.existsSync(path.join(root, 'pages'))
|
|
38
38
|
) {
|
|
39
39
|
isApp = true;
|
|
40
40
|
}
|
|
41
41
|
if (
|
|
42
|
-
fs.existsSync(path.join(root,
|
|
43
|
-
fs.existsSync(path.join(root,
|
|
42
|
+
fs.existsSync(path.join(root, 'docusaurus.config.js')) &&
|
|
43
|
+
fs.existsSync(path.join(root, 'docs'))
|
|
44
44
|
) {
|
|
45
45
|
isDocs = true;
|
|
46
46
|
}
|
|
47
|
-
if (fs.existsSync(path.join(root,
|
|
47
|
+
if (fs.existsSync(path.join(root, 'src')) && !isApp) {
|
|
48
48
|
isLib = true;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -61,9 +61,9 @@ function resolveProject(dir) {
|
|
|
61
61
|
const isNodeLib = !isLib && !isApp && !isWorkspace && !isDocs;
|
|
62
62
|
|
|
63
63
|
/** @type {string | null} */
|
|
64
|
-
let ignore = path.resolve(root,
|
|
64
|
+
let ignore = path.resolve(root, '.gitignore');
|
|
65
65
|
if (!fs.existsSync(ignore) && workspace.root) {
|
|
66
|
-
ignore = path.resolve(workspace.root,
|
|
66
|
+
ignore = path.resolve(workspace.root, '.gitignore');
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
if (!fs.existsSync(ignore)) {
|
|
@@ -71,11 +71,11 @@ function resolveProject(dir) {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
let digigov = {};
|
|
74
|
-
if (fs.existsSync(path.join(root,
|
|
75
|
-
digigov = fs.readJSONSync(path.join(root,
|
|
74
|
+
if (fs.existsSync(path.join(root, 'digigovrc.json'))) {
|
|
75
|
+
digigov = fs.readJSONSync(path.join(root, 'digigovrc.json'));
|
|
76
76
|
}
|
|
77
|
-
if (fs.existsSync(path.join(root,
|
|
78
|
-
digigov = require(path.join(root,
|
|
77
|
+
if (fs.existsSync(path.join(root, 'digigovrc.js'))) {
|
|
78
|
+
digigov = require(path.join(root, 'digigovrc.js'));
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const packageJS = fs.readJSONSync(pkg);
|
|
@@ -83,7 +83,7 @@ function resolveProject(dir) {
|
|
|
83
83
|
const devDependencies = packageJS.devDependencies || {};
|
|
84
84
|
const dependencies = packageJS.dependencies || {};
|
|
85
85
|
const peerDependencies = packageJS.peerDependencies || {};
|
|
86
|
-
const isTs = Object.keys(devDependencies).includes(
|
|
86
|
+
const isTs = Object.keys(devDependencies).includes('typescript');
|
|
87
87
|
const allDependencies = {
|
|
88
88
|
...dependencies,
|
|
89
89
|
...devDependencies,
|
|
@@ -121,16 +121,16 @@ function findPackageJson(startDir = process.cwd()) {
|
|
|
121
121
|
|
|
122
122
|
if (!fs.existsSync(currentDir) || !fs.lstatSync(currentDir).isDirectory()) {
|
|
123
123
|
throw new Error(
|
|
124
|
-
`The start directory "${startDir}" is not a valid directory
|
|
124
|
+
`The start directory "${startDir}" is not a valid directory.`
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
while (true) {
|
|
129
|
-
const packageJsonPath = path.join(currentDir,
|
|
129
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
130
130
|
if (fs.existsSync(packageJsonPath)) {
|
|
131
131
|
return packageJsonPath;
|
|
132
132
|
}
|
|
133
|
-
const parentDir = path.resolve(currentDir,
|
|
133
|
+
const parentDir = path.resolve(currentDir, '..');
|
|
134
134
|
if (parentDir === currentDir) return undefined;
|
|
135
135
|
|
|
136
136
|
currentDir = parentDir;
|
|
@@ -146,18 +146,18 @@ function localRequire(file) {
|
|
|
146
146
|
const project = resolveProject();
|
|
147
147
|
const filePath = path.join(project.root, file);
|
|
148
148
|
if (!fs.existsSync(filePath)) return {};
|
|
149
|
-
if (file.endsWith(
|
|
149
|
+
if (file.endsWith('.json')) return fs.readJSONSync(filePath);
|
|
150
150
|
else return require(filePath);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
function makeConfig(file, cfg = {}) {
|
|
154
154
|
let hook = {};
|
|
155
|
-
if (file && typeof file !==
|
|
155
|
+
if (file && typeof file !== 'string') {
|
|
156
156
|
hook = file;
|
|
157
|
-
} else if (typeof file ===
|
|
157
|
+
} else if (typeof file === 'string') {
|
|
158
158
|
hook = localRequire(file);
|
|
159
159
|
}
|
|
160
|
-
if (typeof hook ===
|
|
160
|
+
if (typeof hook === 'function') {
|
|
161
161
|
return hook(cfg);
|
|
162
162
|
}
|
|
163
163
|
if (hook) {
|
|
@@ -175,7 +175,7 @@ function resolveWorkspace() {
|
|
|
175
175
|
const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation(
|
|
176
176
|
{
|
|
177
177
|
startingFolder: process.cwd(),
|
|
178
|
-
}
|
|
178
|
+
}
|
|
179
179
|
);
|
|
180
180
|
return rushConfiguration;
|
|
181
181
|
} catch {
|
|
@@ -197,7 +197,7 @@ function resolveLocalPackages(dependencies) {
|
|
|
197
197
|
for (const project of rushProjects) {
|
|
198
198
|
if (dependencies.includes(project.packageName)) {
|
|
199
199
|
localPackages[project.packageName] = resolveProject(
|
|
200
|
-
project.projectFolder
|
|
200
|
+
project.projectFolder
|
|
201
201
|
);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
@@ -217,7 +217,7 @@ function aliases(absolute = false) {
|
|
|
217
217
|
/** @type {{ [key: string]: string }} */
|
|
218
218
|
const aliases = {};
|
|
219
219
|
const project = resolveProject();
|
|
220
|
-
const depKeys = [
|
|
220
|
+
const depKeys = ['dependencies', 'peerDependencies', 'devDependencies'];
|
|
221
221
|
const root = project.root;
|
|
222
222
|
/** @type {string[]} */
|
|
223
223
|
let deps = [];
|
|
@@ -231,7 +231,7 @@ function aliases(absolute = false) {
|
|
|
231
231
|
project &&
|
|
232
232
|
deps.includes(project.name) &&
|
|
233
233
|
project.package.devDependencies &&
|
|
234
|
-
project.package.devDependencies[
|
|
234
|
+
project.package.devDependencies['@digigov/cli-build'] &&
|
|
235
235
|
project.isWorkspace
|
|
236
236
|
) {
|
|
237
237
|
const projectSrc = path.join(project.root, project.src);
|
package/load-commands.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import path from
|
|
3
|
-
import { fileURLToPath } from
|
|
4
|
-
import { logger } from
|
|
5
|
-
import {
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { logger } from './lib/index.js';
|
|
5
|
+
import { findPackageJson } from './lib/index.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @param {DigigovCommand} program - The program to load commands into
|
|
8
|
+
* @param {import('./lib/index.js').DigigovCommand} program - The program to load commands into
|
|
9
9
|
*/
|
|
10
10
|
export async function loadCommands(program) {
|
|
11
11
|
const packageFilePath = findPackageJson();
|
|
12
12
|
if (!packageFilePath) {
|
|
13
|
-
logger.warn(
|
|
13
|
+
logger.warn('No package.json found');
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
const packageFile = fs.readFileSync(packageFilePath);
|
|
@@ -24,9 +24,9 @@ export async function loadCommands(program) {
|
|
|
24
24
|
try {
|
|
25
25
|
const modulePath = path.resolve(
|
|
26
26
|
process.cwd(),
|
|
27
|
-
|
|
27
|
+
'node_modules',
|
|
28
28
|
commandPackage,
|
|
29
|
-
|
|
29
|
+
'index.js'
|
|
30
30
|
);
|
|
31
31
|
const realPath = fs.realpathSync(modulePath);
|
|
32
32
|
const command = await import(
|
|
@@ -40,10 +40,9 @@ export async function loadCommands(program) {
|
|
|
40
40
|
error.message.endsWith("undefined (reading '_name')")
|
|
41
41
|
)
|
|
42
42
|
logger.warn(
|
|
43
|
-
errorPrefix
|
|
44
|
-
"| Did you forget to default export the command?",
|
|
43
|
+
`${errorPrefix}\nDid you forget to default export the command?`
|
|
45
44
|
);
|
|
46
|
-
else logger.warn(errorPrefix
|
|
45
|
+
else logger.warn(`${errorPrefix}\n${error}`);
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
48
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/cli",
|
|
3
3
|
"description": "CLI for Digigov apps and libs with plugin support",
|
|
4
|
-
"version": "2.0.0-
|
|
4
|
+
"version": "2.0.0-e20fed09",
|
|
5
5
|
"author": "GRNET Devs <devs@lists.grnet.gr>",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"fs-extra": "11.2.0",
|
|
12
12
|
"deepmerge": "4.3.1",
|
|
13
13
|
"execa": "8.0.1",
|
|
14
|
-
"@microsoft/rush-lib": "5.
|
|
14
|
+
"@microsoft/rush-lib": "5.151.0",
|
|
15
15
|
"commander": "12.1.0",
|
|
16
16
|
"chalk": "4.1.0"
|
|
17
17
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"publint": "0.1.8",
|
|
20
20
|
"typescript": "5.6.2",
|
|
21
21
|
"@types/fs-extra": "11.0.4",
|
|
22
|
-
"@types/node": "
|
|
22
|
+
"@types/node": "20.17.24"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=18"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"publint": "publint",
|
|
44
|
-
"lint": "echo 'no lint needed (yet)'"
|
|
44
|
+
"lint": "echo 'no lint needed (yet)'",
|
|
45
|
+
"typecheck": "tsc"
|
|
45
46
|
}
|
|
46
47
|
}
|