@learnpack/learnpack 5.0.297 → 5.0.300

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 (79) hide show
  1. package/README.md +409 -409
  2. package/lib/commands/audit.js +15 -15
  3. package/lib/commands/breakToken.js +19 -19
  4. package/lib/commands/clean.js +3 -3
  5. package/lib/commands/logout.js +3 -3
  6. package/lib/commands/serve.js +32 -11
  7. package/lib/creatorDist/assets/{index-D25zkBaN.js → index-DoYRptnk.js} +11875 -11992
  8. package/lib/creatorDist/index.html +1 -1
  9. package/lib/managers/config/index.js +77 -77
  10. package/lib/utils/creatorUtilities.js +14 -14
  11. package/lib/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
  12. package/lib/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
  13. package/lib/utils/templates/scorm/adlcp_rootv1p2.xsd +110 -110
  14. package/lib/utils/templates/scorm/config/index.html +209 -209
  15. package/lib/utils/templates/scorm/ims_xml.xsd +1 -1
  16. package/lib/utils/templates/scorm/imscp_rootv1p1p2.xsd +345 -345
  17. package/lib/utils/templates/scorm/imsmanifest.xml +38 -38
  18. package/lib/utils/templates/scorm/imsmd_rootv1p2p1.xsd +573 -573
  19. package/package.json +1 -1
  20. package/src/commands/audit.ts +487 -487
  21. package/src/commands/breakToken.ts +67 -67
  22. package/src/commands/clean.ts +30 -30
  23. package/src/commands/logout.ts +38 -38
  24. package/src/commands/serve.ts +49 -26
  25. package/src/commands/start.ts +333 -333
  26. package/src/commands/translate.ts +123 -123
  27. package/src/creator/README.md +54 -54
  28. package/src/creator/package-lock.json +6621 -6621
  29. package/src/creator/package.json +55 -55
  30. package/src/creator/src/App.tsx +569 -569
  31. package/src/creator/src/components/FileUploader.tsx +302 -302
  32. package/src/creator/src/components/Icon.tsx +18 -18
  33. package/src/creator/src/components/LessonItem.tsx +152 -152
  34. package/src/creator/src/components/Login.tsx +259 -259
  35. package/src/creator/src/components/syllabus/ContentIndex.tsx +323 -323
  36. package/src/creator/src/components/syllabus/SyllabusEditor.tsx +337 -337
  37. package/src/creator/src/i18n.ts +28 -28
  38. package/src/creator/src/locales/en.json +127 -127
  39. package/src/creator/src/locales/es.json +127 -127
  40. package/src/creator/src/utils/configTypes.ts +122 -122
  41. package/src/creator/src/utils/constants.ts +13 -13
  42. package/src/creator/src/utils/creatorUtils.ts +46 -46
  43. package/src/creator/src/utils/eventBus.ts +2 -2
  44. package/src/creator/src/utils/socket.ts +61 -61
  45. package/src/creator/src/utils/store.ts +222 -222
  46. package/src/creator/src/vite-env.d.ts +1 -1
  47. package/src/creator/vite.config.ts +13 -13
  48. package/src/creatorDist/assets/{index-D25zkBaN.js → index-DoYRptnk.js} +11875 -11992
  49. package/src/creatorDist/index.html +1 -1
  50. package/src/managers/config/defaults.ts +49 -49
  51. package/src/managers/config/exercise.ts +364 -364
  52. package/src/managers/config/index.ts +775 -775
  53. package/src/managers/file.ts +236 -236
  54. package/src/managers/server/routes.ts +554 -554
  55. package/src/managers/telemetry.ts +188 -188
  56. package/src/models/action.ts +13 -13
  57. package/src/models/config-manager.ts +28 -28
  58. package/src/models/config.ts +106 -106
  59. package/src/models/exercise-obj.ts +30 -30
  60. package/src/models/session.ts +39 -39
  61. package/src/models/socket.ts +61 -61
  62. package/src/models/status.ts +16 -16
  63. package/src/utils/BaseCommand.ts +56 -56
  64. package/src/utils/audit.ts +392 -392
  65. package/src/utils/checkNotInstalled.ts +267 -267
  66. package/src/utils/convertCreds.js +34 -34
  67. package/src/utils/creatorUtilities.ts +504 -504
  68. package/src/utils/export/README.md +178 -178
  69. package/src/utils/incrementVersion.js +74 -74
  70. package/src/utils/misc.ts +58 -58
  71. package/src/utils/sidebarGenerator.ts +195 -195
  72. package/src/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
  73. package/src/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
  74. package/src/utils/templates/scorm/adlcp_rootv1p2.xsd +110 -110
  75. package/src/utils/templates/scorm/config/index.html +209 -209
  76. package/src/utils/templates/scorm/ims_xml.xsd +1 -1
  77. package/src/utils/templates/scorm/imscp_rootv1p1p2.xsd +345 -345
  78. package/src/utils/templates/scorm/imsmanifest.xml +38 -38
  79. package/src/utils/templates/scorm/imsmd_rootv1p2p1.xsd +573 -573
@@ -1,267 +1,267 @@
1
- import { IExercise } from "../models/exercise-obj"
2
- import { promisify } from "util"
3
- import { exec as execCallback } from "child_process"
4
-
5
- const exec = promisify(execCallback)
6
-
7
- import { cli } from "cli-ux"
8
- import Console from "./console"
9
-
10
- type TNeededPlugins = {
11
- needed: string[]
12
- notInstalled: string[]
13
- }
14
- type TPackageManager = "npm" | "pip"
15
-
16
- export const checkNotInstalledPlugins = async (
17
- exercises: IExercise[],
18
- installedPlugins: string[],
19
- command: any
20
- ): Promise<TNeededPlugins> => {
21
- Console.info("Checking needed plugins...")
22
- const usefulExtensions = new Set(["py", "js", "jsx", "html"])
23
- const foundExtensions: string[] = []
24
- const testingExtensions: string[] = []
25
- const neededPlugins: string[] = []
26
- let someExerciseWithOnlyTestFile = false // I will suppose that there are not exercises with only readme and test files
27
-
28
- // See the extensions of the files that are not tests files
29
- for (const e of exercises) {
30
- const notReadmeFiles = e.files.filter(
31
- f => !f.name.toLowerCase().includes("readme")
32
- )
33
-
34
- if (!someExerciseWithOnlyTestFile && notReadmeFiles.length > 0) {
35
- someExerciseWithOnlyTestFile = notReadmeFiles.every(f => {
36
- return f.name.includes("test")
37
- })
38
-
39
- if (someExerciseWithOnlyTestFile) {
40
- Console.debug(
41
- "Some exercises have only test files, I will install the @learnpack/node plugin to run the tests."
42
- )
43
- }
44
- }
45
-
46
- for (const f of notReadmeFiles) {
47
- const ext = f.name.split(".").pop()
48
- if (!ext)
49
- continue
50
-
51
- if (f.name.includes("test")) {
52
- !testingExtensions.includes(ext) && testingExtensions.push(ext)
53
- continue
54
- }
55
-
56
- if (usefulExtensions.has(ext) && !foundExtensions.includes(ext)) {
57
- foundExtensions.push(ext)
58
- }
59
- }
60
- }
61
-
62
- Console.debug("foundExtensions", foundExtensions)
63
- Console.debug("testingExtensions", testingExtensions)
64
-
65
- if (foundExtensions.length === 0 && testingExtensions.length === 0)
66
- return {
67
- needed: [],
68
- notInstalled: [],
69
- }
70
-
71
- if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
72
- neededPlugins.push("@learnpack/dom")
73
- }
74
-
75
- if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
76
- neededPlugins.push("@learnpack/html")
77
- }
78
-
79
- if (foundExtensions.includes("jsx")) {
80
- neededPlugins.push("@learnpack/react")
81
- }
82
-
83
- if (foundExtensions.includes("py") || testingExtensions.includes("py")) {
84
- neededPlugins.push("@learnpack/python")
85
- }
86
-
87
- if (
88
- (foundExtensions.includes("js") && !foundExtensions.includes("html")) ||
89
- (testingExtensions.includes("js") && someExerciseWithOnlyTestFile)
90
- ) {
91
- neededPlugins.push("@learnpack/node")
92
- }
93
-
94
- const notInstalled = neededPlugins.filter(
95
- item => !installedPlugins.includes(item)
96
- )
97
-
98
- if (notInstalled.length > 0) {
99
- Console.error(
100
- "These plugins are not installed but required: ",
101
- notInstalled
102
- )
103
- const confirmInstall = await cli.confirm(
104
- "Do you want to install the needed plugins? (y/n)"
105
- )
106
- if (confirmInstall) {
107
- Console.info("Installing the needed plugins...")
108
- for await (const p of notInstalled) {
109
- await command.config.runCommand(`plugins:install`, [p])
110
- Console.log(`Plugin ${p} installed`)
111
- }
112
-
113
- Console.log(
114
- "All needed plugins installed, please restart LearnPack to load them."
115
- )
116
- Console.info("Run: $ learnpack start")
117
- command.exit(0)
118
- } else {
119
- Console.error("You need to install the plugins to complete this exercise")
120
- Console.info(
121
- "To install the plugins run each of the following commands: "
122
- )
123
- for (const p of notInstalled) {
124
- Console.log(`learnpack plugins:install ${p}`)
125
- }
126
-
127
- command.exit(1)
128
- }
129
- }
130
-
131
- return {
132
- needed: neededPlugins,
133
- notInstalled,
134
- }
135
- }
136
-
137
- function includesAll(baseString: string, elementsArray: string[]) {
138
- return elementsArray.every(element => baseString.includes(element))
139
- }
140
-
141
- const installDependencies = async (
142
- deps: string[],
143
- packageManager: TPackageManager
144
- ) => {
145
- let command = ""
146
- if (packageManager === "npm") {
147
- command = `npm install -g ${deps.join(" ")}`
148
- } else if (packageManager === "pip") {
149
- command = `pip install ${deps.join(" ")}`
150
- }
151
-
152
- const { stdout, stderr } = await exec(command)
153
- if (stderr && (stderr.includes("npm ERR!") || stderr.includes("Traceback"))) {
154
- Console.error(`Error executing ${command}.`)
155
- Console.error(stderr)
156
- return
157
- }
158
-
159
- Console.info(`Dependencies ${deps.join(" ")} installed...`)
160
- return true
161
- }
162
-
163
- export const checkNotInstalledDependencies = async (
164
- neededPlugins: string[]
165
- ) => {
166
- Console.info("Checking needed dependencies...")
167
-
168
- const jsPluginsDependencies = ["jest@29.7.0", "jest-environment-jsdom@29.7.0"]
169
- // pytest up to 6.2.5
170
- const pyPluginsDependencies = ["pytest", "pytest-testdox", "mock"]
171
-
172
- const npmLsCommand = "npm ls jest jest-environment-jsdom -g"
173
-
174
- let pytestNeeded = false
175
- let jestNeeded = false
176
-
177
- if (
178
- neededPlugins.includes("@learnpack/dom") ||
179
- neededPlugins.includes("@learnpack/html") ||
180
- neededPlugins.includes("@learnpack/react") ||
181
- neededPlugins.includes("@learnpack/node")
182
- ) {
183
- jestNeeded = true
184
- }
185
-
186
- if (neededPlugins.includes("@learnpack/python")) {
187
- pytestNeeded = true
188
- }
189
-
190
- if (jestNeeded) {
191
- const { stdout, stderr } = await exec("npm ls -g")
192
- if (stderr) {
193
- Console.error(`Error executing ${npmLsCommand}. Use debug for more info`)
194
- Console.debug(stderr)
195
- return false
196
- }
197
-
198
- if (includesAll(stdout, jsPluginsDependencies))
199
- return true
200
-
201
- Console.error("The jest dependencies are not installed")
202
- const confirmInstall = await cli.confirm(
203
- "Do you want to install the needed dependencies? (y/n)"
204
- )
205
-
206
- if (!confirmInstall) {
207
- Console.error(
208
- `The exercises can't be tested without the following dependencies: ${jsPluginsDependencies.join(
209
- ", "
210
- )}`
211
- )
212
- Console.info(
213
- `Please install them and try again. Run the following command to install them: \nnpm install -g ${jsPluginsDependencies.join(
214
- " "
215
- )}`
216
- )
217
- return false
218
- }
219
-
220
- Console.log("Installing jest dependencies...")
221
- await installDependencies(jsPluginsDependencies, "npm")
222
- }
223
-
224
- if (pytestNeeded) {
225
- try {
226
- await exec("python -m pip install --upgrade pip")
227
- } catch (error) {
228
- Console.error(
229
- "Error upgrading pip. Please install pip manually, run: pip install --upgrade pip"
230
- )
231
- Console.debug(error)
232
- }
233
-
234
- const { stdout, stderr } = await exec("pip list")
235
- if (stderr) {
236
- Console.error(`Error executing pip list. Use debug for more info`)
237
- Console.debug(stderr)
238
- return
239
- }
240
-
241
- if (includesAll(stdout, pyPluginsDependencies))
242
- return true
243
-
244
- Console.error("The pytest dependencies are not installed")
245
- const confirmInstall = await cli.confirm(
246
- "Do you want to install the needed dependencies? (y/n)"
247
- )
248
- if (!confirmInstall) {
249
- Console.error(
250
- `The exercises can't be tested without the following dependencies: ${pyPluginsDependencies.join(
251
- ", "
252
- )}`
253
- )
254
- Console.info(
255
- `Please install them and try again. Run the following command to install them: \npip install ${pyPluginsDependencies.join(
256
- " "
257
- )}`
258
- )
259
- return false
260
- }
261
-
262
- Console.log("Installing pytest dependencies...")
263
- await installDependencies(pyPluginsDependencies, "pip")
264
- }
265
-
266
- return true
267
- }
1
+ import { IExercise } from "../models/exercise-obj"
2
+ import { promisify } from "util"
3
+ import { exec as execCallback } from "child_process"
4
+
5
+ const exec = promisify(execCallback)
6
+
7
+ import { cli } from "cli-ux"
8
+ import Console from "./console"
9
+
10
+ type TNeededPlugins = {
11
+ needed: string[]
12
+ notInstalled: string[]
13
+ }
14
+ type TPackageManager = "npm" | "pip"
15
+
16
+ export const checkNotInstalledPlugins = async (
17
+ exercises: IExercise[],
18
+ installedPlugins: string[],
19
+ command: any
20
+ ): Promise<TNeededPlugins> => {
21
+ Console.info("Checking needed plugins...")
22
+ const usefulExtensions = new Set(["py", "js", "jsx", "html"])
23
+ const foundExtensions: string[] = []
24
+ const testingExtensions: string[] = []
25
+ const neededPlugins: string[] = []
26
+ let someExerciseWithOnlyTestFile = false // I will suppose that there are not exercises with only readme and test files
27
+
28
+ // See the extensions of the files that are not tests files
29
+ for (const e of exercises) {
30
+ const notReadmeFiles = e.files.filter(
31
+ f => !f.name.toLowerCase().includes("readme")
32
+ )
33
+
34
+ if (!someExerciseWithOnlyTestFile && notReadmeFiles.length > 0) {
35
+ someExerciseWithOnlyTestFile = notReadmeFiles.every(f => {
36
+ return f.name.includes("test")
37
+ })
38
+
39
+ if (someExerciseWithOnlyTestFile) {
40
+ Console.debug(
41
+ "Some exercises have only test files, I will install the @learnpack/node plugin to run the tests."
42
+ )
43
+ }
44
+ }
45
+
46
+ for (const f of notReadmeFiles) {
47
+ const ext = f.name.split(".").pop()
48
+ if (!ext)
49
+ continue
50
+
51
+ if (f.name.includes("test")) {
52
+ !testingExtensions.includes(ext) && testingExtensions.push(ext)
53
+ continue
54
+ }
55
+
56
+ if (usefulExtensions.has(ext) && !foundExtensions.includes(ext)) {
57
+ foundExtensions.push(ext)
58
+ }
59
+ }
60
+ }
61
+
62
+ Console.debug("foundExtensions", foundExtensions)
63
+ Console.debug("testingExtensions", testingExtensions)
64
+
65
+ if (foundExtensions.length === 0 && testingExtensions.length === 0)
66
+ return {
67
+ needed: [],
68
+ notInstalled: [],
69
+ }
70
+
71
+ if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
72
+ neededPlugins.push("@learnpack/dom")
73
+ }
74
+
75
+ if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
76
+ neededPlugins.push("@learnpack/html")
77
+ }
78
+
79
+ if (foundExtensions.includes("jsx")) {
80
+ neededPlugins.push("@learnpack/react")
81
+ }
82
+
83
+ if (foundExtensions.includes("py") || testingExtensions.includes("py")) {
84
+ neededPlugins.push("@learnpack/python")
85
+ }
86
+
87
+ if (
88
+ (foundExtensions.includes("js") && !foundExtensions.includes("html")) ||
89
+ (testingExtensions.includes("js") && someExerciseWithOnlyTestFile)
90
+ ) {
91
+ neededPlugins.push("@learnpack/node")
92
+ }
93
+
94
+ const notInstalled = neededPlugins.filter(
95
+ item => !installedPlugins.includes(item)
96
+ )
97
+
98
+ if (notInstalled.length > 0) {
99
+ Console.error(
100
+ "These plugins are not installed but required: ",
101
+ notInstalled
102
+ )
103
+ const confirmInstall = await cli.confirm(
104
+ "Do you want to install the needed plugins? (y/n)"
105
+ )
106
+ if (confirmInstall) {
107
+ Console.info("Installing the needed plugins...")
108
+ for await (const p of notInstalled) {
109
+ await command.config.runCommand(`plugins:install`, [p])
110
+ Console.log(`Plugin ${p} installed`)
111
+ }
112
+
113
+ Console.log(
114
+ "All needed plugins installed, please restart LearnPack to load them."
115
+ )
116
+ Console.info("Run: $ learnpack start")
117
+ command.exit(0)
118
+ } else {
119
+ Console.error("You need to install the plugins to complete this exercise")
120
+ Console.info(
121
+ "To install the plugins run each of the following commands: "
122
+ )
123
+ for (const p of notInstalled) {
124
+ Console.log(`learnpack plugins:install ${p}`)
125
+ }
126
+
127
+ command.exit(1)
128
+ }
129
+ }
130
+
131
+ return {
132
+ needed: neededPlugins,
133
+ notInstalled,
134
+ }
135
+ }
136
+
137
+ function includesAll(baseString: string, elementsArray: string[]) {
138
+ return elementsArray.every(element => baseString.includes(element))
139
+ }
140
+
141
+ const installDependencies = async (
142
+ deps: string[],
143
+ packageManager: TPackageManager
144
+ ) => {
145
+ let command = ""
146
+ if (packageManager === "npm") {
147
+ command = `npm install -g ${deps.join(" ")}`
148
+ } else if (packageManager === "pip") {
149
+ command = `pip install ${deps.join(" ")}`
150
+ }
151
+
152
+ const { stdout, stderr } = await exec(command)
153
+ if (stderr && (stderr.includes("npm ERR!") || stderr.includes("Traceback"))) {
154
+ Console.error(`Error executing ${command}.`)
155
+ Console.error(stderr)
156
+ return
157
+ }
158
+
159
+ Console.info(`Dependencies ${deps.join(" ")} installed...`)
160
+ return true
161
+ }
162
+
163
+ export const checkNotInstalledDependencies = async (
164
+ neededPlugins: string[]
165
+ ) => {
166
+ Console.info("Checking needed dependencies...")
167
+
168
+ const jsPluginsDependencies = ["jest@29.7.0", "jest-environment-jsdom@29.7.0"]
169
+ // pytest up to 6.2.5
170
+ const pyPluginsDependencies = ["pytest", "pytest-testdox", "mock"]
171
+
172
+ const npmLsCommand = "npm ls jest jest-environment-jsdom -g"
173
+
174
+ let pytestNeeded = false
175
+ let jestNeeded = false
176
+
177
+ if (
178
+ neededPlugins.includes("@learnpack/dom") ||
179
+ neededPlugins.includes("@learnpack/html") ||
180
+ neededPlugins.includes("@learnpack/react") ||
181
+ neededPlugins.includes("@learnpack/node")
182
+ ) {
183
+ jestNeeded = true
184
+ }
185
+
186
+ if (neededPlugins.includes("@learnpack/python")) {
187
+ pytestNeeded = true
188
+ }
189
+
190
+ if (jestNeeded) {
191
+ const { stdout, stderr } = await exec("npm ls -g")
192
+ if (stderr) {
193
+ Console.error(`Error executing ${npmLsCommand}. Use debug for more info`)
194
+ Console.debug(stderr)
195
+ return false
196
+ }
197
+
198
+ if (includesAll(stdout, jsPluginsDependencies))
199
+ return true
200
+
201
+ Console.error("The jest dependencies are not installed")
202
+ const confirmInstall = await cli.confirm(
203
+ "Do you want to install the needed dependencies? (y/n)"
204
+ )
205
+
206
+ if (!confirmInstall) {
207
+ Console.error(
208
+ `The exercises can't be tested without the following dependencies: ${jsPluginsDependencies.join(
209
+ ", "
210
+ )}`
211
+ )
212
+ Console.info(
213
+ `Please install them and try again. Run the following command to install them: \nnpm install -g ${jsPluginsDependencies.join(
214
+ " "
215
+ )}`
216
+ )
217
+ return false
218
+ }
219
+
220
+ Console.log("Installing jest dependencies...")
221
+ await installDependencies(jsPluginsDependencies, "npm")
222
+ }
223
+
224
+ if (pytestNeeded) {
225
+ try {
226
+ await exec("python -m pip install --upgrade pip")
227
+ } catch (error) {
228
+ Console.error(
229
+ "Error upgrading pip. Please install pip manually, run: pip install --upgrade pip"
230
+ )
231
+ Console.debug(error)
232
+ }
233
+
234
+ const { stdout, stderr } = await exec("pip list")
235
+ if (stderr) {
236
+ Console.error(`Error executing pip list. Use debug for more info`)
237
+ Console.debug(stderr)
238
+ return
239
+ }
240
+
241
+ if (includesAll(stdout, pyPluginsDependencies))
242
+ return true
243
+
244
+ Console.error("The pytest dependencies are not installed")
245
+ const confirmInstall = await cli.confirm(
246
+ "Do you want to install the needed dependencies? (y/n)"
247
+ )
248
+ if (!confirmInstall) {
249
+ Console.error(
250
+ `The exercises can't be tested without the following dependencies: ${pyPluginsDependencies.join(
251
+ ", "
252
+ )}`
253
+ )
254
+ Console.info(
255
+ `Please install them and try again. Run the following command to install them: \npip install ${pyPluginsDependencies.join(
256
+ " "
257
+ )}`
258
+ )
259
+ return false
260
+ }
261
+
262
+ Console.log("Installing pytest dependencies...")
263
+ await installDependencies(pyPluginsDependencies, "pip")
264
+ }
265
+
266
+ return true
267
+ }
@@ -1,34 +1,34 @@
1
- import fs from "fs"
2
- import path from "path"
3
- import clipboardy from "clipboardy"
4
- import { fileURLToPath } from "url"
5
- import { dirname } from "path"
6
-
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = dirname(__filename)
9
-
10
- const credsPath = path.resolve(process.cwd(), "src/utils/creds.json")
11
-
12
- if (!fs.existsSync(credsPath)) {
13
- console.error("❌ File not found:", credsPath)
14
- process.exit(1)
15
- }
16
-
17
- try {
18
- const content = fs.readFileSync(credsPath, "utf-8")
19
- const parsed = JSON.parse(content)
20
- const stringified = JSON.stringify(parsed)
21
-
22
- await clipboardy.write(stringified)
23
-
24
- console.log("✅ JSON credentials copied to clipboard.")
25
- console.log("👉 Paste it into your .env like this:\n")
26
- console.log("GCP_CREDENTIALS_JSON='<PASTE_HERE>'\n")
27
-
28
- // Eliminar el archivo creds.json después de copiar
29
- fs.unlinkSync(credsPath)
30
- console.log("🗑️ creds.json has been deleted to avoid propagation.")
31
- } catch (error) {
32
- console.error("❌ Error reading or parsing creds.json:", error.message)
33
- process.exit(1)
34
- }
1
+ import fs from "fs"
2
+ import path from "path"
3
+ import clipboardy from "clipboardy"
4
+ import { fileURLToPath } from "url"
5
+ import { dirname } from "path"
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = dirname(__filename)
9
+
10
+ const credsPath = path.resolve(process.cwd(), "src/utils/creds.json")
11
+
12
+ if (!fs.existsSync(credsPath)) {
13
+ console.error("❌ File not found:", credsPath)
14
+ process.exit(1)
15
+ }
16
+
17
+ try {
18
+ const content = fs.readFileSync(credsPath, "utf-8")
19
+ const parsed = JSON.parse(content)
20
+ const stringified = JSON.stringify(parsed)
21
+
22
+ await clipboardy.write(stringified)
23
+
24
+ console.log("✅ JSON credentials copied to clipboard.")
25
+ console.log("👉 Paste it into your .env like this:\n")
26
+ console.log("GCP_CREDENTIALS_JSON='<PASTE_HERE>'\n")
27
+
28
+ // Eliminar el archivo creds.json después de copiar
29
+ fs.unlinkSync(credsPath)
30
+ console.log("🗑️ creds.json has been deleted to avoid propagation.")
31
+ } catch (error) {
32
+ console.error("❌ Error reading or parsing creds.json:", error.message)
33
+ process.exit(1)
34
+ }