@digigov/cli 2.0.0-2177f152 → 2.0.0-264e5fff

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 CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { DigigovCommand } from "./lib/command.js";
4
- import { loadCommands } from "./load-commands.js";
3
+ import { DigigovCommand } from './lib/command.js';
4
+ import { loadCommands } from './load-commands.js';
5
5
 
6
- const program = new DigigovCommand("digigov", import.meta.url);
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 "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";
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
@@ -15,7 +15,6 @@ import { findPackageJson } from "./project-utils.cjs";
15
15
  export class DigigovCommand extends commander.Command {
16
16
  /**
17
17
  * The id of the command used for logging
18
- * @private
19
18
  * @type {string}
20
19
  */
21
20
  #id;
@@ -34,14 +33,14 @@ export class DigigovCommand extends commander.Command {
34
33
  ? path.dirname(fileURLToPath(importMetaUrl))
35
34
  : null;
36
35
 
37
- this.option("-d, --debug", "display debug information");
36
+ this.option('-d, --debug', 'display debug information');
38
37
 
39
38
  this.configureOutput({
40
- writeErr: (str) => logger.error(str.replace(/^error: /i, "")),
39
+ writeErr: (str) => logger.error(str.replace(/^error: /i, '')),
41
40
  });
42
41
 
43
42
  if (this.context) {
44
- if (this.context.endsWith("dist")) {
43
+ if (this.context.endsWith('dist')) {
45
44
  this.context = path.dirname(this.context);
46
45
  }
47
46
  const pkgPath = findPackageJson(this.context);
@@ -57,6 +56,7 @@ export class DigigovCommand extends commander.Command {
57
56
  * @override
58
57
  * @param {string} message - The message to log
59
58
  * @param {commander.ErrorOptions} [errorOptions] - The error options
59
+ * @returns {never}
60
60
  */
61
61
  error(message, errorOptions) {
62
62
  logger.error(message);
@@ -66,7 +66,7 @@ export class DigigovCommand extends commander.Command {
66
66
  /**
67
67
  * @override
68
68
  * @param {(...args: any[]) => void | Promise<void>} fn - The function to run
69
- * @returns {DigigovCommand} `this` command for chaining
69
+ * @returns {this} `this` command for chaining
70
70
  */
71
71
  action(fn) {
72
72
  return super.action(async (...args) => {
@@ -91,39 +91,42 @@ 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, "node_modules", ".bin", script));
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
- "node_modules",
102
- ".bin",
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: "inherit",
110
+ stdio: 'inherit',
111
111
  });
112
112
  } catch (error) {
113
- this.#throwError(error.message);
113
+ this.#throwError(error);
114
114
  }
115
115
  }
116
116
 
117
117
  /**
118
- * @private
118
+ * @param {unknown} error - The error to log
119
+ * @returns {never}
119
120
  */
120
121
  #throwError(error) {
121
- if (typeof error === "string") logger.error(error);
122
- if (typeof error === "object" && error) {
123
- logger.error("stack" in error ? error.stack : error);
124
- if ("exitCode" in error && typeof error.exitCode === "number") {
125
- process.exit(error.exitCode);
126
- }
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);
127
130
  }
128
131
  process.exit(1);
129
132
  }
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./command.js";
2
- export * from "./project-utils.cjs";
3
- export * from "./logger.js";
1
+ export * from './command.js';
2
+ export * from './project-utils.cjs';
3
+ export * from './logger.js';
package/lib/logger.js CHANGED
@@ -1,44 +1,63 @@
1
- import chalk from "chalk";
1
+ import chalk from 'chalk';
2
2
 
3
3
  const args = process.argv.slice(2);
4
- const IS_DEBUG = args.includes("--debug") || args.includes("-d");
4
+ const IS_DEBUG = args.includes('--debug') || args.includes('-d');
5
5
 
6
+ /**
7
+ * @param {any[]} data - The data to log
8
+ */
6
9
  function log(...data) {
7
- console.log(chalk.bgWhite.black(" LOG "), ...data);
10
+ console.log(chalk.bgWhite.black(' LOG '), ...data);
8
11
  }
9
12
 
13
+ /**
14
+ * @param {any[]} data - The data to log
15
+ */
10
16
  function info(...data) {
11
- console.log(chalk.bgBlue(" INFO "), chalk.blue(...data));
17
+ console.log(chalk.bgBlue(' INFO '), chalk.blue(...data));
12
18
  }
19
+
20
+ /**
21
+ * @param {any[]} data - The data to log
22
+ */
13
23
  function error(...data) {
14
- console.error(chalk.bgRed(" ERROR "), chalk.red(...data));
24
+ console.error(chalk.bgRed(' ERROR '), chalk.red(...data));
15
25
  }
16
26
 
27
+ /**
28
+ * @param {any[]} data - The data to log
29
+ */
17
30
  function success(...data) {
18
- console.log("", chalk.green(...data));
31
+ console.log('', chalk.green(...data));
19
32
  }
20
33
 
34
+ /**
35
+ * @param {any[]} data - The data to log
36
+ */
21
37
  function warn(...data) {
22
- console.log(chalk.bgYellow.black(" WARN "), chalk.yellow(...data));
38
+ console.log(chalk.bgYellow.black(' WARN '), chalk.yellow(...data));
23
39
  }
24
40
 
41
+ /**
42
+ * @param {any[]} data - The data to log
43
+ */
25
44
  function debug(...data) {
26
45
  if (IS_DEBUG)
27
- console.log(chalk.dim.bgWhite.black(" DEBUG "), chalk.dim(...data));
46
+ console.log(chalk.dim.bgWhite.black(' DEBUG '), chalk.dim(...data));
28
47
  }
29
48
 
30
49
  /**
31
50
  * @param {string} label - The label for the timer
32
51
  */
33
52
  function time(label) {
34
- console.time(chalk.bgMagenta("⏱️ " + label));
53
+ console.time(chalk.bgMagenta('⏱️ ' + label));
35
54
  }
36
55
 
37
56
  /**
38
57
  * @param {string} label - The label for the timer
39
58
  */
40
59
  function timeEnd(label) {
41
- console.timeEnd(chalk.bgMagenta("⏱️ " + label));
60
+ console.timeEnd(chalk.bgMagenta('⏱️ ' + label));
42
61
  }
43
62
 
44
63
  export const logger = {
@@ -1,7 +1,7 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const merge = require("deepmerge");
4
- const rushLib = require("@microsoft/rush-lib");
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("No package.json found"); // TODO: reconsider this
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, "yarn.lock")) ||
18
- fs.existsSync(path.join(root, "package-lock.json"))
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 = "dist";
23
- let src = "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, "next.config.js")) ||
37
- fs.existsSync(path.join(root, "pages"))
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, "docusaurus.config.js")) &&
43
- fs.existsSync(path.join(root, "docs"))
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, "src")) && !isApp) {
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, ".gitignore");
64
+ let ignore = path.resolve(root, '.gitignore');
65
65
  if (!fs.existsSync(ignore) && workspace.root) {
66
- ignore = path.resolve(workspace.root, ".gitignore");
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, "digigovrc.json"))) {
75
- digigov = fs.readJSONSync(path.join(root, "digigovrc.json"));
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, "digigovrc.js"))) {
78
- digigov = require(path.join(root, "digigovrc.js"));
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("typescript");
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, "package.json");
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,17 +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(".json")) return fs.readJSONSync(filePath);
149
+ if (file.endsWith('.json')) return fs.readJSONSync(filePath);
150
150
  else return require(filePath);
151
151
  }
152
+
152
153
  function makeConfig(file, cfg = {}) {
153
154
  let hook = {};
154
- if (file && typeof file !== "string") {
155
+ if (file && typeof file !== 'string') {
155
156
  hook = file;
156
- } else if (typeof file === "string") {
157
+ } else if (typeof file === 'string') {
157
158
  hook = localRequire(file);
158
159
  }
159
- if (typeof hook === "function") {
160
+ if (typeof hook === 'function') {
160
161
  return hook(cfg);
161
162
  }
162
163
  if (hook) {
@@ -174,11 +175,11 @@ function resolveWorkspace() {
174
175
  const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation(
175
176
  {
176
177
  startingFolder: process.cwd(),
177
- },
178
+ }
178
179
  );
179
180
  return rushConfiguration;
180
- } catch (err) {
181
- console.error(err);
181
+ } catch {
182
+ // No rush config, ignore error
182
183
  }
183
184
  return null;
184
185
  }
@@ -189,13 +190,14 @@ function resolveWorkspace() {
189
190
  */
190
191
  function resolveLocalPackages(dependencies) {
191
192
  const rush = resolveWorkspace();
193
+ /** @type {{ [key: string]: ReturnType<typeof resolveProject> }} */
192
194
  let localPackages = {};
193
195
  if (rush) {
194
196
  const rushProjects = rush.projects;
195
197
  for (const project of rushProjects) {
196
198
  if (dependencies.includes(project.packageName)) {
197
199
  localPackages[project.packageName] = resolveProject(
198
- project.projectFolder,
200
+ project.projectFolder
199
201
  );
200
202
  }
201
203
  }
@@ -212,20 +214,24 @@ function resolveLocalPackages(dependencies) {
212
214
  *
213
215
  */
214
216
  function aliases(absolute = false) {
217
+ /** @type {{ [key: string]: string }} */
215
218
  const aliases = {};
216
219
  const project = resolveProject();
217
- const depKeys = ["dependencies", "peerDependencies", "devDependencies"];
220
+ const depKeys = ['dependencies', 'peerDependencies', 'devDependencies'];
218
221
  const root = project.root;
219
- const deps = depKeys.reduce((deps, key) => {
220
- return deps.concat(Object.keys(project.package[key] || {}));
221
- }, []);
222
+ /** @type {string[]} */
223
+ let deps = [];
224
+ for (const key of depKeys) {
225
+ deps = deps.concat(Object.keys(project.package[key] || {}));
226
+ }
222
227
  const packages = resolveLocalPackages(deps);
223
228
  Object.keys(packages).forEach((key) => {
224
229
  const project = packages[key];
225
230
  if (
231
+ project &&
226
232
  deps.includes(project.name) &&
227
233
  project.package.devDependencies &&
228
- project.package.devDependencies["@digigov/cli-build"] &&
234
+ project.package.devDependencies['@digigov/cli-build'] &&
229
235
  project.isWorkspace
230
236
  ) {
231
237
  const projectSrc = path.join(project.root, project.src);
package/load-commands.js CHANGED
@@ -1,16 +1,16 @@
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 { DigigovCommand, findPackageJson } from "./lib/index.js";
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("No package.json found");
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
- "node_modules",
27
+ 'node_modules',
28
28
  commandPackage,
29
- "index.js",
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, error);
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-2177f152",
4
+ "version": "2.0.0-264e5fff",
5
5
  "author": "GRNET Devs <devs@lists.grnet.gr>",
6
6
  "type": "module",
7
7
  "bin": {
@@ -11,12 +11,15 @@
11
11
  "fs-extra": "11.2.0",
12
12
  "deepmerge": "4.3.1",
13
13
  "execa": "8.0.1",
14
- "@microsoft/rush-lib": "5.133.4",
14
+ "@microsoft/rush-lib": "5.151.0",
15
15
  "commander": "12.1.0",
16
16
  "chalk": "4.1.0"
17
17
  },
18
18
  "devDependencies": {
19
- "publint": "0.1.8"
19
+ "publint": "0.1.8",
20
+ "typescript": "5.6.2",
21
+ "@types/fs-extra": "11.0.4",
22
+ "@types/node": "20.17.24"
20
23
  },
21
24
  "engines": {
22
25
  "node": ">=18"
@@ -33,10 +36,12 @@
33
36
  "./lib": {
34
37
  "require": "./lib/project-utils.cjs",
35
38
  "default": "./lib/index.js"
36
- }
39
+ },
40
+ "./tsconfig.cli": "./tsconfig.cli.json"
37
41
  },
38
42
  "scripts": {
39
43
  "publint": "publint",
40
- "lint": "echo 'no lint needed (yet)'"
44
+ "lint": "echo 'no lint needed (yet)'",
45
+ "typecheck": "tsc"
41
46
  }
42
47
  }
package/tsconfig.cli.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "compilerOptions": {
3
3
  "module": "NodeNext",
4
4
  "moduleResolution": "NodeNext",
5
- "sourceMap": true,
5
+ "noEmit": true,
6
6
  "allowJs": true,
7
- "declaration": true,
7
+ "checkJs": true,
8
8
  "strict": true,
9
9
  "allowSyntheticDefaultImports": true,
10
10
  "skipLibCheck": true,
@@ -13,7 +13,7 @@
13
13
  "forceConsistentCasingInFileNames": true,
14
14
  "noImplicitReturns": true,
15
15
  "noImplicitThis": true,
16
- "noImplicitAny": true,
16
+ "noImplicitAny": false,
17
17
  "strictNullChecks": true,
18
18
  "noUnusedLocals": true,
19
19
  "noUnusedParameters": true,