@magda/scripts 2.3.3 → 3.0.0-alpha.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.
Files changed (64) hide show
  1. package/acs-cmd/acs-cmd-admin-set.js +6 -5
  2. package/acs-cmd/acs-cmd-admin-unset.js +6 -5
  3. package/acs-cmd/acs-cmd-admin.js +3 -2
  4. package/acs-cmd/acs-cmd-assign-permission.js +7 -6
  5. package/acs-cmd/acs-cmd-assign-role.js +7 -6
  6. package/acs-cmd/acs-cmd-assign.js +3 -2
  7. package/acs-cmd/acs-cmd-create-operation.js +8 -7
  8. package/acs-cmd/acs-cmd-create-permission.js +6 -6
  9. package/acs-cmd/acs-cmd-create.js +3 -2
  10. package/acs-cmd/acs-cmd-jwt.js +6 -6
  11. package/acs-cmd/acs-cmd-list-permissions.js +5 -4
  12. package/acs-cmd/acs-cmd-list-resources.js +5 -4
  13. package/acs-cmd/acs-cmd-list-roles.js +5 -4
  14. package/acs-cmd/acs-cmd-list-users.js +5 -4
  15. package/acs-cmd/acs-cmd-list.js +3 -2
  16. package/acs-cmd/acs-cmd-remove-permission.js +7 -6
  17. package/acs-cmd/acs-cmd-remove-role.js +7 -6
  18. package/acs-cmd/acs-cmd-remove.js +3 -2
  19. package/acs-cmd/index.js +3 -2
  20. package/acs-cmd/utils.js +2 -5
  21. package/build-changed.js +8 -7
  22. package/check-release-version.js +6 -4
  23. package/create-api-key.js +7 -6
  24. package/create-docker-context-for-node-component.js +20 -15
  25. package/create-jwt-token.js +5 -5
  26. package/create-region-synonym-file.js +12 -27
  27. package/create-secrets/askQuestions.js +14 -20
  28. package/create-secrets/index.js +7 -6
  29. package/create-secrets/k8sExecution.js +9 -9
  30. package/create-secrets/preloadConfig.js +4 -4
  31. package/create-secrets/prompts/inquirer-fuzzy-path.js +9 -9
  32. package/create-secrets/prompts/list-with-transformer.js +5 -5
  33. package/create-secrets/pwgen.js +2 -2
  34. package/db/getDBConfig.js +1 -3
  35. package/db/getDBPool.js +3 -3
  36. package/docker-util.js +11 -11
  37. package/findLastModifiedFile.js +2 -2
  38. package/generate-api-documentation.js +7 -6
  39. package/generate-registry-typescript.js +5 -4
  40. package/getAllPackages.js +6 -2
  41. package/isScalaPackage.js +3 -3
  42. package/isTypeScriptPackage.js +4 -3
  43. package/loaders/remove-hashbag-loader.js +2 -2
  44. package/org-tree/getNodeIdFromNameOrId.js +2 -2
  45. package/org-tree/getUserIdFromNameOrId.js +2 -2
  46. package/org-tree/index.js +3 -2
  47. package/org-tree/org-tree-assign.js +9 -9
  48. package/org-tree/org-tree-create.js +6 -6
  49. package/org-tree/org-tree-delete.js +7 -7
  50. package/org-tree/org-tree-insert.js +8 -8
  51. package/org-tree/org-tree-move.js +8 -8
  52. package/org-tree/org-tree-unassign.js +6 -8
  53. package/org-tree/org-tree-view.js +5 -5
  54. package/package.json +18 -13
  55. package/retag-and-push.js +3 -8
  56. package/run-in-submodules.js +11 -9
  57. package/run-typescript-in-nodemon.js +6 -9
  58. package/set-scss-vars.js +1 -0
  59. package/tools/swagger-codegen-cli.jar +0 -0
  60. package/tools/swagger-codegen-cli.md +1 -1
  61. package/update-helm-chart-version.js +1 -0
  62. package/create-all-tsconfigs.js +0 -51
  63. package/create-pod-and-forward.js +0 -108
  64. package/generate-connector-jobs.js +0 -192
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const path = require("path");
4
- const childProcess = require("child_process");
5
- const glob = require("glob");
6
- const _ = require("lodash");
7
- const os = require("os");
3
+ import { require } from "@magda/esm-utils";
4
+ import path from "node:path";
5
+ import childProcess from "child_process";
6
+ import glob from "glob";
7
+ import _ from "lodash";
8
+ import os from "node:os";
9
+ import yargs from "yargs";
8
10
 
9
11
  const lernaJson = require("../lerna.json");
10
12
 
11
- const argv = require("yargs").option("filters", {
13
+ const argv = yargs.option("filters", {
12
14
  alias: "f",
13
15
  type: "string",
14
16
  describe:
@@ -30,8 +32,8 @@ const filters = argFilters.map((string) => {
30
32
  });
31
33
 
32
34
  const jsPackages = _(lernaJson.packages)
33
- .map((package) => package + "/package.json")
34
- .flatMap((package) => glob.sync(package))
35
+ .map((pkg) => pkg + "/package.json")
36
+ .flatMap((pkg) => glob.sync(pkg))
35
37
  .map((packagePath) => {
36
38
  const packageJson = require(path.resolve(packagePath));
37
39
  return packageJson;
@@ -50,7 +52,7 @@ const jsPackages = _(lernaJson.packages)
50
52
  const result = childProcess.spawnSync(
51
53
  "lerna",
52
54
  [
53
- ...jsPackages.map((package) => "--scope " + package),
55
+ ...jsPackages.map((pkg) => "--scope " + pkg),
54
56
  "--stream",
55
57
  "--concurrency",
56
58
  os.cpus().length,
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
- const fse = require("fs-extra");
3
- const nodemon = require("nodemon");
4
- const path = require("path");
5
- const process = require("process");
2
+ import { require } from "@magda/esm-utils";
3
+ import fse from "fs-extra";
4
+ import nodemon from "nodemon";
5
+ import path from "path";
6
+ import process from "process";
6
7
 
7
8
  const script = process.argv[2];
8
9
  if (!script) {
@@ -47,11 +48,7 @@ nodemon({
47
48
  args: process.argv.slice(3),
48
49
  watch: watchPaths,
49
50
  execMap: {
50
- ts:
51
- "node " +
52
- require.resolve("ts-node/dist/bin.js") +
53
- " -r " +
54
- require.resolve("tsconfig-paths/register")
51
+ ts: "node " + " --import tsx/esm "
55
52
  }
56
53
  });
57
54
 
package/set-scss-vars.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { require } from "@magda/esm-utils";
2
3
  const chalk = require("chalk");
3
4
  const path = require("path");
4
5
  const fse = require("fs-extra");
Binary file
@@ -12,7 +12,7 @@ yarn run generateSwaggerApis
12
12
  To build:
13
13
 
14
14
  ```
15
- git checkout -b magda git@github.com:TerriaJS/swagger-codegen.git
15
+ git checkout -b magda git@github.com:magda-io/swagger-codegen.git
16
16
  cd swagger-codegen
17
17
  mvn clean package
18
18
  ```
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { require } from "@magda/esm-utils";
2
3
  const path = require("path");
3
4
  const recursive = require("recursive-readdir");
4
5
  const fse = require("fs-extra");
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
- const fse = require("fs-extra");
3
- const path = require("path");
4
- const getAllPackages = require("./getAllPackages");
5
- const isTypeScriptPackage = require("./isTypeScriptPackage");
6
-
7
- getAllPackages().forEach(function (packagePath) {
8
- const packageJson = require(path.resolve(packagePath, "package.json"));
9
- const isTypeScript = isTypeScriptPackage(packagePath, packageJson);
10
- if (!isTypeScript) {
11
- return;
12
- }
13
-
14
- console.log(packagePath);
15
-
16
- const tsConfigBuild = {
17
- extends: "../tsconfig-global.json",
18
- compilerOptions: {
19
- declaration: true,
20
- outDir: "dist",
21
- baseUrl: "."
22
- },
23
- include: ["src"]
24
- };
25
-
26
- fse.writeFileSync(
27
- path.resolve(packagePath, "tsconfig-build.json"),
28
- JSON.stringify(tsConfigBuild, undefined, " ")
29
- );
30
-
31
- const paths = {};
32
- const dependencies = packageJson.dependencies || {};
33
- Object.keys(dependencies)
34
- .filter((key) => key.indexOf("@magda") === 0)
35
- .forEach(function (key) {
36
- paths[key + "/dist/*"] = ["./node_modules/" + key + "/src/*"];
37
- });
38
-
39
- const tsConfig = {
40
- extends: "./tsconfig-build.json",
41
- compilerOptions: {
42
- baseUrl: ".",
43
- paths: paths
44
- }
45
- };
46
-
47
- fse.writeFileSync(
48
- path.resolve(packagePath, "tsconfig.json"),
49
- JSON.stringify(tsConfig, undefined, " ")
50
- );
51
- });
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env node
2
- const childProcess = require("child_process");
3
- const process = require("process");
4
- const yargs = require("yargs");
5
-
6
- const argv = yargs
7
- .options({
8
- configuration: {
9
- description: "The Kubernetes configuration to apply.",
10
- type: "string",
11
- demand: true
12
- },
13
- selector: {
14
- description:
15
- "The selector to use to find the pod to forward into, such as `service=combined-db`.",
16
- type: "string",
17
- demand: true
18
- },
19
- port: {
20
- description: "The pod port to which to forward.",
21
- type: "number",
22
- demand: true
23
- },
24
- localPort: {
25
- description:
26
- "The local port to forward into the pod. If not specified, the local port is the same as the pod port.",
27
- type: "number"
28
- }
29
- })
30
- .help().argv;
31
-
32
- const dockerEnvProcess = childProcess.execSync(
33
- "minikube docker-env --shell bash",
34
- { encoding: "utf8" }
35
- );
36
- const dockerEnv = dockerEnvProcess
37
- .split("\n")
38
- .filter((line) => line.indexOf("export ") === 0)
39
- .reduce(function (env, line) {
40
- const match = /^export (\w+)="(.*)"$/.exec(line);
41
- if (match) {
42
- env[match[1]] = match[2];
43
- }
44
- return env;
45
- }, {});
46
-
47
- const env = Object.assign({}, process.env, dockerEnv);
48
-
49
- childProcess.execSync("kubectl config use-context minikube", {
50
- stdio: "inherit",
51
- env: env
52
- });
53
- childProcess.execSync("yarn run docker-build-local", {
54
- stdio: "inherit",
55
- env: env
56
- });
57
- childProcess.execSync(`kubectl apply -f ${argv.configuration}`, {
58
- stdio: "inherit",
59
- env: env
60
- });
61
-
62
- console.log("Waiting for the pod to start...");
63
-
64
- let status;
65
- const endTime = Date.now() + 90 * 1000;
66
- do {
67
- status = childProcess
68
- .execSync(
69
- `kubectl get pods -l ${argv.selector} -o=custom-columns=NAME:.status.phase --no-headers`,
70
- { encoding: "utf8", env: env }
71
- )
72
- .trim();
73
- } while (status !== "Running" && Date.now() < endTime);
74
-
75
- if (status !== "Running") {
76
- console.log(
77
- `Pod failed to start within 90 seconds. The last status was: ${status}.`
78
- );
79
- process.exit(1);
80
- }
81
-
82
- console.log("Pod is running!");
83
-
84
- const podName = childProcess
85
- .execSync(
86
- `kubectl get pods -l ${argv.selector} -o=custom-columns=NAME:.metadata.name --no-headers`,
87
- { encoding: "utf8", env: env }
88
- )
89
- .trim();
90
- const portSpec =
91
- argv.localPort !== undefined
92
- ? `${argv.localPort}:${argv.port}`
93
- : argv.port.toString();
94
- const portForwardProcess = childProcess.spawn(
95
- "kubectl",
96
- ["port-forward", podName, portSpec],
97
- {
98
- stdio: "inherit",
99
- env: env,
100
- shell: true
101
- }
102
- );
103
-
104
- const logsProcess = childProcess.spawn("kubectl", ["logs", "-f", podName], {
105
- stdio: "inherit",
106
- env: env,
107
- shell: true
108
- });
@@ -1,192 +0,0 @@
1
- #!/usr/bin/env node
2
- const fs = require("fs-extra");
3
- const klawSync = require("klaw-sync");
4
- const path = require("path");
5
- const yargs = require("yargs");
6
-
7
- const argv = yargs
8
- .config()
9
- .help()
10
- .option("in", {
11
- describe:
12
- "The directory containing the connector configuration JSON files.",
13
- type: "string",
14
- demandOption: true
15
- })
16
- .option("out", {
17
- describe:
18
- "The directory in which to write the generated Kubernetes config files.",
19
- type: "string",
20
- demandOption: true
21
- })
22
- .option("local", {
23
- describe:
24
- "true to generate config files for a Minikube deployment with the registry on localhost:5000 and the version at latest. Otherwise, the default registry and the version in the connector's package.json are used.",
25
- type: "boolean",
26
- default: false
27
- })
28
- .option("prod", {
29
- describe:
30
- "Whether to use values appropriate for a dev cluster or a prod cluster",
31
- type: "boolean",
32
- default: false
33
- })
34
- .option("imageVersion", {
35
- describe:
36
- "Overrides the version of the image that will be given to the jobs. Defaults to 'latest' if 'local' is specified, otherwise it will match the version of this package.",
37
- type: "string"
38
- })
39
- .option("imagePrefix", {
40
- describe:
41
- "Overrides the prefix for the image that will be given to the jobs. Defaults to 'localhost:5000/data61' if 'local' is specified, otherwise data61/",
42
- type: "string"
43
- }).argv;
44
-
45
- fs.ensureDirSync(argv.out);
46
-
47
- const files = klawSync(argv.in, { nodir: true });
48
- files.forEach(function (connectorConfigFile) {
49
- const configFile = JSON.parse(
50
- fs.readFileSync(connectorConfigFile.path, "utf8")
51
- );
52
- const connectorPackageName = configFile.type;
53
- const connectorPackagePath = path.join("..", connectorPackageName);
54
- const connectorPackageJson = JSON.parse(
55
- fs.readFileSync(path.join(connectorPackagePath, "package.json"), "utf8")
56
- );
57
-
58
- function getImageVersion() {
59
- if (argv.imageVersion) {
60
- return argv.imageVersion;
61
- } else if (argv.local) {
62
- return "latest";
63
- } else {
64
- return connectorPackageJson.version;
65
- }
66
- }
67
-
68
- function getImagePrefix() {
69
- if (argv.imagePrefix) {
70
- return argv.imagePrefix;
71
- } else if (argv.local) {
72
- return "localhost:5000/data61/";
73
- } else {
74
- return "data61/";
75
- }
76
- }
77
-
78
- const image = getImagePrefix() + configFile.type + ":" + getImageVersion();
79
- const prod = argv.prod;
80
-
81
- const basename = path.basename(connectorConfigFile.path, ".json");
82
-
83
- const jobSpec = {
84
- template: {
85
- metadata: {
86
- name: "connector-" + basename
87
- },
88
- spec: {
89
- containers: [
90
- {
91
- name: "connector-" + basename,
92
- image: image,
93
- command: [
94
- "node",
95
- "/usr/src/app/component/dist/index.js",
96
- "--config",
97
- "/etc/config/connector.json",
98
- "--registryUrl",
99
- "http://registry-api/v0"
100
- ],
101
- imagePullPolicy: prod ? "IfNotPresent" : "Always",
102
- resources: {
103
- requests: {
104
- cpu: prod ? "500m" : "500m",
105
- memory: prod ? "500Mi" : "500Mi"
106
- },
107
- limits: {
108
- cpu: prod ? "1000m" : "500m"
109
- }
110
- },
111
- volumeMounts: [
112
- {
113
- mountPath: "/etc/config",
114
- name: "config"
115
- }
116
- ],
117
- env: [
118
- {
119
- name: "USER_ID",
120
- value: "00000000-0000-4000-8000-000000000000"
121
- },
122
- {
123
- name: "JWT_SECRET",
124
- valueFrom: {
125
- secretKeyRef: {
126
- name: "auth-secrets",
127
- key: "jwt-secret"
128
- }
129
- }
130
- }
131
- ]
132
- }
133
- ],
134
- restartPolicy: "OnFailure",
135
- volumes: [
136
- {
137
- name: "config",
138
- configMap: {
139
- name: "connector-config",
140
- items: [
141
- {
142
- key: path.basename(
143
- connectorConfigFile.path
144
- ),
145
- path: "connector.json"
146
- }
147
- ]
148
- }
149
- }
150
- ]
151
- }
152
- }
153
- };
154
-
155
- const job = {
156
- apiVersion: "batch/v1",
157
- kind: "Job",
158
- metadata: {
159
- name: "connector-" + basename
160
- },
161
- spec: jobSpec
162
- };
163
-
164
- fs.writeFileSync(
165
- path.join(argv.out, "connector-" + basename + ".json"),
166
- JSON.stringify(job, undefined, " "),
167
- "utf8"
168
- );
169
-
170
- const cron = {
171
- apiVersion: "batch/v1",
172
- kind: "CronJob",
173
- metadata: {
174
- name: "connector-" + basename
175
- },
176
- spec: {
177
- schedule:
178
- configFile.schedule && prod
179
- ? configFile.schedule
180
- : "0 14 * * 6", // 12am Sydney time on Sunday
181
- jobTemplate: {
182
- spec: jobSpec
183
- }
184
- }
185
- };
186
-
187
- fs.writeFileSync(
188
- path.join(argv.out, "connector-" + basename + "-cron.json"),
189
- JSON.stringify(cron, undefined, " "),
190
- "utf8"
191
- );
192
- });