@learnpack/learnpack 5.0.335 → 5.0.340

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 (48) hide show
  1. package/bin/run +17 -17
  2. package/lib/commands/init.js +41 -41
  3. package/lib/commands/serve.js +589 -126
  4. package/lib/creatorDist/assets/index-BhqDgBS9.js +8448 -78631
  5. package/lib/creatorDist/assets/index-CjddKHB_.css +1 -1688
  6. package/lib/managers/config/exercise.js +2 -14
  7. package/lib/managers/readmeHistoryService.js +3 -1
  8. package/lib/managers/server/routes.js +2 -1
  9. package/lib/utils/configBuilder.js +2 -1
  10. package/lib/utils/creatorUtilities.js +14 -14
  11. package/lib/utils/exerciseFileOrder.d.ts +20 -0
  12. package/lib/utils/exerciseFileOrder.js +49 -0
  13. package/lib/utils/export/epub.js +26 -26
  14. package/lib/utils/readmeSanitizer.d.ts +8 -0
  15. package/lib/utils/readmeSanitizer.js +13 -0
  16. package/lib/utils/templates/epub/epub.css +146 -146
  17. package/lib/utils/templates/scorm/config/api.js +175 -175
  18. package/package.json +1 -1
  19. package/src/commands/init.ts +655 -655
  20. package/src/commands/publish.ts +670 -670
  21. package/src/commands/serve.ts +5853 -5216
  22. package/src/creator/eslint.config.js +28 -28
  23. package/src/creator/src/index.css +227 -227
  24. package/src/creator/src/utils/lib.ts +471 -471
  25. package/src/creatorDist/assets/index-BhqDgBS9.js +8448 -78631
  26. package/src/creatorDist/assets/index-CjddKHB_.css +1 -1688
  27. package/src/managers/config/exercise.ts +3 -15
  28. package/src/managers/readmeHistoryService.ts +3 -1
  29. package/src/managers/server/routes.ts +15 -6
  30. package/src/managers/session.ts +184 -184
  31. package/src/ui/_app/app.css +1 -1
  32. package/src/ui/_app/app.js +1950 -1878
  33. package/src/ui/app.tar.gz +0 -0
  34. package/src/utils/api.ts +675 -675
  35. package/src/utils/configBuilder.ts +102 -100
  36. package/src/utils/creatorUtilities.ts +536 -536
  37. package/src/utils/errors.ts +108 -108
  38. package/src/utils/exerciseFileOrder.ts +50 -0
  39. package/src/utils/export/epub.ts +553 -553
  40. package/src/utils/export/index.ts +4 -4
  41. package/src/utils/export/scorm.ts +121 -121
  42. package/src/utils/export/shared.ts +61 -61
  43. package/src/utils/export/types.ts +25 -25
  44. package/src/utils/export/zip.ts +55 -55
  45. package/src/utils/readmeSanitizer.ts +10 -0
  46. package/src/utils/rigoActions.ts +642 -642
  47. package/src/utils/templates/epub/epub.css +146 -146
  48. package/src/utils/templates/scorm/config/api.js +175 -175
@@ -1,670 +1,670 @@
1
- /* eslint-disable arrow-parens */
2
- /* eslint-disable unicorn/no-array-for-each */
3
- import { execSync } from "child_process"
4
- import { flags } from "@oclif/command"
5
- import SessionCommand from "../utils/SessionCommand"
6
- import SessionManager from "../managers/session"
7
- import * as fs from "fs"
8
- import * as path from "path"
9
- import * as archiver from "archiver"
10
- import axios from "axios"
11
- import FormData = require("form-data");
12
- import Console from "../utils/console"
13
- import {
14
- decompress,
15
- downloadEditor,
16
- checkIfDirectoryExists,
17
- } from "../managers/file"
18
- import api, { getConsumable, RIGOBOT_HOST, TAcademy } from "../utils/api"
19
- import * as prompts from "prompts"
20
- import { isValidRigoToken } from "../utils/rigoActions"
21
- import { minutesToISO8601Duration } from "../utils/misc"
22
- import { getReadmeExtension, slugify } from "../utils/creatorUtilities"
23
-
24
- const uploadZipEndpont = RIGOBOT_HOST + "/v1/learnpack/upload"
25
-
26
- const getAvailableLangs = (learnJson: any): string[] => {
27
- const langs = Object.keys(learnJson?.title || {})
28
- return langs.filter((l) => typeof l === "string" && l.length > 0)
29
- }
30
-
31
- const getDefaultLang = (learnJson: any): string => {
32
- const availableLangs = getAvailableLangs(learnJson)
33
- if (availableLangs.length === 0) return "en"
34
- return availableLangs.includes("en") ? "en" : availableLangs[0]
35
- }
36
-
37
- const getLocalizedValue = (
38
- translations: Record<string, any> | undefined,
39
- lang: string,
40
- fallbackLangs: string[] = ["en", "us"]
41
- ): string => {
42
- if (!translations || typeof translations !== "object") return ""
43
-
44
- const direct = translations[lang]
45
- if (typeof direct === "string" && direct.trim().length > 0) return direct
46
-
47
- for (const fb of fallbackLangs) {
48
- const v = translations[fb]
49
- if (typeof v === "string" && v.trim().length > 0) return v
50
- }
51
-
52
- const firstKey = Object.keys(translations)[0]
53
- const first = firstKey ? translations[firstKey] : ""
54
- return typeof first === "string" ? first : ""
55
- }
56
-
57
- export const handleAssetCreation = async (
58
- sessionPayload: { token: string; rigobotToken: string },
59
- learnJson: any,
60
- selectedLang: string,
61
- learnpackDeployUrl: string,
62
- b64IndexReadme: string,
63
- academyId: number | undefined,
64
- all_translations: string[] = []
65
- ) => {
66
- const category = "uncategorized"
67
-
68
- try {
69
- const user = await api.validateToken(sessionPayload.token)
70
-
71
- const assetTitle = getLocalizedValue(learnJson?.title, selectedLang)
72
- const assetDescription = getLocalizedValue(
73
- learnJson?.description,
74
- selectedLang
75
- )
76
-
77
- if (!assetTitle) {
78
- throw new Error(
79
- `Missing learn.json title for language "${selectedLang}"`
80
- )
81
- }
82
-
83
- let slug = slugify(assetTitle).slice(0, 47)
84
- slug = `${slug}-${selectedLang}`
85
-
86
- const { exists, academyId: existingAcademyId } = await api.doesAssetExists(
87
- sessionPayload.token,
88
- slug
89
- )
90
-
91
- // Compare academy IDs if asset exists and academyId is provided
92
- if (
93
- exists &&
94
- existingAcademyId !== undefined &&
95
- academyId !== undefined &&
96
- existingAcademyId !== academyId
97
- ) {
98
- Console.warning(
99
- `Asset exists in academy ${existingAcademyId}, but attempting to publish to academy ${academyId}. ` +
100
- `The asset will be updated in its current academy (${existingAcademyId}).`
101
- )
102
- }
103
-
104
- // const technologies: unknown[] = Array.isArray(learnJson?.technologies) ?
105
- // learnJson.technologies :
106
- // []
107
-
108
- if (!exists) {
109
- Console.info("Asset does not exist in this academy, creating it")
110
- const assetPayload: any = {
111
- slug: slug,
112
- title: assetTitle,
113
- lang: selectedLang,
114
- graded: true,
115
- description: assetDescription,
116
- learnpack_deploy_url: learnpackDeployUrl,
117
- // technologies: technologies.map((tech: unknown) =>
118
- // String(tech).toLowerCase().replace(/\s+/g, "-")
119
- // ),
120
- technologies: [],
121
- url: learnpackDeployUrl,
122
- category: category,
123
- owner: user.id,
124
- author: user.id,
125
- preview: learnJson.preview,
126
- readme_raw: b64IndexReadme,
127
- all_translations,
128
- }
129
- if (academyId !== undefined) {
130
- assetPayload.academy_id = academyId
131
- }
132
-
133
- const asset = await api.createAsset(sessionPayload.token, assetPayload)
134
- try {
135
- await api.updateRigoPackage(
136
- sessionPayload.rigobotToken.trim(),
137
- learnJson.slug,
138
- {
139
- asset_id: asset.id,
140
- }
141
- )
142
- } catch (error) {
143
- Console.error("Error updating Rigo package:", error)
144
- }
145
-
146
- Console.info("Asset created with id", asset.id)
147
- return asset
148
- }
149
-
150
- Console.info("Asset exists, updating it")
151
- const asset = await api.updateAsset(sessionPayload.token, slug, {
152
- graded: true,
153
- learnpack_deploy_url: learnpackDeployUrl,
154
- title: assetTitle,
155
- category: category,
156
- description: assetDescription,
157
- all_translations,
158
- })
159
- try {
160
- await api.updateRigoPackage(
161
- sessionPayload.rigobotToken.trim(),
162
- learnJson.slug,
163
- {
164
- asset_id: asset.id,
165
- }
166
- )
167
- } catch (error) {
168
- Console.error("Error updating Rigo package:", error)
169
- }
170
-
171
- Console.info("Asset updated with id", asset.id)
172
- return asset
173
- } catch (error) {
174
- Console.error("Error updating or creating asset:", error)
175
- throw error
176
- }
177
- }
178
-
179
- const createMultiLangAssetFromDisk = async (
180
- sessionPayload: { token: string; rigobotToken: string },
181
- learnJson: any,
182
- deployUrl: string
183
- ) => {
184
- const availableLangs = getAvailableLangs(learnJson)
185
-
186
- if (availableLangs.length === 0) {
187
- Console.error(
188
- "No languages found in learn.json.title. Add at least one language (e.g. title.en)."
189
- )
190
- return
191
- }
192
-
193
- const all_translations: string[] = []
194
- for (const lang of availableLangs) {
195
- const readmePath = path.join(
196
- process.cwd(),
197
- `README${getReadmeExtension(lang)}`
198
- )
199
-
200
- let indexReadmeString = ""
201
- try {
202
- if (fs.existsSync(readmePath)) {
203
- indexReadmeString = fs.readFileSync(readmePath, "utf-8")
204
- }
205
- } catch (error) {
206
- Console.error("Error reading index readme:", error)
207
- indexReadmeString = ""
208
- }
209
-
210
- const b64IndexReadme = Buffer.from(indexReadmeString).toString("base64")
211
-
212
- try {
213
- // eslint-disable-next-line no-await-in-loop
214
- const asset = await handleAssetCreation(
215
- sessionPayload,
216
- learnJson,
217
- lang,
218
- deployUrl,
219
- b64IndexReadme,
220
- undefined,
221
- all_translations
222
- )
223
-
224
- if (!asset) {
225
- Console.debug("Could not create/update asset for lang", lang)
226
- continue
227
- }
228
-
229
- all_translations.push(asset.slug)
230
- } catch (error) {
231
- Console.error("Error creating asset for language", lang, error)
232
- // Continue with other languages
233
- }
234
- }
235
- }
236
-
237
- const runAudit = (strict: boolean) => {
238
- try {
239
- Console.info("Running learnpack audit before publishing...")
240
- execSync(`learnpack audit ${strict ? "--strict" : ""}`, {
241
- stdio: "inherit",
242
- })
243
- } catch (error) {
244
- Console.error("Failed to audit with learnpack")
245
-
246
- // Si `execSync` lanza un error, capturamos el mensaje de error
247
- if (error instanceof Error) {
248
- Console.error(error.message)
249
- } else {
250
- Console.error("Unknown error occurred")
251
- }
252
-
253
- // Detener la ejecución del comando si `learnpack publish` falla
254
- process.exit(1)
255
- }
256
-
257
- // Continuar con el proceso de build solo si `learnpack publish` fue exitoso
258
- Console.info(
259
- "Learnpack publish completed successfully. Proceeding with build..."
260
- )
261
- }
262
-
263
- type Academy = {
264
- id: number;
265
- name: string;
266
- slug?: string;
267
- timezone?: string;
268
- };
269
-
270
- type Category = {
271
- id: number;
272
- slug: string;
273
- title: string;
274
- lang: string;
275
- academy: Academy;
276
- };
277
-
278
- function getCategoriesByAcademy(
279
- categories: Category[],
280
- academy: Academy
281
- ): Category[] {
282
- return categories.filter((cat) => cat.academy.id === academy.id)
283
- }
284
-
285
- const selectAcademy = async (
286
- academies: TAcademy[],
287
- bcToken: string
288
- ): Promise<{ academy: TAcademy | null; category: number }> => {
289
- if (academies.length === 0) {
290
- return { academy: null, category: 0 }
291
- }
292
-
293
- if (academies.length === 1) {
294
- return { academy: academies[0], category: 0 }
295
- }
296
-
297
- // prompts the user to select an academy to upload the assets
298
- Console.info("In which academy do you want to publish the asset?")
299
- const response = await prompts({
300
- type: "select",
301
- name: "academy",
302
- message: "Select an academy",
303
- choices: academies.map((academy) => ({
304
- title: academy.name,
305
- value: academy,
306
- })),
307
- })
308
-
309
- const categories: Category[] = await api.getCategories(bcToken)
310
- const categoriesByAcademy = getCategoriesByAcademy(
311
- categories,
312
- response.academy
313
- )
314
-
315
- const categoriesPrompt = await prompts({
316
- type: "select",
317
- name: "category",
318
- message: "Select a category",
319
- choices: categoriesByAcademy.map((category) => ({
320
- title: category.title,
321
- value: category.id,
322
- })),
323
- })
324
-
325
- return {
326
- academy: response.academy,
327
- category: categoriesPrompt.category,
328
- }
329
- }
330
-
331
- class BuildCommand extends SessionCommand {
332
- static description =
333
- "Builds the project by copying necessary files and directories into a zip file"
334
-
335
- static flags = {
336
- help: flags.help({ char: "h" }),
337
- strict: flags.boolean({
338
- char: "s",
339
- description: "strict mode",
340
- default: false,
341
- }),
342
- }
343
-
344
- async init() {
345
- const { flags } = this.parse(BuildCommand)
346
- await this.initSession(flags)
347
- }
348
-
349
- async run() {
350
- const buildDir = path.join(process.cwd(), "build")
351
-
352
- const { flags }: { flags: { strict: boolean } } = this.parse(BuildCommand)
353
- const strict = flags.strict
354
- Console.debug("Strict mode: ", strict)
355
- // this.configManager?.clean()
356
-
357
- const configObject = this.configManager?.get()
358
-
359
- let sessionPayload = await SessionManager.getPayload()
360
-
361
- const sessionExists = sessionPayload && sessionPayload.rigobot
362
-
363
- const isValidToken =
364
- sessionExists && sessionPayload.rigobot.key ?
365
- await isValidRigoToken(sessionPayload.rigobot.key) :
366
- false
367
-
368
- const isValidBreathecodeToken =
369
- sessionExists && sessionPayload.token ?
370
- await api.validateToken(sessionPayload.token) :
371
- false
372
-
373
- if (!sessionExists || !isValidBreathecodeToken || !isValidToken) {
374
- Console.info(
375
- "Almost there! First you need to login with 4Geeks.com to use AI Generation tool for creators. You can create a new account here: https://4geeks.com/checkout?plan=learnpack-creator"
376
- )
377
- try {
378
- sessionPayload = await SessionManager.login()
379
- } catch (error) {
380
- Console.error("Error trying to authenticate")
381
- Console.error((error as TypeError).message || (error as string))
382
- }
383
- }
384
-
385
- const rigoToken = sessionPayload.rigobot.key
386
-
387
- const consumable = await getConsumable(
388
- sessionPayload.token,
389
- "learnpack-publish"
390
- )
391
-
392
- if (consumable.count === 0) {
393
- Console.error(
394
- "It seems you cannot publish tutorials. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions. If you believe there is an issue you can always contact support@4geeks.com"
395
- )
396
- process.exit(1)
397
- }
398
-
399
- if (configObject) {
400
- Console.info("Cleaning configuration files")
401
- this.configManager?.clean()
402
- // build exerises
403
- runAudit(strict)
404
-
405
- Console.debug("Building exercises")
406
- this.configManager?.buildIndex()
407
- }
408
-
409
- const academies = await api.listUserAcademies(sessionPayload.token)
410
-
411
- if (academies.length === 0) {
412
- Console.error(
413
- "It seems you cannot publish tutorials. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions. If you believe there is an issue you can always contact support@4geeks.com"
414
- )
415
- process.exit(1)
416
- }
417
-
418
- const { academy, category } = await selectAcademy(
419
- academies,
420
- sessionPayload.token
421
- )
422
-
423
- const learnJsonPath = path.join(process.cwd(), "learn.json")
424
- if (!fs.existsSync(learnJsonPath)) {
425
- this.error("learn.json not found")
426
- }
427
-
428
- const learnJson = JSON.parse(fs.readFileSync(learnJsonPath, "utf-8"))
429
-
430
- const zipFilePath = path.join(process.cwd(), `${learnJson.slug}.zip`)
431
-
432
- // Ensure build directory exists
433
- if (!fs.existsSync(buildDir)) {
434
- fs.mkdirSync(buildDir)
435
- }
436
-
437
- if (configObject) {
438
- const { config } = configObject
439
- const appAlreadyExists = checkIfDirectoryExists(
440
- `${config?.dirPath}/_app`
441
- )
442
-
443
- if (!appAlreadyExists) {
444
- // download app and decompress
445
- await downloadEditor(
446
- config?.editor.version,
447
- `${config?.dirPath}/app.tar.gz`
448
- )
449
-
450
- Console.info("Decompressing LearnPack UI, this may take a minute...")
451
- await decompress(
452
- `${config?.dirPath}/app.tar.gz`,
453
- `${config?.dirPath}/_app/`
454
- )
455
- }
456
- }
457
-
458
- // Copy config.json
459
- const configPath = path.join(process.cwd(), ".learn", "config.json")
460
- if (fs.existsSync(configPath)) {
461
- fs.copyFileSync(configPath, path.join(buildDir, "config.json"))
462
- } else {
463
- this.error("config.json not found")
464
- }
465
-
466
- // Copy .learn/assets directory, if it exists else create it
467
- const assetsDir = path.join(process.cwd(), ".learn", "assets")
468
- if (fs.existsSync(assetsDir)) {
469
- this.copyDirectory(assetsDir, path.join(buildDir, ".learn", "assets"))
470
- } else {
471
- fs.mkdirSync(path.join(buildDir, ".learn", "assets"), {
472
- recursive: true,
473
- })
474
- }
475
-
476
- // Copy .learn/_app directory files to the same level as config.json
477
- const appDir = path.join(process.cwd(), ".learn", "_app")
478
- if (fs.existsSync(appDir)) {
479
- this.copyDirectory(appDir, buildDir)
480
- } else {
481
- this.error(".learn/_app directory not found")
482
- }
483
-
484
- // After copying the _app directory
485
- const indexHtmlPath = path.join(appDir, "index.html")
486
- const buildIndexHtmlPath = path.join(buildDir, "index.html")
487
- const manifestPWA = path.join(appDir, "manifest.webmanifest")
488
- const buildManifestPWA = path.join(buildDir, "manifest.webmanifest")
489
-
490
- if (fs.existsSync(indexHtmlPath)) {
491
- let indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf-8")
492
-
493
- const selectedLang = getDefaultLang(learnJson)
494
- const description =
495
- getLocalizedValue(learnJson?.description, selectedLang) ||
496
- "LearnPack is awesome!"
497
- const title =
498
- getLocalizedValue(learnJson?.title, selectedLang) ||
499
- "LearnPack: Interactive Learning as a Service"
500
-
501
- const previewUrl =
502
- learnJson.preview ||
503
- "https://raw.githubusercontent.com/learnpack/ide/refs/heads/master/public/learnpack.svg"
504
- // Replace placeholders and the <title>Old title </title> tag for a new tag with the title
505
- indexHtmlContent = indexHtmlContent
506
- .replace(/{{description}}/g, description)
507
- .replace(/<title>.*<\/title>/, `<title>${title}</title>`)
508
- .replace(/{{title}}/g, title)
509
- .replace(/{{preview}}/g, previewUrl)
510
- .replace(/{{slug}}/g, learnJson.slug)
511
- .replace(/{{duration}}/g, minutesToISO8601Duration(learnJson.duration))
512
-
513
- // Write the modified content to the build directory
514
- fs.writeFileSync(buildIndexHtmlPath, indexHtmlContent)
515
- } else {
516
- this.error("index.html not found in _app directory")
517
- }
518
-
519
- if (fs.existsSync(manifestPWA)) {
520
- let manifestPWAContent = fs.readFileSync(manifestPWA, "utf-8")
521
- const selectedLang = getDefaultLang(learnJson)
522
- const courseTitle =
523
- getLocalizedValue(learnJson?.title, selectedLang) ||
524
- getLocalizedValue(learnJson?.title, "us") ||
525
- getLocalizedValue(learnJson?.title, "en") ||
526
- "LearnPack"
527
- manifestPWAContent = manifestPWAContent.replace(
528
- "{{course_title}}",
529
- courseTitle
530
- )
531
-
532
- const courseShortName = { answer: "testing-tutorial" }
533
- // const courseShortName = await generateCourseShortName(rigoToken, {
534
- // learnJSON: JSON.stringify(learnJson),
535
- // })
536
-
537
- manifestPWAContent = manifestPWAContent.replace(
538
- "{{course_app_name}}",
539
- courseShortName.answer
540
- )
541
- fs.writeFileSync(buildManifestPWA, manifestPWAContent)
542
- } else {
543
- this.error("manifest.webmanifest not found in _app directory")
544
- }
545
-
546
- // Copy exercises directory
547
- const exercisesDir = path.join(process.cwd(), "exercises")
548
- const learnExercisesDir = path.join(process.cwd(), ".learn", "exercises")
549
-
550
- if (fs.existsSync(exercisesDir)) {
551
- this.copyDirectory(exercisesDir, path.join(buildDir, "exercises"))
552
- } else if (fs.existsSync(learnExercisesDir)) {
553
- this.copyDirectory(learnExercisesDir, path.join(buildDir, "exercises"))
554
- } else {
555
- this.error("exercises directory not found in either location")
556
- }
557
-
558
- fs.copyFileSync(learnJsonPath, path.join(buildDir, "learn.json"))
559
- const sidebarPath = path.join(process.cwd(), ".learn", "sidebar.json")
560
- if (fs.existsSync(sidebarPath)) {
561
- fs.copyFileSync(sidebarPath, path.join(buildDir, "sidebar.json"))
562
- } else {
563
- this.error("sidebar.json not found in .learn directory")
564
- }
565
-
566
- const output = fs.createWriteStream(zipFilePath)
567
- const archive = archiver("zip", {
568
- zlib: { level: 9 },
569
- })
570
-
571
- output.on("close", async () => {
572
- this.log(
573
- `Build completed: ${zipFilePath} (${archive.pointer()} total bytes)`
574
- )
575
- // Remove build directory after zip is created
576
-
577
- Console.debug("Zip file saved in project root")
578
-
579
- const formData = new FormData()
580
- formData.append("file", fs.createReadStream(zipFilePath))
581
- formData.append("config", JSON.stringify(learnJson))
582
-
583
- try {
584
- const res = await axios.post(uploadZipEndpont, formData, {
585
- headers: {
586
- ...formData.getHeaders(),
587
- Authorization: `Token ${rigoToken}`,
588
- },
589
- })
590
- console.log(res.data)
591
-
592
- fs.unlinkSync(zipFilePath)
593
- this.removeDirectory(buildDir)
594
-
595
- await createMultiLangAssetFromDisk(
596
- { token: sessionPayload.token, rigobotToken: rigoToken },
597
- learnJson,
598
- res.data.url
599
- )
600
- } catch (error) {
601
- if (axios.isAxiosError(error)) {
602
- if (error.response && error.response.status === 403) {
603
- console.error("Error 403:", error.response.data.error)
604
- } else if (error.response && error.response.status === 400) {
605
- console.error(error.response.data.error)
606
- } else {
607
- console.error("Error uploading file:", error)
608
- }
609
- } else {
610
- console.error("Error uploading file:", error)
611
- }
612
-
613
- // fs.unlinkSync(zipFilePath)
614
- // this.removeDirectory(buildDir)
615
- }
616
- })
617
-
618
- archive.on("error", (err: any) => {
619
- throw err
620
- })
621
-
622
- archive.pipe(output)
623
- archive.directory(buildDir, false)
624
- await archive.finalize()
625
- }
626
-
627
- copyDirectory(src: string, dest: string) {
628
- if (!fs.existsSync(dest)) {
629
- fs.mkdirSync(dest, { recursive: true })
630
- }
631
-
632
- const entries = fs.readdirSync(src, { withFileTypes: true })
633
-
634
- for (const entry of entries) {
635
- const srcPath = path.join(src, entry.name)
636
- const destPath = path.join(dest, entry.name)
637
-
638
- if (entry.isDirectory()) {
639
- this.copyDirectory(srcPath, destPath)
640
- } else {
641
- fs.copyFileSync(srcPath, destPath)
642
- }
643
- }
644
- }
645
-
646
- removeDirectory(dir: string) {
647
- if (fs.existsSync(dir)) {
648
- fs.readdirSync(dir).forEach((file) => {
649
- const currentPath = path.join(dir, file)
650
- if (fs.lstatSync(currentPath).isDirectory()) {
651
- this.removeDirectory(currentPath)
652
- } else {
653
- fs.unlinkSync(currentPath)
654
- }
655
- })
656
- fs.rmdirSync(dir)
657
- }
658
- }
659
- }
660
-
661
- BuildCommand.flags = {
662
- strict: flags.boolean({
663
- char: "s",
664
- description: "strict mode",
665
- default: false,
666
- }),
667
- help: flags.help({ char: "h" }),
668
- }
669
-
670
- export default BuildCommand
1
+ /* eslint-disable arrow-parens */
2
+ /* eslint-disable unicorn/no-array-for-each */
3
+ import { execSync } from "child_process"
4
+ import { flags } from "@oclif/command"
5
+ import SessionCommand from "../utils/SessionCommand"
6
+ import SessionManager from "../managers/session"
7
+ import * as fs from "fs"
8
+ import * as path from "path"
9
+ import * as archiver from "archiver"
10
+ import axios from "axios"
11
+ import FormData = require("form-data");
12
+ import Console from "../utils/console"
13
+ import {
14
+ decompress,
15
+ downloadEditor,
16
+ checkIfDirectoryExists,
17
+ } from "../managers/file"
18
+ import api, { getConsumable, RIGOBOT_HOST, TAcademy } from "../utils/api"
19
+ import * as prompts from "prompts"
20
+ import { isValidRigoToken } from "../utils/rigoActions"
21
+ import { minutesToISO8601Duration } from "../utils/misc"
22
+ import { getReadmeExtension, slugify } from "../utils/creatorUtilities"
23
+
24
+ const uploadZipEndpont = RIGOBOT_HOST + "/v1/learnpack/upload"
25
+
26
+ const getAvailableLangs = (learnJson: any): string[] => {
27
+ const langs = Object.keys(learnJson?.title || {})
28
+ return langs.filter((l) => typeof l === "string" && l.length > 0)
29
+ }
30
+
31
+ const getDefaultLang = (learnJson: any): string => {
32
+ const availableLangs = getAvailableLangs(learnJson)
33
+ if (availableLangs.length === 0) return "en"
34
+ return availableLangs.includes("en") ? "en" : availableLangs[0]
35
+ }
36
+
37
+ const getLocalizedValue = (
38
+ translations: Record<string, any> | undefined,
39
+ lang: string,
40
+ fallbackLangs: string[] = ["en", "us"]
41
+ ): string => {
42
+ if (!translations || typeof translations !== "object") return ""
43
+
44
+ const direct = translations[lang]
45
+ if (typeof direct === "string" && direct.trim().length > 0) return direct
46
+
47
+ for (const fb of fallbackLangs) {
48
+ const v = translations[fb]
49
+ if (typeof v === "string" && v.trim().length > 0) return v
50
+ }
51
+
52
+ const firstKey = Object.keys(translations)[0]
53
+ const first = firstKey ? translations[firstKey] : ""
54
+ return typeof first === "string" ? first : ""
55
+ }
56
+
57
+ export const handleAssetCreation = async (
58
+ sessionPayload: { token: string; rigobotToken: string },
59
+ learnJson: any,
60
+ selectedLang: string,
61
+ learnpackDeployUrl: string,
62
+ b64IndexReadme: string,
63
+ academyId: number | undefined,
64
+ all_translations: string[] = []
65
+ ) => {
66
+ const category = "uncategorized"
67
+
68
+ try {
69
+ const user = await api.validateToken(sessionPayload.token)
70
+
71
+ const assetTitle = getLocalizedValue(learnJson?.title, selectedLang)
72
+ const assetDescription = getLocalizedValue(
73
+ learnJson?.description,
74
+ selectedLang
75
+ )
76
+
77
+ if (!assetTitle) {
78
+ throw new Error(
79
+ `Missing learn.json title for language "${selectedLang}"`
80
+ )
81
+ }
82
+
83
+ let slug = slugify(assetTitle).slice(0, 47)
84
+ slug = `${slug}-${selectedLang}`
85
+
86
+ const { exists, academyId: existingAcademyId } = await api.doesAssetExists(
87
+ sessionPayload.token,
88
+ slug
89
+ )
90
+
91
+ // Compare academy IDs if asset exists and academyId is provided
92
+ if (
93
+ exists &&
94
+ existingAcademyId !== undefined &&
95
+ academyId !== undefined &&
96
+ existingAcademyId !== academyId
97
+ ) {
98
+ Console.warning(
99
+ `Asset exists in academy ${existingAcademyId}, but attempting to publish to academy ${academyId}. ` +
100
+ `The asset will be updated in its current academy (${existingAcademyId}).`
101
+ )
102
+ }
103
+
104
+ // const technologies: unknown[] = Array.isArray(learnJson?.technologies) ?
105
+ // learnJson.technologies :
106
+ // []
107
+
108
+ if (!exists) {
109
+ Console.info("Asset does not exist in this academy, creating it")
110
+ const assetPayload: any = {
111
+ slug: slug,
112
+ title: assetTitle,
113
+ lang: selectedLang,
114
+ graded: true,
115
+ description: assetDescription,
116
+ learnpack_deploy_url: learnpackDeployUrl,
117
+ // technologies: technologies.map((tech: unknown) =>
118
+ // String(tech).toLowerCase().replace(/\s+/g, "-")
119
+ // ),
120
+ technologies: [],
121
+ url: learnpackDeployUrl,
122
+ category: category,
123
+ owner: user.id,
124
+ author: user.id,
125
+ preview: learnJson.preview,
126
+ readme_raw: b64IndexReadme,
127
+ all_translations,
128
+ }
129
+ if (academyId !== undefined) {
130
+ assetPayload.academy_id = academyId
131
+ }
132
+
133
+ const asset = await api.createAsset(sessionPayload.token, assetPayload)
134
+ try {
135
+ await api.updateRigoPackage(
136
+ sessionPayload.rigobotToken.trim(),
137
+ learnJson.slug,
138
+ {
139
+ asset_id: asset.id,
140
+ }
141
+ )
142
+ } catch (error) {
143
+ Console.error("Error updating Rigo package:", error)
144
+ }
145
+
146
+ Console.info("Asset created with id", asset.id)
147
+ return asset
148
+ }
149
+
150
+ Console.info("Asset exists, updating it")
151
+ const asset = await api.updateAsset(sessionPayload.token, slug, {
152
+ graded: true,
153
+ learnpack_deploy_url: learnpackDeployUrl,
154
+ title: assetTitle,
155
+ category: category,
156
+ description: assetDescription,
157
+ all_translations,
158
+ })
159
+ try {
160
+ await api.updateRigoPackage(
161
+ sessionPayload.rigobotToken.trim(),
162
+ learnJson.slug,
163
+ {
164
+ asset_id: asset.id,
165
+ }
166
+ )
167
+ } catch (error) {
168
+ Console.error("Error updating Rigo package:", error)
169
+ }
170
+
171
+ Console.info("Asset updated with id", asset.id)
172
+ return asset
173
+ } catch (error) {
174
+ Console.error("Error updating or creating asset:", error)
175
+ throw error
176
+ }
177
+ }
178
+
179
+ const createMultiLangAssetFromDisk = async (
180
+ sessionPayload: { token: string; rigobotToken: string },
181
+ learnJson: any,
182
+ deployUrl: string
183
+ ) => {
184
+ const availableLangs = getAvailableLangs(learnJson)
185
+
186
+ if (availableLangs.length === 0) {
187
+ Console.error(
188
+ "No languages found in learn.json.title. Add at least one language (e.g. title.en)."
189
+ )
190
+ return
191
+ }
192
+
193
+ const all_translations: string[] = []
194
+ for (const lang of availableLangs) {
195
+ const readmePath = path.join(
196
+ process.cwd(),
197
+ `README${getReadmeExtension(lang)}`
198
+ )
199
+
200
+ let indexReadmeString = ""
201
+ try {
202
+ if (fs.existsSync(readmePath)) {
203
+ indexReadmeString = fs.readFileSync(readmePath, "utf-8")
204
+ }
205
+ } catch (error) {
206
+ Console.error("Error reading index readme:", error)
207
+ indexReadmeString = ""
208
+ }
209
+
210
+ const b64IndexReadme = Buffer.from(indexReadmeString).toString("base64")
211
+
212
+ try {
213
+ // eslint-disable-next-line no-await-in-loop
214
+ const asset = await handleAssetCreation(
215
+ sessionPayload,
216
+ learnJson,
217
+ lang,
218
+ deployUrl,
219
+ b64IndexReadme,
220
+ undefined,
221
+ all_translations
222
+ )
223
+
224
+ if (!asset) {
225
+ Console.debug("Could not create/update asset for lang", lang)
226
+ continue
227
+ }
228
+
229
+ all_translations.push(asset.slug)
230
+ } catch (error) {
231
+ Console.error("Error creating asset for language", lang, error)
232
+ // Continue with other languages
233
+ }
234
+ }
235
+ }
236
+
237
+ const runAudit = (strict: boolean) => {
238
+ try {
239
+ Console.info("Running learnpack audit before publishing...")
240
+ execSync(`learnpack audit ${strict ? "--strict" : ""}`, {
241
+ stdio: "inherit",
242
+ })
243
+ } catch (error) {
244
+ Console.error("Failed to audit with learnpack")
245
+
246
+ // Si `execSync` lanza un error, capturamos el mensaje de error
247
+ if (error instanceof Error) {
248
+ Console.error(error.message)
249
+ } else {
250
+ Console.error("Unknown error occurred")
251
+ }
252
+
253
+ // Detener la ejecución del comando si `learnpack publish` falla
254
+ process.exit(1)
255
+ }
256
+
257
+ // Continuar con el proceso de build solo si `learnpack publish` fue exitoso
258
+ Console.info(
259
+ "Learnpack publish completed successfully. Proceeding with build..."
260
+ )
261
+ }
262
+
263
+ type Academy = {
264
+ id: number;
265
+ name: string;
266
+ slug?: string;
267
+ timezone?: string;
268
+ };
269
+
270
+ type Category = {
271
+ id: number;
272
+ slug: string;
273
+ title: string;
274
+ lang: string;
275
+ academy: Academy;
276
+ };
277
+
278
+ function getCategoriesByAcademy(
279
+ categories: Category[],
280
+ academy: Academy
281
+ ): Category[] {
282
+ return categories.filter((cat) => cat.academy.id === academy.id)
283
+ }
284
+
285
+ const selectAcademy = async (
286
+ academies: TAcademy[],
287
+ bcToken: string
288
+ ): Promise<{ academy: TAcademy | null; category: number }> => {
289
+ if (academies.length === 0) {
290
+ return { academy: null, category: 0 }
291
+ }
292
+
293
+ if (academies.length === 1) {
294
+ return { academy: academies[0], category: 0 }
295
+ }
296
+
297
+ // prompts the user to select an academy to upload the assets
298
+ Console.info("In which academy do you want to publish the asset?")
299
+ const response = await prompts({
300
+ type: "select",
301
+ name: "academy",
302
+ message: "Select an academy",
303
+ choices: academies.map((academy) => ({
304
+ title: academy.name,
305
+ value: academy,
306
+ })),
307
+ })
308
+
309
+ const categories: Category[] = await api.getCategories(bcToken)
310
+ const categoriesByAcademy = getCategoriesByAcademy(
311
+ categories,
312
+ response.academy
313
+ )
314
+
315
+ const categoriesPrompt = await prompts({
316
+ type: "select",
317
+ name: "category",
318
+ message: "Select a category",
319
+ choices: categoriesByAcademy.map((category) => ({
320
+ title: category.title,
321
+ value: category.id,
322
+ })),
323
+ })
324
+
325
+ return {
326
+ academy: response.academy,
327
+ category: categoriesPrompt.category,
328
+ }
329
+ }
330
+
331
+ class BuildCommand extends SessionCommand {
332
+ static description =
333
+ "Builds the project by copying necessary files and directories into a zip file"
334
+
335
+ static flags = {
336
+ help: flags.help({ char: "h" }),
337
+ strict: flags.boolean({
338
+ char: "s",
339
+ description: "strict mode",
340
+ default: false,
341
+ }),
342
+ }
343
+
344
+ async init() {
345
+ const { flags } = this.parse(BuildCommand)
346
+ await this.initSession(flags)
347
+ }
348
+
349
+ async run() {
350
+ const buildDir = path.join(process.cwd(), "build")
351
+
352
+ const { flags }: { flags: { strict: boolean } } = this.parse(BuildCommand)
353
+ const strict = flags.strict
354
+ Console.debug("Strict mode: ", strict)
355
+ // this.configManager?.clean()
356
+
357
+ const configObject = this.configManager?.get()
358
+
359
+ let sessionPayload = await SessionManager.getPayload()
360
+
361
+ const sessionExists = sessionPayload && sessionPayload.rigobot
362
+
363
+ const isValidToken =
364
+ sessionExists && sessionPayload.rigobot.key ?
365
+ await isValidRigoToken(sessionPayload.rigobot.key) :
366
+ false
367
+
368
+ const isValidBreathecodeToken =
369
+ sessionExists && sessionPayload.token ?
370
+ await api.validateToken(sessionPayload.token) :
371
+ false
372
+
373
+ if (!sessionExists || !isValidBreathecodeToken || !isValidToken) {
374
+ Console.info(
375
+ "Almost there! First you need to login with 4Geeks.com to use AI Generation tool for creators. You can create a new account here: https://4geeks.com/checkout?plan=learnpack-creator"
376
+ )
377
+ try {
378
+ sessionPayload = await SessionManager.login()
379
+ } catch (error) {
380
+ Console.error("Error trying to authenticate")
381
+ Console.error((error as TypeError).message || (error as string))
382
+ }
383
+ }
384
+
385
+ const rigoToken = sessionPayload.rigobot.key
386
+
387
+ const consumable = await getConsumable(
388
+ sessionPayload.token,
389
+ "learnpack-publish"
390
+ )
391
+
392
+ if (consumable.count === 0) {
393
+ Console.error(
394
+ "It seems you cannot publish tutorials. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions. If you believe there is an issue you can always contact support@4geeks.com"
395
+ )
396
+ process.exit(1)
397
+ }
398
+
399
+ if (configObject) {
400
+ Console.info("Cleaning configuration files")
401
+ this.configManager?.clean()
402
+ // build exerises
403
+ runAudit(strict)
404
+
405
+ Console.debug("Building exercises")
406
+ this.configManager?.buildIndex()
407
+ }
408
+
409
+ const academies = await api.listUserAcademies(sessionPayload.token)
410
+
411
+ if (academies.length === 0) {
412
+ Console.error(
413
+ "It seems you cannot publish tutorials. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions. If you believe there is an issue you can always contact support@4geeks.com"
414
+ )
415
+ process.exit(1)
416
+ }
417
+
418
+ const { academy, category } = await selectAcademy(
419
+ academies,
420
+ sessionPayload.token
421
+ )
422
+
423
+ const learnJsonPath = path.join(process.cwd(), "learn.json")
424
+ if (!fs.existsSync(learnJsonPath)) {
425
+ this.error("learn.json not found")
426
+ }
427
+
428
+ const learnJson = JSON.parse(fs.readFileSync(learnJsonPath, "utf-8"))
429
+
430
+ const zipFilePath = path.join(process.cwd(), `${learnJson.slug}.zip`)
431
+
432
+ // Ensure build directory exists
433
+ if (!fs.existsSync(buildDir)) {
434
+ fs.mkdirSync(buildDir)
435
+ }
436
+
437
+ if (configObject) {
438
+ const { config } = configObject
439
+ const appAlreadyExists = checkIfDirectoryExists(
440
+ `${config?.dirPath}/_app`
441
+ )
442
+
443
+ if (!appAlreadyExists) {
444
+ // download app and decompress
445
+ await downloadEditor(
446
+ config?.editor.version,
447
+ `${config?.dirPath}/app.tar.gz`
448
+ )
449
+
450
+ Console.info("Decompressing LearnPack UI, this may take a minute...")
451
+ await decompress(
452
+ `${config?.dirPath}/app.tar.gz`,
453
+ `${config?.dirPath}/_app/`
454
+ )
455
+ }
456
+ }
457
+
458
+ // Copy config.json
459
+ const configPath = path.join(process.cwd(), ".learn", "config.json")
460
+ if (fs.existsSync(configPath)) {
461
+ fs.copyFileSync(configPath, path.join(buildDir, "config.json"))
462
+ } else {
463
+ this.error("config.json not found")
464
+ }
465
+
466
+ // Copy .learn/assets directory, if it exists else create it
467
+ const assetsDir = path.join(process.cwd(), ".learn", "assets")
468
+ if (fs.existsSync(assetsDir)) {
469
+ this.copyDirectory(assetsDir, path.join(buildDir, ".learn", "assets"))
470
+ } else {
471
+ fs.mkdirSync(path.join(buildDir, ".learn", "assets"), {
472
+ recursive: true,
473
+ })
474
+ }
475
+
476
+ // Copy .learn/_app directory files to the same level as config.json
477
+ const appDir = path.join(process.cwd(), ".learn", "_app")
478
+ if (fs.existsSync(appDir)) {
479
+ this.copyDirectory(appDir, buildDir)
480
+ } else {
481
+ this.error(".learn/_app directory not found")
482
+ }
483
+
484
+ // After copying the _app directory
485
+ const indexHtmlPath = path.join(appDir, "index.html")
486
+ const buildIndexHtmlPath = path.join(buildDir, "index.html")
487
+ const manifestPWA = path.join(appDir, "manifest.webmanifest")
488
+ const buildManifestPWA = path.join(buildDir, "manifest.webmanifest")
489
+
490
+ if (fs.existsSync(indexHtmlPath)) {
491
+ let indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf-8")
492
+
493
+ const selectedLang = getDefaultLang(learnJson)
494
+ const description =
495
+ getLocalizedValue(learnJson?.description, selectedLang) ||
496
+ "LearnPack is awesome!"
497
+ const title =
498
+ getLocalizedValue(learnJson?.title, selectedLang) ||
499
+ "LearnPack: Interactive Learning as a Service"
500
+
501
+ const previewUrl =
502
+ learnJson.preview ||
503
+ "https://raw.githubusercontent.com/learnpack/ide/refs/heads/master/public/learnpack.svg"
504
+ // Replace placeholders and the <title>Old title </title> tag for a new tag with the title
505
+ indexHtmlContent = indexHtmlContent
506
+ .replace(/{{description}}/g, description)
507
+ .replace(/<title>.*<\/title>/, `<title>${title}</title>`)
508
+ .replace(/{{title}}/g, title)
509
+ .replace(/{{preview}}/g, previewUrl)
510
+ .replace(/{{slug}}/g, learnJson.slug)
511
+ .replace(/{{duration}}/g, minutesToISO8601Duration(learnJson.duration))
512
+
513
+ // Write the modified content to the build directory
514
+ fs.writeFileSync(buildIndexHtmlPath, indexHtmlContent)
515
+ } else {
516
+ this.error("index.html not found in _app directory")
517
+ }
518
+
519
+ if (fs.existsSync(manifestPWA)) {
520
+ let manifestPWAContent = fs.readFileSync(manifestPWA, "utf-8")
521
+ const selectedLang = getDefaultLang(learnJson)
522
+ const courseTitle =
523
+ getLocalizedValue(learnJson?.title, selectedLang) ||
524
+ getLocalizedValue(learnJson?.title, "us") ||
525
+ getLocalizedValue(learnJson?.title, "en") ||
526
+ "LearnPack"
527
+ manifestPWAContent = manifestPWAContent.replace(
528
+ "{{course_title}}",
529
+ courseTitle
530
+ )
531
+
532
+ const courseShortName = { answer: "testing-tutorial" }
533
+ // const courseShortName = await generateCourseShortName(rigoToken, {
534
+ // learnJSON: JSON.stringify(learnJson),
535
+ // })
536
+
537
+ manifestPWAContent = manifestPWAContent.replace(
538
+ "{{course_app_name}}",
539
+ courseShortName.answer
540
+ )
541
+ fs.writeFileSync(buildManifestPWA, manifestPWAContent)
542
+ } else {
543
+ this.error("manifest.webmanifest not found in _app directory")
544
+ }
545
+
546
+ // Copy exercises directory
547
+ const exercisesDir = path.join(process.cwd(), "exercises")
548
+ const learnExercisesDir = path.join(process.cwd(), ".learn", "exercises")
549
+
550
+ if (fs.existsSync(exercisesDir)) {
551
+ this.copyDirectory(exercisesDir, path.join(buildDir, "exercises"))
552
+ } else if (fs.existsSync(learnExercisesDir)) {
553
+ this.copyDirectory(learnExercisesDir, path.join(buildDir, "exercises"))
554
+ } else {
555
+ this.error("exercises directory not found in either location")
556
+ }
557
+
558
+ fs.copyFileSync(learnJsonPath, path.join(buildDir, "learn.json"))
559
+ const sidebarPath = path.join(process.cwd(), ".learn", "sidebar.json")
560
+ if (fs.existsSync(sidebarPath)) {
561
+ fs.copyFileSync(sidebarPath, path.join(buildDir, "sidebar.json"))
562
+ } else {
563
+ this.error("sidebar.json not found in .learn directory")
564
+ }
565
+
566
+ const output = fs.createWriteStream(zipFilePath)
567
+ const archive = archiver("zip", {
568
+ zlib: { level: 9 },
569
+ })
570
+
571
+ output.on("close", async () => {
572
+ this.log(
573
+ `Build completed: ${zipFilePath} (${archive.pointer()} total bytes)`
574
+ )
575
+ // Remove build directory after zip is created
576
+
577
+ Console.debug("Zip file saved in project root")
578
+
579
+ const formData = new FormData()
580
+ formData.append("file", fs.createReadStream(zipFilePath))
581
+ formData.append("config", JSON.stringify(learnJson))
582
+
583
+ try {
584
+ const res = await axios.post(uploadZipEndpont, formData, {
585
+ headers: {
586
+ ...formData.getHeaders(),
587
+ Authorization: `Token ${rigoToken}`,
588
+ },
589
+ })
590
+ console.log(res.data)
591
+
592
+ fs.unlinkSync(zipFilePath)
593
+ this.removeDirectory(buildDir)
594
+
595
+ await createMultiLangAssetFromDisk(
596
+ { token: sessionPayload.token, rigobotToken: rigoToken },
597
+ learnJson,
598
+ res.data.url
599
+ )
600
+ } catch (error) {
601
+ if (axios.isAxiosError(error)) {
602
+ if (error.response && error.response.status === 403) {
603
+ console.error("Error 403:", error.response.data.error)
604
+ } else if (error.response && error.response.status === 400) {
605
+ console.error(error.response.data.error)
606
+ } else {
607
+ console.error("Error uploading file:", error)
608
+ }
609
+ } else {
610
+ console.error("Error uploading file:", error)
611
+ }
612
+
613
+ // fs.unlinkSync(zipFilePath)
614
+ // this.removeDirectory(buildDir)
615
+ }
616
+ })
617
+
618
+ archive.on("error", (err: any) => {
619
+ throw err
620
+ })
621
+
622
+ archive.pipe(output)
623
+ archive.directory(buildDir, false)
624
+ await archive.finalize()
625
+ }
626
+
627
+ copyDirectory(src: string, dest: string) {
628
+ if (!fs.existsSync(dest)) {
629
+ fs.mkdirSync(dest, { recursive: true })
630
+ }
631
+
632
+ const entries = fs.readdirSync(src, { withFileTypes: true })
633
+
634
+ for (const entry of entries) {
635
+ const srcPath = path.join(src, entry.name)
636
+ const destPath = path.join(dest, entry.name)
637
+
638
+ if (entry.isDirectory()) {
639
+ this.copyDirectory(srcPath, destPath)
640
+ } else {
641
+ fs.copyFileSync(srcPath, destPath)
642
+ }
643
+ }
644
+ }
645
+
646
+ removeDirectory(dir: string) {
647
+ if (fs.existsSync(dir)) {
648
+ fs.readdirSync(dir).forEach((file) => {
649
+ const currentPath = path.join(dir, file)
650
+ if (fs.lstatSync(currentPath).isDirectory()) {
651
+ this.removeDirectory(currentPath)
652
+ } else {
653
+ fs.unlinkSync(currentPath)
654
+ }
655
+ })
656
+ fs.rmdirSync(dir)
657
+ }
658
+ }
659
+ }
660
+
661
+ BuildCommand.flags = {
662
+ strict: flags.boolean({
663
+ char: "s",
664
+ description: "strict mode",
665
+ default: false,
666
+ }),
667
+ help: flags.help({ char: "h" }),
668
+ }
669
+
670
+ export default BuildCommand