@digigov/cli 1.1.1-rc.9 → 1.1.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/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.1-rc.9 darwin-arm64 node-v16.20.2
22
+ @digigov/cli/1.1.1 linux-x64 node-v18.20.3
23
23
  $ digigov --help [COMMAND]
24
24
  USAGE
25
25
  $ digigov COMMAND
File without changes
File without changes
File without changes
File without changes
package/lib/index.d.ts CHANGED
File without changes
package/lib/index.js CHANGED
File without changes
@@ -1 +1 @@
1
- {"version":"1.1.1-rc.9","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"}]}}}
1
+ {"version":"1.1.1","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"}]}}}
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": "1.1.1-rc.9",
4
+ "version": "1.1.1",
5
5
  "author": "GRNET Devs <devs@lists.grnet.gr>",
6
6
  "bin": {
7
7
  "digigov": "./bin/run"
@@ -43,6 +43,7 @@
43
43
  "/bin",
44
44
  "/lib",
45
45
  "/lib.js",
46
+ "/resolveProject.js",
46
47
  "/npm-shrinkwrap.json",
47
48
  "/oclif.manifest.json"
48
49
  ],
@@ -61,13 +62,15 @@
61
62
  "init": "./lib/hooks/init/addcommand"
62
63
  }
63
64
  },
64
- "types": "lib/index.d.ts",
65
65
  "scripts": {
66
66
  "publint": "publint",
67
67
  "lint": "echo 'no lint needed (yet)'",
68
+ "postpack": "rm -f oclif.manifest.json",
69
+ "prepack": "oclif-dev manifest && oclif-dev readme",
68
70
  "prepublish": "tsc",
69
71
  "test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
70
72
  "version": "oclif-dev readme && git add README.md",
71
73
  "build": "tsc"
72
- }
73
- }
74
+ },
75
+ "types": "lib/index.d.ts"
76
+ }
@@ -0,0 +1,217 @@
1
+ const pkgUp = require("pkg-up");
2
+ const fs = require("fs-extra");
3
+ const path = require("path");
4
+ const merge = require("deepmerge");
5
+
6
+ function resolveProject(dir) {
7
+ const pkg = pkgUp.sync({ cwd: dir || process.cwd() });
8
+ const root = path.dirname(pkg);
9
+ let externalLockFile = false;
10
+ if (fs.existsSync(path.join(root, "yarn.lock")) ||
11
+ fs.existsSync(path.join(root, "package-lock.json"))) {
12
+ externalLockFile = true;
13
+ }
14
+ let distDir = "dist";
15
+ let src = "src";
16
+ let workspace = {};
17
+ if (!fs.existsSync(path.join(root, src))) {
18
+ src = ".";
19
+ distDir = ".";
20
+ }
21
+ // project type heuristics
22
+ let isLib = false;
23
+ let isWorkspace = false;
24
+ let isApp = false;
25
+ let isDocs = false;
26
+
27
+ if (fs.existsSync(path.join(root, "next.config.js")) ||
28
+ fs.existsSync(path.join(root, "pages"))) {
29
+ isApp = true;
30
+ }
31
+ if (fs.existsSync(path.join(root, "docusaurus.config.js")) &&
32
+ fs.existsSync(path.join(root, "docs"))) {
33
+ isDocs = true;
34
+ }
35
+ if (fs.existsSync(path.join(root, "src")) && !isApp) {
36
+ isLib = true;
37
+ }
38
+
39
+ const rush = resolveWorkspace();
40
+ if (rush) {
41
+ isWorkspace = true;
42
+ workspace = {
43
+ config: rush,
44
+ root: rush.rushJsonFolder,
45
+ };
46
+ }
47
+
48
+ const isNodeLib = !isLib && !isApp && !isWorkspace && !isDocs;
49
+
50
+ let ignore = path.resolve(root, ".gitignore");
51
+ if (!fs.existsSync(ignore) && workspace.root) {
52
+ ignore = path.resolve(workspace.root, ".gitignore");
53
+ }
54
+
55
+ if (!fs.existsSync(ignore)) {
56
+ ignore = null;
57
+ }
58
+
59
+ let digigov = {};
60
+ if (fs.existsSync(path.join(root, "digigovrc.json"))) {
61
+ digigov = require(path.join(root, "digigovrc.json"));
62
+ }
63
+ if (fs.existsSync(path.join(root, "digigovrc.js"))) {
64
+ digigov = require(path.join(root, "digigovrc.js"));
65
+ }
66
+
67
+ const packageJS = require(pkg);
68
+
69
+ const devDependencies = packageJS.devDependencies || {};
70
+ const dependencies = packageJS.dependencies || {};
71
+ const peerDependencies = packageJS.peerDependencies || {};
72
+ const isTs = Object.keys(devDependencies).includes("typescript");
73
+ const allDependencies = {
74
+ ...dependencies,
75
+ ...devDependencies,
76
+ ...peerDependencies,
77
+ };
78
+ // hook applies extra properties based on project type
79
+ return {
80
+ name: packageJS.name,
81
+ isTs,
82
+ isLib,
83
+ isApp,
84
+ isDocs,
85
+ isWorkspace,
86
+ isNodeLib,
87
+ distDir,
88
+ package: packageJS,
89
+ dependencies: allDependencies,
90
+ src,
91
+ root,
92
+ workspace,
93
+ ignore,
94
+ digigov,
95
+ externalLockFile,
96
+ };
97
+ }
98
+ function localRequire(file, dflt) {
99
+ const project = resolveProject();
100
+ const filePath = path.join(project.root, file);
101
+ if (fs.existsSync(filePath)) {
102
+ return require(filePath);
103
+ }
104
+ return dflt;
105
+ }
106
+ function makeConfig(file, cfg) {
107
+ let hook = {};
108
+ if (file && typeof file !== "string") {
109
+ hook = file;
110
+ } else if (typeof file === "string") {
111
+ hook = localRequire(file, {});
112
+ }
113
+ if (typeof hook === "function") {
114
+ return hook(cfg);
115
+ }
116
+ if (hook) {
117
+ return merge(cfg, hook);
118
+ }
119
+ }
120
+ function resolveWorkspace(dir) {
121
+ try {
122
+ const rushLib = require("@microsoft/rush-lib");
123
+ const rushConfiguration = rushLib.RushConfiguration.loadFromDefaultLocation(
124
+ {
125
+ startingFolder: process.cwd(),
126
+ }
127
+ );
128
+ return rushConfiguration;
129
+ } catch (err) {
130
+ // console.log(err);
131
+ }
132
+ }
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);
140
+ if (rush) {
141
+ rush.projects.forEach((p) => {
142
+ if (dependencies.includes(p.packageName)) {
143
+ packages[p.packageName] = resolveProject(p.projectFolder);
144
+ }
145
+ });
146
+ return packages;
147
+ }
148
+ return {};
149
+ }
150
+ /**
151
+ * Map `resolveLocalPackages` result to a babel/jest compatible package aliases
152
+ * object. Use only packages which are declared as a dependency for the current
153
+ * project
154
+ */
155
+ function aliases(dir, absolute = false) {
156
+ const aliases = {};
157
+ const project = resolveProject(dir);
158
+ const depKeys = ["dependencies", "peerDependencies", "devDependencies"];
159
+ const root = project.root;
160
+ const deps = depKeys.reduce((deps, key) => {
161
+ return deps.concat(Object.keys(project.package[key] || {}));
162
+ }, []);
163
+ const packages = resolveLocalPackages(project.root, deps);
164
+ Object.keys(packages).forEach((key) => {
165
+ const project = packages[key];
166
+ if (deps.includes(project.name) &&
167
+ project.package.devDependencies &&
168
+ project.package.devDependencies["@digigov/cli-build"] &&
169
+ project.isWorkspace) {
170
+ const projectSrc = path.join(project.root, project.src);
171
+ if (absolute) {
172
+ aliases[project.name] = path.resolve(root, projectSrc);
173
+ } else {
174
+ aliases[project.name] = projectSrc;
175
+ }
176
+ }
177
+ });
178
+ if (absolute) {
179
+ aliases[project.name] = path.resolve(root, project.src);
180
+ } else {
181
+ aliases[project.name] = project.src;
182
+ }
183
+ return aliases;
184
+ }
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
+
210
+ module.exports = {
211
+ makeConfig,
212
+ resolveLocalPackages,
213
+ aliases,
214
+ resolveProject,
215
+ resolveWorkspace,
216
+ extractCommandArgs,
217
+ };