@digigov/cli 1.1.2-daaf7bdf → 2.0.0-0c4be34e

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/README.md CHANGED
@@ -19,7 +19,7 @@ $ npm install -g @digigov/cli
19
19
  $ digigov COMMAND
20
20
  running command...
21
21
  $ digigov (-v|--version|version)
22
- @digigov/cli/1.1.2-daaf7bdf linux-x64 node-v18.20.4
22
+ @digigov/cli/1.1.1 linux-x64 node-v18.20.3
23
23
  $ digigov --help [COMMAND]
24
24
  USAGE
25
25
  $ digigov COMMAND
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { DigigovCommand } from "./lib/command.js";
4
+ import { loadCommands } from "./load-commands.js";
5
+
6
+ const program = new DigigovCommand("digigov", import.meta.url);
7
+
8
+ await loadCommands(program);
9
+
10
+ await program.parseAsync(process.argv);
package/lib/command.js ADDED
@@ -0,0 +1,130 @@
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
+
9
+ /**
10
+ * A class that extends the Commander Command class with additional
11
+ * functionality.
12
+ *
13
+ * @extends commander.Command
14
+ */
15
+ export class DigigovCommand extends commander.Command {
16
+ /**
17
+ * The id of the command used for logging
18
+ * @private
19
+ * @type {string}
20
+ */
21
+ #id;
22
+ /** @type {string | null} */
23
+ context;
24
+
25
+ /**
26
+ * @constructor
27
+ * @param {string} name - The name of the command
28
+ * @param {string} [importMetaUrl] - The import.meta.url of the command
29
+ */
30
+ constructor(name, importMetaUrl) {
31
+ super(name);
32
+ this.#id = name;
33
+ this.context = importMetaUrl
34
+ ? path.dirname(fileURLToPath(importMetaUrl))
35
+ : null;
36
+
37
+ this.option("-d, --debug", "display debug information");
38
+
39
+ this.configureOutput({
40
+ writeErr: (str) => logger.error(str.replace(/^error: /i, "")),
41
+ });
42
+
43
+ if (this.context) {
44
+ if (this.context.endsWith("dist")) {
45
+ this.context = path.dirname(this.context);
46
+ }
47
+ const pkgPath = findPackageJson(this.context);
48
+ if (!pkgPath)
49
+ this.#throwError(`No package.json found in ${this.context}`);
50
+ const pkg = fs.readJSONSync(pkgPath);
51
+ this.description(pkg.description).version(pkg.version);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Display error message and exit
57
+ * @override
58
+ * @param {string} message - The message to log
59
+ * @param {commander.ErrorOptions} [errorOptions] - The error options
60
+ */
61
+ error(message, errorOptions) {
62
+ logger.error(message);
63
+ process.exit(errorOptions?.exitCode);
64
+ }
65
+
66
+ /**
67
+ * @override
68
+ * @param {(...args: any[]) => void | Promise<void>} fn - The function to run
69
+ * @returns {DigigovCommand} `this` command for chaining
70
+ */
71
+ action(fn) {
72
+ return super.action(async (...args) => {
73
+ try {
74
+ logger.time(`"${this.#id}" execution time`);
75
+ await fn(...args);
76
+ logger.timeEnd(`"${this.#id}" execution time`);
77
+ } catch (error) {
78
+ this.#throwError(error);
79
+ }
80
+ });
81
+ }
82
+
83
+ /**
84
+ * Executes a script with the given arguments
85
+ *
86
+ * @param {string} script - The script to run
87
+ * @param {string[]} args - The arguments to pass to the script
88
+ * @param {execa.Options} [config] - The configuration for the script
89
+ */
90
+ exec(script, args, config) {
91
+ const __dirname =
92
+ this.context ?? path.dirname(fileURLToPath(import.meta.url));
93
+ const binLocation = [process.cwd(), __dirname].find((location) => {
94
+ return fs.existsSync(path.join(location, "node_modules", ".bin", script));
95
+ });
96
+ if (!binLocation || !fs.existsSync(binLocation)) {
97
+ this.#throwError(`Executable ${script} not installed`);
98
+ }
99
+ const executablePath = path.join(
100
+ binLocation,
101
+ "node_modules",
102
+ ".bin",
103
+ script,
104
+ );
105
+ const executableName = path.basename(executablePath);
106
+ logger.log(`Running: ${executableName} ${args.join(" ")}`);
107
+ try {
108
+ return execa.execa(executablePath, args, {
109
+ ...config,
110
+ stdio: "inherit",
111
+ });
112
+ } catch (error) {
113
+ this.#throwError(error.message);
114
+ }
115
+ }
116
+
117
+ /**
118
+ * @private
119
+ */
120
+ #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
+ }
127
+ }
128
+ process.exit(1);
129
+ }
130
+ }
package/lib/index.js CHANGED
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.run = void 0;
4
- var command_1 = require("@oclif/command");
5
- Object.defineProperty(exports, "run", { enumerable: true, get: function () { return command_1.run; } });
1
+ export * from "./command.js";
2
+ export * from "./project-utils.cjs";
3
+ export * from "./logger.js";
package/lib/logger.js ADDED
@@ -0,0 +1,53 @@
1
+ import chalk from "chalk";
2
+
3
+ const args = process.argv.slice(2);
4
+ const IS_DEBUG = args.includes("--debug") || args.includes("-d");
5
+
6
+ function log(...data) {
7
+ console.log(chalk.bgWhite.black(" LOG "), ...data);
8
+ }
9
+
10
+ function info(...data) {
11
+ console.log(chalk.bgBlue(" INFO "), chalk.blue(...data));
12
+ }
13
+ function error(...data) {
14
+ console.error(chalk.bgRed(" ERROR "), chalk.red(...data));
15
+ }
16
+
17
+ function success(...data) {
18
+ console.log("✅ ", chalk.green(...data));
19
+ }
20
+
21
+ function warn(...data) {
22
+ console.log(chalk.bgYellow.black(" WARN "), chalk.yellow(...data));
23
+ }
24
+
25
+ function debug(...data) {
26
+ if (IS_DEBUG)
27
+ console.log(chalk.dim.bgWhite.black(" DEBUG "), chalk.dim(...data));
28
+ }
29
+
30
+ /**
31
+ * @param {string} label - The label for the timer
32
+ */
33
+ function time(label) {
34
+ console.time(chalk.bgMagenta("⏱️ " + label));
35
+ }
36
+
37
+ /**
38
+ * @param {string} label - The label for the timer
39
+ */
40
+ function timeEnd(label) {
41
+ console.timeEnd(chalk.bgMagenta("⏱️ " + label));
42
+ }
43
+
44
+ export const logger = {
45
+ log,
46
+ info,
47
+ error,
48
+ success,
49
+ warn,
50
+ debug,
51
+ time,
52
+ timeEnd,
53
+ };
@@ -1,19 +1,27 @@
1
- const pkgUp = require("pkg-up");
2
1
  const fs = require("fs-extra");
3
2
  const path = require("path");
4
3
  const merge = require("deepmerge");
4
+ const rushLib = require("@microsoft/rush-lib");
5
5
 
6
+ /**
7
+ * Resolve the project configuration from the nearest package.json
8
+ *
9
+ * @param {string} [dir] - The directory to start package searching from
10
+ */
6
11
  function resolveProject(dir) {
7
- const pkg = pkgUp.sync({ cwd: dir || process.cwd() });
12
+ const pkg = findPackageJson(dir);
13
+ if (!pkg) throw new Error("No package.json found"); // TODO: reconsider this
8
14
  const root = path.dirname(pkg);
9
15
  let externalLockFile = false;
10
- if (fs.existsSync(path.join(root, "yarn.lock")) ||
11
- fs.existsSync(path.join(root, "package-lock.json"))) {
16
+ if (
17
+ fs.existsSync(path.join(root, "yarn.lock")) ||
18
+ fs.existsSync(path.join(root, "package-lock.json"))
19
+ ) {
12
20
  externalLockFile = true;
13
21
  }
14
22
  let distDir = "dist";
15
23
  let src = "src";
16
- let workspace = {};
24
+
17
25
  if (!fs.existsSync(path.join(root, src))) {
18
26
  src = ".";
19
27
  distDir = ".";
@@ -24,12 +32,16 @@ function resolveProject(dir) {
24
32
  let isApp = false;
25
33
  let isDocs = false;
26
34
 
27
- if (fs.existsSync(path.join(root, "next.config.js")) ||
28
- fs.existsSync(path.join(root, "pages"))) {
35
+ if (
36
+ fs.existsSync(path.join(root, "next.config.js")) ||
37
+ fs.existsSync(path.join(root, "pages"))
38
+ ) {
29
39
  isApp = true;
30
40
  }
31
- if (fs.existsSync(path.join(root, "docusaurus.config.js")) &&
32
- fs.existsSync(path.join(root, "docs"))) {
41
+ if (
42
+ fs.existsSync(path.join(root, "docusaurus.config.js")) &&
43
+ fs.existsSync(path.join(root, "docs"))
44
+ ) {
33
45
  isDocs = true;
34
46
  }
35
47
  if (fs.existsSync(path.join(root, "src")) && !isApp) {
@@ -37,16 +49,18 @@ function resolveProject(dir) {
37
49
  }
38
50
 
39
51
  const rush = resolveWorkspace();
40
- if (rush) {
41
- isWorkspace = true;
42
- workspace = {
43
- config: rush,
44
- root: rush.rushJsonFolder,
45
- };
46
- }
52
+ if (rush) isWorkspace = true;
53
+
54
+ const workspace = rush
55
+ ? {
56
+ config: rush,
57
+ root: rush.rushJsonFolder,
58
+ }
59
+ : {};
47
60
 
48
61
  const isNodeLib = !isLib && !isApp && !isWorkspace && !isDocs;
49
62
 
63
+ /** @type {string | null} */
50
64
  let ignore = path.resolve(root, ".gitignore");
51
65
  if (!fs.existsSync(ignore) && workspace.root) {
52
66
  ignore = path.resolve(workspace.root, ".gitignore");
@@ -58,13 +72,13 @@ function resolveProject(dir) {
58
72
 
59
73
  let digigov = {};
60
74
  if (fs.existsSync(path.join(root, "digigovrc.json"))) {
61
- digigov = require(path.join(root, "digigovrc.json"));
75
+ digigov = fs.readJSONSync(path.join(root, "digigovrc.json"));
62
76
  }
63
77
  if (fs.existsSync(path.join(root, "digigovrc.js"))) {
64
78
  digigov = require(path.join(root, "digigovrc.js"));
65
79
  }
66
80
 
67
- const packageJS = require(pkg);
81
+ const packageJS = fs.readJSONSync(pkg);
68
82
 
69
83
  const devDependencies = packageJS.devDependencies || {};
70
84
  const dependencies = packageJS.dependencies || {};
@@ -95,20 +109,52 @@ function resolveProject(dir) {
95
109
  externalLockFile,
96
110
  };
97
111
  }
98
- function localRequire(file, dflt) {
112
+
113
+ /**
114
+ * Recursively find the nearest package.json by walking up the directory tree.
115
+ *
116
+ * @param {string} startDir - The directory to start searching from
117
+ * @returns {string | undefined} package.json path, or undefined if not found.
118
+ */
119
+ function findPackageJson(startDir = process.cwd()) {
120
+ let currentDir = startDir;
121
+
122
+ if (!fs.existsSync(currentDir) || !fs.lstatSync(currentDir).isDirectory()) {
123
+ throw new Error(
124
+ `The start directory "${startDir}" is not a valid directory.`,
125
+ );
126
+ }
127
+
128
+ while (true) {
129
+ const packageJsonPath = path.join(currentDir, "package.json");
130
+ if (fs.existsSync(packageJsonPath)) {
131
+ return packageJsonPath;
132
+ }
133
+ const parentDir = path.resolve(currentDir, "..");
134
+ if (parentDir === currentDir) return undefined;
135
+
136
+ currentDir = parentDir;
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Require a file relative to the project root
142
+ *
143
+ * @param {string} file - The file to require
144
+ */
145
+ function localRequire(file) {
99
146
  const project = resolveProject();
100
147
  const filePath = path.join(project.root, file);
101
- if (fs.existsSync(filePath)) {
102
- return require(filePath);
103
- }
104
- return dflt;
148
+ if (!fs.existsSync(filePath)) return {};
149
+ if (file.endsWith(".json")) return fs.readJSONSync(filePath);
150
+ else return require(filePath);
105
151
  }
106
- function makeConfig(file, cfg) {
152
+ function makeConfig(file, cfg = {}) {
107
153
  let hook = {};
108
154
  if (file && typeof file !== "string") {
109
155
  hook = file;
110
156
  } else if (typeof file === "string") {
111
- hook = localRequire(file, {});
157
+ hook = localRequire(file);
112
158
  }
113
159
  if (typeof hook === "function") {
114
160
  return hook(cfg);
@@ -117,56 +163,71 @@ function makeConfig(file, cfg) {
117
163
  return merge(cfg, hook);
118
164
  }
119
165
  }
120
- function resolveWorkspace(dir) {
166
+
167
+ /**
168
+ * Resolve the project's Rush workspace configuration
169
+ *
170
+ * @returns {rushLib.RushConfiguration | null} - The Rush configuration or null if not found
171
+ */
172
+ function resolveWorkspace() {
121
173
  try {
122
- const rushLib = require("@microsoft/rush-lib");
123
174
  const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation(
124
175
  {
125
176
  startingFolder: process.cwd(),
126
- }
177
+ },
127
178
  );
128
179
  return rushConfiguration;
129
180
  } catch (err) {
130
- // console.log(err);
181
+ console.error(err);
131
182
  }
183
+ return null;
132
184
  }
133
- /*
134
- Identify if project running the command from, is lerna-enabled. If so, return
135
- lerna registered projects metadata.
136
- */
137
- function resolveLocalPackages(dir, dependencies) {
138
- const packages = {};
139
- const rush = resolveWorkspace(dir);
185
+
186
+ /**
187
+ * @param {string[]} dependencies - The dependencies to resolve
188
+ * @returns {{ [key: string]: ReturnType<typeof resolveProject> }} - The local packages
189
+ */
190
+ function resolveLocalPackages(dependencies) {
191
+ const rush = resolveWorkspace();
192
+ let localPackages = {};
140
193
  if (rush) {
141
- rush.projects.forEach((p) => {
142
- if (dependencies.includes(p.packageName)) {
143
- packages[p.packageName] = resolveProject(p.projectFolder);
194
+ const rushProjects = rush.projects;
195
+ for (const project of rushProjects) {
196
+ if (dependencies.includes(project.packageName)) {
197
+ localPackages[project.packageName] = resolveProject(
198
+ project.projectFolder,
199
+ );
144
200
  }
145
- });
146
- return packages;
201
+ }
147
202
  }
148
- return {};
203
+ return localPackages;
149
204
  }
150
205
  /**
151
206
  * Map `resolveLocalPackages` result to a babel/jest compatible package aliases
152
207
  * object. Use only packages which are declared as a dependency for the current
153
208
  * project
209
+ *
210
+ * @param {boolean} absolute=false - Whether to return absolute paths
211
+ * @returns {{ [key: string]: string }} - The aliases object
212
+ *
154
213
  */
155
- function aliases(dir, absolute = false) {
214
+ function aliases(absolute = false) {
156
215
  const aliases = {};
157
- const project = resolveProject(dir);
216
+ const project = resolveProject();
158
217
  const depKeys = ["dependencies", "peerDependencies", "devDependencies"];
159
218
  const root = project.root;
160
219
  const deps = depKeys.reduce((deps, key) => {
161
220
  return deps.concat(Object.keys(project.package[key] || {}));
162
221
  }, []);
163
- const packages = resolveLocalPackages(project.root, deps);
222
+ const packages = resolveLocalPackages(deps);
164
223
  Object.keys(packages).forEach((key) => {
165
224
  const project = packages[key];
166
- if (deps.includes(project.name) &&
225
+ if (
226
+ deps.includes(project.name) &&
167
227
  project.package.devDependencies &&
168
228
  project.package.devDependencies["@digigov/cli-build"] &&
169
- project.isWorkspace) {
229
+ project.isWorkspace
230
+ ) {
170
231
  const projectSrc = path.join(project.root, project.src);
171
232
  if (absolute) {
172
233
  aliases[project.name] = path.resolve(root, projectSrc);
@@ -182,36 +243,12 @@ function aliases(dir, absolute = false) {
182
243
  }
183
244
  return aliases;
184
245
  }
185
- const extractCommandArgs = (config, commandArgs) => {
186
- const vars = Object.values(args).reduce((values, v) => {
187
- return {
188
- ...values,
189
- ...(v.default && { [v.var]: v.default }),
190
- };
191
- }, {});
192
-
193
- const exclude = [];
194
- commandArgs.forEach((arg, idx) => {
195
- if (exclude.includes(idx)) {
196
- return;
197
- }
198
- if (args[arg]) {
199
- if (args[arg].type) {
200
- vars[args[arg].var] = args[arg].type(commandArgs[idx + 1]);
201
- exclude.push(idx + 1);
202
- } else {
203
- vars[args[arg].var] = true;
204
- }
205
- }
206
- });
207
- return vars;
208
- };
209
246
 
210
247
  module.exports = {
211
- makeConfig,
212
- resolveLocalPackages,
213
- aliases,
214
248
  resolveProject,
249
+ findPackageJson,
215
250
  resolveWorkspace,
216
- extractCommandArgs,
217
- };
251
+ resolveLocalPackages,
252
+ aliases,
253
+ makeConfig,
254
+ };
@@ -0,0 +1,49 @@
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";
6
+
7
+ /**
8
+ * @param {DigigovCommand} program - The program to load commands into
9
+ */
10
+ export async function loadCommands(program) {
11
+ const packageFilePath = findPackageJson();
12
+ if (!packageFilePath) {
13
+ logger.warn("No package.json found");
14
+ return;
15
+ }
16
+ const packageFile = fs.readFileSync(packageFilePath);
17
+
18
+ const { dependencies, devDependencies } = JSON.parse(packageFile.toString());
19
+ const commandPackages = Object.keys({
20
+ ...dependencies,
21
+ ...devDependencies,
22
+ }).filter((p) => p.match(/@digigov\/cli-.*?/));
23
+ for (const commandPackage of commandPackages) {
24
+ try {
25
+ const modulePath = path.resolve(
26
+ process.cwd(),
27
+ "node_modules",
28
+ commandPackage,
29
+ "index.js",
30
+ );
31
+ const realPath = fs.realpathSync(modulePath);
32
+ const command = await import(
33
+ fileURLToPath(new URL(`file://${realPath}`))
34
+ );
35
+ program.addCommand(command.default);
36
+ } catch (error) {
37
+ const errorPrefix = `Could not load command package: ${commandPackage}`;
38
+ if (
39
+ error instanceof Error &&
40
+ error.message.endsWith("undefined (reading '_name')")
41
+ )
42
+ logger.warn(
43
+ errorPrefix,
44
+ "| Did you forget to default export the command?",
45
+ );
46
+ else logger.warn(errorPrefix, error);
47
+ }
48
+ }
49
+ }
package/package.json CHANGED
@@ -1,74 +1,42 @@
1
1
  {
2
2
  "name": "@digigov/cli",
3
3
  "description": "CLI for Digigov apps and libs with plugin support",
4
- "version": "1.1.2-daaf7bdf",
4
+ "version": "2.0.0-0c4be34e",
5
5
  "author": "GRNET Devs <devs@lists.grnet.gr>",
6
+ "type": "module",
6
7
  "bin": {
7
- "digigov": "./bin/run"
8
+ "digigov": "./index.js"
8
9
  },
9
10
  "dependencies": {
10
- "@oclif/command": "1.8.0",
11
- "@oclif/config": "1",
12
- "@oclif/plugin-help": "3",
13
- "tslib": "2.6.2",
14
- "cli-ux": "5.5.1",
15
- "@oclif/errors": "1.3.4",
16
- "pkg-up": "3.1.0",
17
11
  "fs-extra": "11.2.0",
18
- "deepmerge": "4.2.2",
19
- "execa": "5.0.0",
20
- "rimraf": "3.0.2",
21
- "glob": "7.1.6",
22
- "publint": "0.1.8"
12
+ "deepmerge": "4.3.1",
13
+ "execa": "8.0.1",
14
+ "@microsoft/rush-lib": "5.133.4",
15
+ "commander": "12.1.0",
16
+ "chalk": "4.1.0"
23
17
  },
24
18
  "devDependencies": {
25
- "@oclif/dev-cli": "1",
26
- "@oclif/test": "1",
27
- "@types/chai": "4",
28
- "@types/mocha": "5",
29
- "@types/node": "18.19.0",
30
- "chai": "4",
31
- "globby": "11.0.0",
32
- "mocha": "5",
33
- "nyc": "14",
34
- "ts-node": "10.9.2",
35
- "typescript": "5.6.2",
36
- "publint": "0.1.8",
37
- "@microsoft/rush-lib": "5.133.4"
19
+ "publint": "0.1.8"
38
20
  },
39
21
  "engines": {
40
- "node": ">=12.13.0"
22
+ "node": ">=18"
41
23
  },
42
24
  "files": [
43
- "/bin",
25
+ "index.js",
26
+ "load-commands.js",
44
27
  "/lib",
45
- "/lib.js",
46
- "/resolveProject.js",
47
- "/npm-shrinkwrap.json",
48
- "/oclif.manifest.json"
49
- ],
50
- "homepage": "https://github.com/tooling/cli",
51
- "keywords": [
52
- "oclif"
28
+ "tsconfig.cli.json"
53
29
  ],
54
- "main": "lib/index.js",
55
- "oclif": {
56
- "commands": "./lib/commands",
57
- "bin": "digigov",
58
- "plugins": [
59
- "@oclif/plugin-help"
60
- ],
61
- "hooks": {
62
- "init": "./lib/hooks/init/addcommand"
30
+ "main": "./index.js",
31
+ "exports": {
32
+ ".": "./index.js",
33
+ "./lib": {
34
+ "require": "./lib/project-utils.cjs",
35
+ "default": "./lib/index.js"
63
36
  }
64
37
  },
65
- "types": "lib/index.d.ts",
66
38
  "scripts": {
67
39
  "publint": "publint",
68
- "lint": "echo 'no lint needed (yet)'",
69
- "prepublish": "tsc",
70
- "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
71
- "version": "oclif-dev readme && git add README.md",
72
- "build": "tsc"
40
+ "lint": "echo 'no lint needed (yet)'"
73
41
  }
74
42
  }
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "NodeNext",
4
+ "moduleResolution": "NodeNext",
5
+ "sourceMap": true,
6
+ "allowJs": true,
7
+ "declaration": true,
8
+ "strict": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "skipLibCheck": true,
11
+ "resolveJsonModule": true,
12
+ "esModuleInterop": true,
13
+ "forceConsistentCasingInFileNames": true,
14
+ "noImplicitReturns": true,
15
+ "noImplicitThis": true,
16
+ "noImplicitAny": true,
17
+ "strictNullChecks": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "strictFunctionTypes": true,
21
+ "strictBindCallApply": true,
22
+ "strictPropertyInitialization": true,
23
+ "alwaysStrict": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedIndexedAccess": true,
26
+ "noPropertyAccessFromIndexSignature": true,
27
+ "skipDefaultLibCheck": true
28
+ }
29
+ }
package/bin/run DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('@oclif/command').run()
4
- .then(require('@oclif/command/flush'))
5
- .catch(require('@oclif/errors/handle'))
package/bin/run.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\run" %*
@@ -1,9 +0,0 @@
1
- import { Command } from '@oclif/command';
2
- export default class Hello extends Command {
3
- static description: string;
4
- static examples: string[];
5
- static args: {
6
- name: string;
7
- }[];
8
- run(): Promise<void>;
9
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- class Hello extends command_1.Command {
5
- async run() {
6
- var _a;
7
- const { args, flags } = this.parse(Hello);
8
- const name = (_a = flags.name) !== null && _a !== void 0 ? _a : 'world';
9
- this.log(`hello ${name} from ./src/commands/hello.ts`);
10
- if (args.file && flags.force) {
11
- this.log(`you input --force and --file: ${args.file}`);
12
- }
13
- }
14
- }
15
- Hello.description = 'describe the command here';
16
- Hello.examples = [
17
- `$ digigov hello
18
- hello world from ./src/hello.ts!
19
- `,
20
- ];
21
- Hello.args = [{ name: 'file' }];
22
- exports.default = Hello;
@@ -1,2 +0,0 @@
1
- declare const hook: (this: any) => Promise<void>;
2
- export default hook;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const Config = require("@oclif/config");
5
- const pkgUp = require("pkg-up");
6
- const fs = require('fs');
7
- const packageFile = pkgUp.sync();
8
- const { dependencies, devDependencies } = JSON.parse(fs.readFileSync(packageFile).toString());
9
- const plugins = Object.keys(Object.assign(Object.assign({}, dependencies), devDependencies)).filter(p => p.match(/@digigov\/cli-.*?/));
10
- class DynamicPlugin extends Config.Plugin {
11
- get hooks() { return {}; }
12
- get topics() {
13
- return [];
14
- }
15
- get commandIDs() {
16
- return plugins.map(p => p.match(/@digigov\/cli-(.*?)$/)[1]);
17
- }
18
- get commands() {
19
- return plugins.map(plugin => {
20
- return require(plugin);
21
- });
22
- }
23
- }
24
- const hook = async function () {
25
- this.config.plugins.push(new DynamicPlugin(this.config));
26
- };
27
- exports.default = hook;
package/lib/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { run } from '@oclif/command';
package/lib.js DELETED
@@ -1,45 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const execa = require("execa");
4
- const glob = require("glob");
5
- const { Command } = require("@oclif/command");
6
- const {
7
- makeConfig,
8
- resolveLocalPackages,
9
- aliases,
10
- resolveProject,
11
- resolveWorkspace,
12
- extractCommandArgs
13
- } = require("./resolveProject");
14
-
15
-
16
- class DigigovCommand extends Command {
17
- async exec(script, args, config) {
18
- const binLocation = [process.cwd(), this.dirname, __dirname].find(
19
- (location) => {
20
- return fs.existsSync(
21
- path.join(location, "node_modules", ".bin", script),
22
- );
23
- },
24
- );
25
- if (!binLocation || !fs.existsSync(binLocation)) {
26
- throw new Error(`Executable ${script} not installed`);
27
- }
28
- let executable = path.join(binLocation, "node_modules", ".bin", script);
29
- console.log("Running ", executable, ...args);
30
- try {
31
- return await execa(executable, args, { ...config, stdio: "inherit" });
32
- } catch (err) {
33
- process.exit(err.exitCode);
34
- }
35
- }
36
- }
37
- module.exports = {
38
- makeConfig,
39
- resolveLocalPackages,
40
- aliases,
41
- DigigovCommand,
42
- resolveProject,
43
- resolveWorkspace,
44
- extractCommandArgs,
45
- };
@@ -1 +0,0 @@
1
- {"version":"1.1.2-daaf7bdf","commands":{"hello":{"id":"hello","description":"describe the command here","pluginName":"@digigov/cli","pluginType":"core","aliases":[],"examples":["$ digigov hello\nhello world from ./src/hello.ts!\n"],"flags":{},"args":[{"name":"file"}]}}}