@procamp/cli 0.0.2 → 0.0.4

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/dist/bin/index.js CHANGED
@@ -10,7 +10,8 @@ const new_1 = require("../command/new");
10
10
  const pack_1 = require("../command/pack");
11
11
  const publish_1 = require("../command/publish");
12
12
  const validate_1 = require("../command/validate");
13
- const error_1 = require("../utils/error");
13
+ const output_1 = require("../utils/output");
14
+ const set_1 = require("../command/set");
14
15
  const { version, name, description } = require('../../package.json');
15
16
  exports.program = new commander_1.Command();
16
17
  exports.program.name(name).version(version).description(description);
@@ -37,13 +38,29 @@ exports.program
37
38
  .description('Validate course folder structure')
38
39
  .action(validate_1.validate);
39
40
  exports.program
40
- .command('generate <courseName>')
41
+ .command('generate <key> <value>')
41
42
  .alias('g')
42
43
  .description('Generating Course with blueprint.yml')
43
- .action(generate_1.generateCourse);
44
+ .action((key, value) => {
45
+ if (key === 'course')
46
+ return (0, generate_1.generateCourse)(value);
47
+ return (0, output_1.error)('unknown command ');
48
+ });
49
+ exports.program
50
+ .command('set <key> <value>')
51
+ .description('set value')
52
+ .action((key, value) => {
53
+ if (key === 'courseId')
54
+ return (0, set_1.setCourseId)(value);
55
+ else if (key === 'clientId')
56
+ return (0, set_1.setClientId)(value);
57
+ else if (key === 'clientSecret')
58
+ return (0, set_1.setClientSecret)(value);
59
+ return (0, output_1.error)('unknown command ');
60
+ });
44
61
  exports.program.command('login').description('Login to procamp').action(login_1.login);
45
62
  exports.program.on('command:*', ([command]) => {
46
- (0, error_1.error)(`Erreur : commande "${command}" inconnue`);
63
+ (0, output_1.error)(`Erreur : unknown "${command}" command`);
47
64
  exports.program.help();
48
65
  process.exit(1);
49
66
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":";;;;AAEA,yCAAoC;AACpC,kDAAqD;AACrD,0CAA6C;AAC7C,4CAAyC;AACzC,wCA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WAAW,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,aAAK,CAAC,CAAC;AACvE,eAAO,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE;IACpC,IAAA,aAAK,EAAC,sBAAsB,OAAO,YAAY,CAAC,CAAC;IACjD,eAAO,CAAC,IAAI,EAAE,CAAC;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AACH,eAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport { generateCourse } from '../command/generate';\nimport { initCourse } from '../command/init';\nimport { login } from '../command/login';\nimport { createCourse } from '../command/new';\nimport { zipCourse } from '../command/pack';\nimport { publishCourse } from '../command/publish';\nimport { validate } from '../command/validate';\nimport { error } from '../utils/error';\n\nconst { version, name, description } = require('../../package.json');\n\nexport const program = new Command();\nprogram.name(name).version(version).description(description);\n\nprogram\n .command('init')\n .description('Initialise project configuration ')\n .option(\n '-d, --directory <directory>',\n 'Directory to initialise project',\n process.cwd()\n )\n .action(initCourse);\n\nprogram\n .command('new <projectName>')\n .description('Generate course project')\n .action(createCourse);\n\nprogram\n .command('pack')\n .description('Compress files')\n .option('-d, --directory <directory>', 'Directory to compress', process.cwd())\n .action(zipCourse);\n\nprogram\n .command('publish')\n .description('Publish file to service')\n .action(publishCourse);\n\nprogram\n .command('validate')\n .description('Validate course folder structure')\n .action(validate);\n\n// Commande pour générer un chapitre\nprogram\n .command('generate <courseName>')\n .alias('g')\n .description('Generating Course with blueprint.yml')\n .action(generateCourse);\n\nprogram.command('login').description('Login to procamp').action(login);\nprogram.on('command:*', ([command]) => {\n error(`Erreur : commande \"${command}\" inconnue`);\n program.help();\n process.exit(1);\n});\nprogram.parse(process.argv);\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":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;KACnD,MAAM,CAAC,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;IACrC,IAAI,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAA,yBAAc,EAAC,KAAK,CAAC,CAAC;IAEnD,OAAO,IAAA,cAAK,EAAC,kBAAkB,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEL,eAAO;KACJ,OAAO,CAAC,mBAAmB,CAAC;KAC5B,WAAW,CAAC,WAAW,CAAC;KACxB,MAAM,CAAC,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;IACrC,IAAI,GAAG,KAAK,UAAU;QAAE,OAAO,IAAA,iBAAW,EAAC,KAAK,CAAC,CAAC;SAC7C,IAAI,GAAG,KAAK,UAAU;QAAE,OAAO,IAAA,iBAAW,EAAC,KAAK,CAAC,CAAC;SAClD,IAAI,GAAG,KAAK,cAAc;QAAE,OAAO,IAAA,qBAAe,EAAC,KAAK,CAAC,CAAC;IAC/D,OAAO,IAAA,cAAK,EAAC,kBAAkB,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEL,eAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,aAAK,CAAC,CAAC;AACvE,eAAO,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE;IACpC,IAAA,cAAK,EAAC,qBAAqB,OAAO,WAAW,CAAC,CAAC;IAC/C,eAAO,CAAC,IAAI,EAAE,CAAC;IACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AACH,eAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["#! /usr/bin/env node\n\nimport { Command } from 'commander';\nimport { generateCourse } from '../command/generate';\nimport { initCourse } from '../command/init';\nimport { login } from '../command/login';\nimport { createCourse } from '../command/new';\nimport { zipCourse } from '../command/pack';\nimport { publishCourse } from '../command/publish';\nimport { validate } from '../command/validate';\nimport { error } from '../utils/output';\nimport { setClientId, setClientSecret, setCourseId } from '../command/set';\n\nconst { version, name, description } = require('../../package.json');\n\nexport const program = new Command();\nprogram.name(name).version(version).description(description);\n\nprogram\n .command('init')\n .description('Initialise project configuration ')\n .option(\n '-d, --directory <directory>',\n 'Directory to initialise project',\n process.cwd()\n )\n .action(initCourse);\n\nprogram\n .command('new <projectName>')\n .description('Generate course project')\n .action(createCourse);\n\nprogram\n .command('pack')\n .description('Compress files')\n .option('-d, --directory <directory>', 'Directory to compress', process.cwd())\n .action(zipCourse);\n\nprogram\n .command('publish')\n .description('Publish file to service')\n .action(publishCourse);\n\nprogram\n .command('validate')\n .description('Validate course folder structure')\n .action(validate);\n\n// Commande pour générer un chapitre\nprogram\n .command('generate <key> <value>')\n .alias('g')\n .description('Generating Course with blueprint.yml')\n .action((key: string, value: string) => {\n if (key === 'course') return generateCourse(value);\n\n return error('unknown command ');\n });\n\nprogram\n .command('set <key> <value>')\n .description('set value')\n .action((key: string, value: string) => {\n if (key === 'courseId') return setCourseId(value);\n else if (key === 'clientId') return setClientId(value);\n else if (key === 'clientSecret') return setClientSecret(value);\n return error('unknown command ');\n });\n\nprogram.command('login').description('Login to procamp').action(login);\nprogram.on('command:*', ([command]) => {\n error(`Erreur : unknown \"${command}\" command`);\n program.help();\n process.exit(1);\n});\nprogram.parse(process.argv);\n"]}
@@ -40,7 +40,7 @@ const fs = __importStar(require("fs-extra"));
40
40
  const inquirer_1 = __importDefault(require("inquirer"));
41
41
  const yaml = __importStar(require("js-yaml"));
42
42
  const path = __importStar(require("path"));
43
- const error_1 = require("../utils/error");
43
+ const output_1 = require("../utils/output");
44
44
  const getUserId_1 = require("../utils/getUserId");
45
45
  const process = __importStar(require("process"));
46
46
  const deleteFolder = (srcDir, arrayObject) => __awaiter(void 0, void 0, void 0, function* () {
@@ -198,19 +198,19 @@ function generateCourse(courseName) {
198
198
  }
199
199
  }
200
200
  else
201
- return (0, error_1.error)(`I can't find lessons in the chapter ${i + 1}`);
201
+ return (0, output_1.error)(`I can't find lessons in the chapter ${i + 1}`);
202
202
  }
203
203
  }
204
204
  else
205
- return (0, error_1.error)("You haven't chapters in your blueprint.yaml");
205
+ return (0, output_1.error)("You haven't chapters in your blueprint.yaml");
206
206
  console.log('Folder structure created');
207
207
  }
208
208
  catch (err) {
209
- (0, error_1.error)('Error creating folder structure: ' + err);
209
+ (0, output_1.error)('Error creating folder structure: ' + err);
210
210
  }
211
211
  }
212
212
  else
213
- return (0, error_1.error)('We need the blueprint.yaml file to create a course');
213
+ return (0, output_1.error)('We need the blueprint.yaml file to create a course');
214
214
  });
215
215
  }
216
216
  exports.generateCourse = generateCourse;
@@ -1 +1 @@
1
- {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/command/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,wDAAgC;AAChC,8CAAgC;AAChC,2CAA6B;AAE7B,0CAAuC;AACvC,kDAA+C;AAC/C,iDAAmC;AAEnC,MAAM,YAAY,GAAG,CAAO,MAAc,EAAE,WAAW,EAAE,EAAE;IACzD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QAC3B,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,OAAO;aACxB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;aACxC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,YAAY,GAAa,EAAE,CAAC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AC,QAAQ,KAAK,IAAI;4CAC9B,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;qCAChD;iCACF;qCAAM;oCACL,MAAM,aAAa,GAAG,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC;yCACtC,QAAQ,EAAE;yCACV,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;oCAC9D,MAAM,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;oCAClC,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,aAAa,YAAY,EAAE,EAAE,CAAC,CAAC;oCAErD,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;iCAC9C;6BACF;yBACF;;4BAAM,OAAO,IAAA,aAAK,EAAC,uCAAuC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;qBACrE;iBACF;;oBAAM,OAAO,IAAA,aAAK,EAAC,6CAA6C,CAAC,CAAC;gBAEnE,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;aACzC;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAA,aAAK,EAAC,mCAAmC,GAAG,GAAG,CAAC,CAAC;aAClD;SACF;;YAAM,OAAO,IAAA,aAAK,EAAC,oDAAoD,CAAC,CAAC;IAC5E,CAAC;CAAA;AA9GD,wCA8GC","sourcesContent":["import * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport * as yaml from 'js-yaml';\nimport * as path from 'path';\nimport { course, courseInfo } from '../interfaces/course';\nimport { error } from '../utils/error';\nimport { getUserId } from '../utils/getUserId';\nimport * as process from 'process';\n\nconst deleteFolder = async (srcDir: string, arrayObject) => {\n if (await fs.exists(srcDir)) {\n const entries = await fs.readdir(srcDir, { withFileTypes: true });\n const directories = entries\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n const names = arrayObject.map((obj) => obj.title);\n let deleteFolder: string[] = [];\n for (const directory of directories) {\n const dir = directory\n .toString()\n .slice(directory.toString().indexOf('-') + 1)\n .replaceAll('-', ' ');\n if (!names.includes(dir)) {\n deleteFolder.push(directory);\n }\n }\n if (deleteFolder.length !== 0) {\n const { confirm } = await inquirer.prompt({\n type: 'confirm',\n message: `We found folders not listed in the structure of your course: \\n ${deleteFolder} \\n Do you want to delete them ?`,\n name: 'confirm',\n default: 'y'\n });\n\n if (confirm) {\n for (const directory of deleteFolder) {\n await fs.rm(path.join(srcDir, directory), {\n recursive: true,\n force: true\n });\n }\n console.log('Unlisted folders deleted');\n } else {\n console.log('Deletion aborted.');\n return;\n }\n }\n }\n};\n\nconst updateCourse = async (\n srcDir: string,\n fileDir: string,\n object,\n i: number\n) => {\n if (await fs.exists(srcDir)) {\n const entries = await fs.readdir(srcDir, { withFileTypes: true });\n if (entries.length === 0) await fs.ensureDir(fileDir);\n else {\n const directories = entries\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n const file = directories.find((file) => {\n return (\n file\n .toString()\n .slice(file.toString().indexOf('-') + 1)\n .localeCompare(object.title.toString().replaceAll(' ', '-')) === 0\n );\n });\n\n if (file) {\n const filePath = path.join(srcDir, file);\n if (\n Number(file.toString().slice(0, file.toString().indexOf('-'))) !==\n i + 1\n ) {\n await fs.move(filePath, fileDir, { overwrite: true });\n }\n } else {\n await fs.ensureDir(fileDir);\n }\n }\n } else await fs.mkdir(fileDir);\n};\n\nexport async function generateCourse(courseName: string) {\n const configFile = path.join(process.cwd(), 'blueprint.yaml');\n if (await fs.exists(configFile)) {\n const baseDir = courseName === '.' ? process.cwd() : courseName;\n const fileContents = await fs.readFile(configFile, 'utf8');\n const courses: any = yaml.load(fileContents);\n const courseData: course = { ...courses };\n\n try {\n let configContent = getUserId();\n\n await fs.ensureDir(baseDir);\n\n if (await fs.exists(baseDir)) {\n const courseInfo = courseData.course;\n const meta: courseInfo = {\n title: baseDir,\n author: courseInfo.author,\n description: courseInfo.description,\n version: courseInfo.version,\n courseId: courseInfo.courseId,\n userId: configContent ? configContent.userId : ''\n };\n\n await fs.writeJson(`${baseDir}/meta.json`, meta, {\n spaces: 2\n });\n await fs.writeFile(`${baseDir}/README.md`, '');\n }\n\n if ('chapters' in courseData) {\n const chapters = courseData.chapters;\n await deleteFolder(baseDir, chapters);\n for (let i = 0; i < chapters.length; i++) {\n const chapter = chapters[i];\n const chapterDir = `${baseDir}/${(i + 1)\n .toString()\n .padStart(2, '0')}-${chapter.title.replace(/[:\\s]+/g, '-')}`;\n await updateCourse(baseDir, chapterDir, chapter, i);\n\n // Create meta.json for chapter\n const chapterMeta = {\n title: chapter.title,\n order: i + 1\n };\n\n await fs.writeJson(`${chapterDir}/meta.json`, chapterMeta, {\n spaces: 2\n });\n\n if ('lessons' in chapter) {\n const lessons = chapter.lessons;\n await deleteFolder(chapterDir, lessons);\n for (let j = 0; j < lessons.length; j++) {\n const lesson = lessons[j];\n const lessonDir = `${chapterDir}/${(j + 1)\n .toString()\n .padStart(2, '0')}-${lesson.title.replace(/[:\\s]+/g, '-')}`;\n await updateCourse(chapterDir, lessonDir, lesson, j);\n\n // Create meta.json for lesson\n const lessonMeta = {\n title: lesson.title,\n objectives: lesson.objectives,\n order: j + 1\n };\n await fs.writeJson(`${lessonDir}/meta.json`, lessonMeta, {\n spaces: 2\n });\n\n if ('assessments' in lesson) {\n const assessments = lesson.assessments;\n await deleteFolder(lessonDir, assessments);\n for (let k = 0; k < assessments.length; k++) {\n const assessment = assessments[k];\n const assessmentDir = `${lessonDir}/${(k + 1)\n .toString()\n .padStart(2, '0')}-${assessment.title.replace(\n /[:\\s]+/g,\n '-'\n )}`;\n await updateCourse(lessonDir, assessmentDir, assessment, k);\n\n await fs.writeFile(`${assessmentDir}/README.md`, '');\n\n // Create app-a and app-b folders inside assessment folder\n await fs.ensureDir(`${assessmentDir}/app-a`);\n\n if (assessment.solution === true)\n await fs.ensureDir(`${assessmentDir}/app-b`);\n }\n } else {\n const assessmentDir = `${lessonDir}/${(1)\n .toString()\n .padStart(2, '0')}-${lesson.title.replace(/[:\\s]+/g, '-')}`;\n await fs.ensureDir(assessmentDir);\n await fs.writeFile(`${assessmentDir}/README.md`, '');\n // Create app-a folders inside assessment folder\n await fs.ensureDir(`${assessmentDir}/app-a`);\n }\n }\n } else return error(`I can't find lessons in the chapter ${i + 1}`);\n }\n } else return error(\"You haven't chapters in your blueprint.yaml\");\n\n console.log('Folder structure created');\n } catch (err) {\n error('Error creating folder structure: ' + err);\n }\n } else return error('We need the blueprint.yaml file to create a course');\n}\n"]}
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../src/command/generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,wDAAgC;AAChC,8CAAgC;AAChC,2CAA6B;AAE7B,4CAAwC;AACxC,kDAA+C;AAC/C,iDAAmC;AAEnC,MAAM,YAAY,GAAG,CAAO,MAAc,EAAE,WAAW,EAAE,EAAE;IACzD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;QAC3B,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAClE,MAAM,WAAW,GAAG,OAAO;aACxB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;aACxC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,YAAY,GAAa,EAAE,CAAC;QAChC,KAAK,MAAM,SAAS,IAAI,WAAW,EAAE;YACnC,MAAM,GAAG,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GAAG,aAAa,QAAQ,CAAC,CAAC;qCAChD;iCACF;qCAAM;oCACL,MAAM,aAAa,GAAG,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC;yCACtC,QAAQ,EAAE;yCACV,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,CAAC;oCAC9D,MAAM,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;oCAClC,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,aAAa,YAAY,EAAE,EAAE,CAAC,CAAC;oCAErD,MAAM,EAAE,CAAC,SAAS,CAAC,GAAG,aAAa,QAAQ,CAAC,CAAC;iCAC9C;6BACF;yBACF;;4BAAM,OAAO,IAAA,cAAK,EAAC,uCAAuC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;qBACrE;iBACF;;oBAAM,OAAO,IAAA,cAAK,EAAC,6CAA6C,CAAC,CAAC;gBAEnE,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;aACzC;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAA,cAAK,EAAC,mCAAmC,GAAG,GAAG,CAAC,CAAC;aAClD;SACF;;YAAM,OAAO,IAAA,cAAK,EAAC,oDAAoD,CAAC,CAAC;IAC5E,CAAC;CAAA;AA9GD,wCA8GC","sourcesContent":["import * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport * as yaml from 'js-yaml';\nimport * as path from 'path';\nimport { course, courseInfo } from '../interfaces/course';\nimport { error } from '../utils/output';\nimport { getUserId } from '../utils/getUserId';\nimport * as process from 'process';\n\nconst deleteFolder = async (srcDir: string, arrayObject) => {\n if (await fs.exists(srcDir)) {\n const entries = await fs.readdir(srcDir, { withFileTypes: true });\n const directories = entries\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n const names = arrayObject.map((obj) => obj.title);\n let deleteFolder: string[] = [];\n for (const directory of directories) {\n const dir = directory\n .toString()\n .slice(directory.toString().indexOf('-') + 1)\n .replaceAll('-', ' ');\n if (!names.includes(dir)) {\n deleteFolder.push(directory);\n }\n }\n if (deleteFolder.length !== 0) {\n const { confirm } = await inquirer.prompt({\n type: 'confirm',\n message: `We found folders not listed in the structure of your course: \\n ${deleteFolder} \\n Do you want to delete them ?`,\n name: 'confirm',\n default: 'y'\n });\n\n if (confirm) {\n for (const directory of deleteFolder) {\n await fs.rm(path.join(srcDir, directory), {\n recursive: true,\n force: true\n });\n }\n console.log('Unlisted folders deleted');\n } else {\n console.log('Deletion aborted.');\n return;\n }\n }\n }\n};\n\nconst updateCourse = async (\n srcDir: string,\n fileDir: string,\n object,\n i: number\n) => {\n if (await fs.exists(srcDir)) {\n const entries = await fs.readdir(srcDir, { withFileTypes: true });\n if (entries.length === 0) await fs.ensureDir(fileDir);\n else {\n const directories = entries\n .filter((dirent) => dirent.isDirectory())\n .map((dirent) => dirent.name);\n const file = directories.find((file) => {\n return (\n file\n .toString()\n .slice(file.toString().indexOf('-') + 1)\n .localeCompare(object.title.toString().replaceAll(' ', '-')) === 0\n );\n });\n\n if (file) {\n const filePath = path.join(srcDir, file);\n if (\n Number(file.toString().slice(0, file.toString().indexOf('-'))) !==\n i + 1\n ) {\n await fs.move(filePath, fileDir, { overwrite: true });\n }\n } else {\n await fs.ensureDir(fileDir);\n }\n }\n } else await fs.mkdir(fileDir);\n};\n\nexport async function generateCourse(courseName: string) {\n const configFile = path.join(process.cwd(), 'blueprint.yaml');\n if (await fs.exists(configFile)) {\n const baseDir = courseName === '.' ? process.cwd() : courseName;\n const fileContents = await fs.readFile(configFile, 'utf8');\n const courses: any = yaml.load(fileContents);\n const courseData: course = { ...courses };\n\n try {\n let configContent = getUserId();\n\n await fs.ensureDir(baseDir);\n\n if (await fs.exists(baseDir)) {\n const courseInfo = courseData.course;\n const meta: courseInfo = {\n title: baseDir,\n author: courseInfo.author,\n description: courseInfo.description,\n version: courseInfo.version,\n courseId: courseInfo.courseId,\n userId: configContent ? configContent.userId : ''\n };\n\n await fs.writeJson(`${baseDir}/meta.json`, meta, {\n spaces: 2\n });\n await fs.writeFile(`${baseDir}/README.md`, '');\n }\n\n if ('chapters' in courseData) {\n const chapters = courseData.chapters;\n await deleteFolder(baseDir, chapters);\n for (let i = 0; i < chapters.length; i++) {\n const chapter = chapters[i];\n const chapterDir = `${baseDir}/${(i + 1)\n .toString()\n .padStart(2, '0')}-${chapter.title.replace(/[:\\s]+/g, '-')}`;\n await updateCourse(baseDir, chapterDir, chapter, i);\n\n // Create meta.json for chapter\n const chapterMeta = {\n title: chapter.title,\n order: i + 1\n };\n\n await fs.writeJson(`${chapterDir}/meta.json`, chapterMeta, {\n spaces: 2\n });\n\n if ('lessons' in chapter) {\n const lessons = chapter.lessons;\n await deleteFolder(chapterDir, lessons);\n for (let j = 0; j < lessons.length; j++) {\n const lesson = lessons[j];\n const lessonDir = `${chapterDir}/${(j + 1)\n .toString()\n .padStart(2, '0')}-${lesson.title.replace(/[:\\s]+/g, '-')}`;\n await updateCourse(chapterDir, lessonDir, lesson, j);\n\n // Create meta.json for lesson\n const lessonMeta = {\n title: lesson.title,\n objectives: lesson.objectives,\n order: j + 1\n };\n await fs.writeJson(`${lessonDir}/meta.json`, lessonMeta, {\n spaces: 2\n });\n\n if ('assessments' in lesson) {\n const assessments = lesson.assessments;\n await deleteFolder(lessonDir, assessments);\n for (let k = 0; k < assessments.length; k++) {\n const assessment = assessments[k];\n const assessmentDir = `${lessonDir}/${(k + 1)\n .toString()\n .padStart(2, '0')}-${assessment.title.replace(\n /[:\\s]+/g,\n '-'\n )}`;\n await updateCourse(lessonDir, assessmentDir, assessment, k);\n\n await fs.writeFile(`${assessmentDir}/README.md`, '');\n\n // Create app-a and app-b folders inside assessment folder\n await fs.ensureDir(`${assessmentDir}/app-a`);\n\n if (assessment.solution === true)\n await fs.ensureDir(`${assessmentDir}/app-b`);\n }\n } else {\n const assessmentDir = `${lessonDir}/${(1)\n .toString()\n .padStart(2, '0')}-${lesson.title.replace(/[:\\s]+/g, '-')}`;\n await fs.ensureDir(assessmentDir);\n await fs.writeFile(`${assessmentDir}/README.md`, '');\n // Create app-a folders inside assessment folder\n await fs.ensureDir(`${assessmentDir}/app-a`);\n }\n }\n } else return error(`I can't find lessons in the chapter ${i + 1}`);\n }\n } else return error(\"You haven't chapters in your blueprint.yaml\");\n\n console.log('Folder structure created');\n } catch (err) {\n error('Error creating folder structure: ' + err);\n }\n } else return error('We need the blueprint.yaml file to create a course');\n}\n"]}
@@ -39,8 +39,8 @@ exports.initCourse = void 0;
39
39
  const fs = __importStar(require("fs-extra"));
40
40
  const inquirer_1 = __importDefault(require("inquirer"));
41
41
  const path = __importStar(require("path"));
42
- const error_1 = require("../utils/error");
43
42
  const getUserId_1 = require("../utils/getUserId");
43
+ const output_1 = require("../utils/output");
44
44
  function initCourse(opt) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
46
  const directory = opt.directory;
@@ -79,7 +79,7 @@ function initCourse(opt) {
79
79
  let configContent = (0, getUserId_1.getUserId)();
80
80
  const answers = yield inquirer_1.default.prompt(questions);
81
81
  if (!answers.courseId || answers.courseId.length === 0)
82
- return (0, error_1.error)('Course id must be not null');
82
+ return (0, output_1.error)('Course id must be not null');
83
83
  const meta = {
84
84
  title: answers.title,
85
85
  author: answers.author,
@@ -91,12 +91,11 @@ function initCourse(opt) {
91
91
  const filename = 'meta.json';
92
92
  const filepath = path.join(directory, filename);
93
93
  try {
94
- yield fs.writeFile(filepath, JSON.stringify(meta));
94
+ yield fs.writeFile(filepath, JSON.stringify(meta, null, 2));
95
95
  console.log(`Le fichier ${filename} a été créé avec succès dans le répertoire ${directory} !`);
96
96
  }
97
97
  catch (err) {
98
- if (err)
99
- throw err;
98
+ throw err;
100
99
  }
101
100
  });
102
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/command/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;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;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;SAClD,CAAC;QACF,MAAM,QAAQ,GAAG,WAAW,CAAC;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEhD,IAAI;YACF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YACnD,OAAO,CAAC,GAAG,CACT,cAAc,QAAQ,8CAA8C,SAAS,IAAI,CAClF,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG;gBAAE,MAAM,GAAG,CAAC;SACpB;IACH,CAAC;CAAA;AA3DD,gCA2DC","sourcesContent":["import * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport * as path from 'path';\nimport { error } from '../utils/error';\nimport { getUserId } from '../utils/getUserId';\nimport { courseInfo } from '../interfaces/course';\n\nexport async function initCourse(opt) {\n const directory: string = opt.directory;\n const questions = [\n {\n type: 'input',\n name: 'title',\n message: 'What is the title of the Folder?',\n default: path.basename(directory)\n },\n {\n type: 'input',\n name: 'author',\n message: 'Author ?',\n default: ''\n },\n {\n type: 'input',\n name: 'description',\n message: 'What is the course description ?',\n default: ''\n },\n {\n type: 'input',\n name: 'version',\n message: 'What is the course version ?',\n default: '1.0'\n },\n {\n type: 'input',\n name: 'courseId',\n message: 'What is the course id ?',\n default: ''\n }\n ];\n let configContent = getUserId();\n const answers = await inquirer.prompt(questions);\n\n if (!answers.courseId || answers.courseId.length === 0)\n return error('Course id must be not null');\n\n const meta: courseInfo = {\n title: answers.title,\n author: answers.author,\n description: answers.description,\n courseId: answers.courseId,\n version: answers.version,\n userId: configContent ? configContent.userId : ''\n };\n const filename = 'meta.json';\n const filepath = path.join(directory, filename);\n\n try {\n await fs.writeFile(filepath, JSON.stringify(meta));\n console.log(\n `Le fichier ${filename} a été créé avec succès dans le répertoire ${directory} !`\n );\n } catch (err) {\n if (err) throw err;\n }\n}\n"]}
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/command/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,wDAAgC;AAChC,2CAA6B;AAE7B,kDAA+C;AAC/C,4CAAwC;AAExC,SAAsB,UAAU,CAAC,GAAG;;QAClC,MAAM,SAAS,GAAW,GAAG,CAAC,SAAS,CAAC;QACxC,MAAM,SAAS,GAAG;YAChB;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,kCAAkC;gBAC3C,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;aAClC;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,UAAU;gBACnB,OAAO,EAAE,EAAE;aACZ;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,kCAAkC;gBAC3C,OAAO,EAAE,EAAE;aACZ;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,8BAA8B;gBACvC,OAAO,EAAE,KAAK;aACf;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,yBAAyB;gBAClC,OAAO,EAAE,EAAE;aACZ;SACF,CAAC;QACF,IAAI,aAAa,GAAG,IAAA,qBAAS,GAAE,CAAC;QAChC,MAAM,OAAO,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAEjD,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;YACpD,OAAO,IAAA,cAAK,EAAC,4BAA4B,CAAC,CAAC;QAE7C,MAAM,IAAI,GAAe;YACvB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;SAClD,CAAC;QACF,MAAM,QAAQ,GAAG,WAAW,CAAC;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAEhD,IAAI;YACF,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CACT,cAAc,QAAQ,8CAA8C,SAAS,IAAI,CAClF,CAAC;SACH;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,GAAG,CAAC;SACX;IACH,CAAC;CAAA;AA3DD,gCA2DC","sourcesContent":["import * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport * as path from 'path';\nimport { courseInfo } from '../interfaces/course';\nimport { getUserId } from '../utils/getUserId';\nimport { error } from '../utils/output';\n\nexport async function initCourse(opt) {\n const directory: string = opt.directory;\n const questions = [\n {\n type: 'input',\n name: 'title',\n message: 'What is the title of the Folder?',\n default: path.basename(directory)\n },\n {\n type: 'input',\n name: 'author',\n message: 'Author ?',\n default: ''\n },\n {\n type: 'input',\n name: 'description',\n message: 'What is the course description ?',\n default: ''\n },\n {\n type: 'input',\n name: 'version',\n message: 'What is the course version ?',\n default: '1.0'\n },\n {\n type: 'input',\n name: 'courseId',\n message: 'What is the course id ?',\n default: ''\n }\n ];\n let configContent = getUserId();\n const answers = await inquirer.prompt(questions);\n\n if (!answers.courseId || answers.courseId.length === 0)\n return error('Course id must be not null');\n\n const meta: courseInfo = {\n title: answers.title,\n author: answers.author,\n description: answers.description,\n courseId: answers.courseId,\n version: answers.version,\n userId: configContent ? configContent.userId : ''\n };\n const filename = 'meta.json';\n const filepath = path.join(directory, filename);\n\n try {\n await fs.writeFile(filepath, JSON.stringify(meta, null, 2));\n console.log(\n `Le fichier ${filename} a été créé avec succès dans le répertoire ${directory} !`\n );\n } catch (err) {\n throw err;\n }\n}\n"]}
@@ -42,7 +42,7 @@ const inquirer_1 = __importDefault(require("inquirer"));
42
42
  const jwt_decode_1 = __importDefault(require("jwt-decode"));
43
43
  const os = __importStar(require("os"));
44
44
  const path = __importStar(require("path"));
45
- const error_1 = require("../utils/error");
45
+ const output_1 = require("../utils/output");
46
46
  function login() {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
48
  const questions = [
@@ -67,7 +67,7 @@ function login() {
67
67
  mask: '*',
68
68
  validate: (password) => {
69
69
  if (!password || password.length === 0)
70
- return (0, error_1.error)('Password must be not null');
70
+ return (0, output_1.error)('Password must be not null');
71
71
  return true;
72
72
  }
73
73
  }
@@ -136,7 +136,7 @@ function login() {
136
136
  if ('response' in e)
137
137
  if ('data' in e.response)
138
138
  if ('error_description' in e.response.data) {
139
- (0, error_1.error)(`${e.response.data.error_description}`);
139
+ (0, output_1.error)(`${e.response.data.error_description}`);
140
140
  return;
141
141
  }
142
142
  throw e;
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/command/login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,6CAA+B;AAC/B,wDAAgC;AAChC,4DAAoC;AACpC,uCAAyB;AACzB,2CAA6B;AAC7B,0CAAuC;AAGvC,SAAsB,KAAK;;QACzB,MAAM,SAAS,GAAG;YAChB;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gB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X;gBACE,OAAO,EAAE,WAAW;aACrB,CACF;iBACA,IAAI,CAAC,CAAO,GAAG,EAAE,EAAE;gBAClB,IAAI,OAAe,CAAC;gBAEpB,IAAI,cAAc,IAAI,GAAG,CAAC,IAAI;oBAC5B,OAAO,GAAG,IAAA,oBAAU,EAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBAE9C,MAAM,EAAE,CAAC,SAAS,CAChB,UAAU,kCAEL,UAAU,KACb,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,EAC3B,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,KAExB,EAAE,MAAM,EAAE,CAAC,EAAE,CACd,CAAC;gBACF,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,WAAW,CAAC,CAAC;YACxD,CAAC,CAAA,CAAC;iBACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,IAAI,UAAU,IAAI,CAAC;oBACjB,IAAI,MAAM,IAAI,CAAC,CAAC,QAAQ;wBACtB,IAAI,mBAAmB,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE;4BAC1C,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;4BAC9C,OAAO;yBACR;gBACL,MAAM,CAAC,CAAC;YACV,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AAzHD,sBAyHC","sourcesContent":["import axios from 'axios';\nimport * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport jwt_decode from 'jwt-decode';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { error } from '../utils/error';\nimport { procampConfig } from '../interfaces/procamp_config';\n\nexport async function login() {\n const questions = [\n {\n type: 'input',\n name: 'email',\n message: 'Email:',\n validate: function (input) {\n // Basic email format validation using a regular expression\n const emailRegex = /^\\S+@\\S+\\.\\S+$/;\n if (input.toString().length === 0) return 'Email not be null';\n\n if (emailRegex.test(input)) {\n return true;\n }\n\n return 'Please enter a valid email address.';\n }\n },\n {\n type: 'password',\n name: 'password',\n message: 'Password:',\n mask: '*',\n validate: (password) => {\n if (!password || password.length === 0)\n return error('Password must be not null');\n return true;\n }\n }\n ];\n\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n const clientDataStatic = {\n grant_type: 'password',\n client_id: 'procamp-cli',\n client_secret: 'XGNKcjhw2uYICROaNcfRzMlC5QDXoHWY'\n };\n let configContent: procampConfig;\n if (!(await fs.exists(configPath))) {\n try {\n await fs.writeJSON(configPath, clientDataStatic, { spaces: 2 });\n } catch (e) {\n throw e;\n }\n }\n try {\n configContent = await fs.readJSON(configPath);\n const configContentClient = {\n grant_type: configContent['grant_type'],\n client_id: configContent['client_id'],\n client_secret: configContent['client_secret']\n };\n\n if (configContentClient !== clientDataStatic) {\n configContent = {\n ...configContent,\n ...clientDataStatic\n };\n }\n } catch (e) {\n throw e;\n }\n inquirer.prompt(questions).then((answers) => {\n const clientData = {\n grant_type: configContent.grant_type,\n client_id: configContent.client_id,\n client_secret: configContent.client_secret\n };\n const data = {\n username: answers.email,\n password: answers.password,\n ...clientData\n };\n let bodyContent = '';\n const entries = Object.entries(data);\n for (let i = 0; i < entries.length; i++) {\n const [name, value] = entries[i];\n bodyContent += `${name}=${value}`;\n if (i !== entries.length - 1) {\n bodyContent += '&';\n }\n }\n let headersList = {\n Accept: '*/*',\n 'Content-Type': 'application/x-www-form-urlencoded'\n };\n axios\n .post(\n 'https://auth.procamp.dev/realms/procamp/protocol/openid-connect/token',\n bodyContent,\n {\n headers: headersList\n }\n )\n .then(async (res) => {\n let decoded: object;\n\n if ('access_token' in res.data)\n decoded = jwt_decode(res.data.access_token);\n\n await fs.writeJSON(\n configPath,\n {\n ...clientData,\n api_key: decoded['api-key'],\n userId: decoded['sub']\n },\n { spaces: 2 }\n );\n console.log('You are \\x1b[32m%s\\x1b[0m', 'connected');\n })\n .catch((e) => {\n if ('response' in e)\n if ('data' in e.response)\n if ('error_description' in e.response.data) {\n error(`${e.response.data.error_description}`);\n return;\n }\n throw e;\n });\n });\n}\n"]}
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/command/login.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,6CAA+B;AAC/B,wDAAgC;AAChC,4DAAoC;AACpC,uCAAyB;AACzB,2CAA6B;AAC7B,4CAAwC;AAGxC,SAAsB,KAAK;;QACzB,MAAM,SAAS,GAAG;YAChB;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO;gBACb,OAAO,EAAE,QAAQ;gBACjB,QAAQ,EAAE,UAAU,KAAK;oBAEvB,MAAM,UAAU,GAAG,gBAAgB,CAAC;oBACpC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,KAAK,CAAC;wBAAE,OAAO,mBAAmB,CAAC;oBAE9D,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;wBAC1B,OAAO,IAAI,CAAC;qBACb;oBAED,OAAO,qCAAqC,CAAC;gBAC/C,CAAC;aACF;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,WAAW;gBACpB,IAAI,EAAE,GAAG;gBACT,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;oBACrB,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;wBACpC,OAAO,IAAA,cAAK,EAAC,2BAA2B,CAAC,CAAC;oBAC5C,OAAO,IAAI,CAAC;gBACd,CAAC;aACF;SACF,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,sBAAsB,CAAC,CAAC;QACnE,MAAM,gBAAgB,GAAG;YACvB,UAAU,EAAE,UAAU;YACtB,SAAS,EAAE,aAAa;YACxB,aAAa,EAAE,kCAAkC;S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AAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;CAAA;AAzHD,sBAyHC","sourcesContent":["import axios from 'axios';\nimport * as fs from 'fs-extra';\nimport inquirer from 'inquirer';\nimport jwt_decode from 'jwt-decode';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { error } from '../utils/output';\nimport { procampConfig } from '../interfaces/procamp_config';\n\nexport async function login() {\n const questions = [\n {\n type: 'input',\n name: 'email',\n message: 'Email:',\n validate: function (input) {\n // Basic email format validation using a regular expression\n const emailRegex = /^\\S+@\\S+\\.\\S+$/;\n if (input.toString().length === 0) return 'Email not be null';\n\n if (emailRegex.test(input)) {\n return true;\n }\n\n return 'Please enter a valid email address.';\n }\n },\n {\n type: 'password',\n name: 'password',\n message: 'Password:',\n mask: '*',\n validate: (password) => {\n if (!password || password.length === 0)\n return error('Password must be not null');\n return true;\n }\n }\n ];\n\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n const clientDataStatic = {\n grant_type: 'password',\n client_id: 'procamp-cli',\n client_secret: 'XGNKcjhw2uYICROaNcfRzMlC5QDXoHWY'\n };\n let configContent: procampConfig;\n if (!(await fs.exists(configPath))) {\n try {\n await fs.writeJSON(configPath, clientDataStatic, { spaces: 2 });\n } catch (e) {\n throw e;\n }\n }\n try {\n configContent = await fs.readJSON(configPath);\n const configContentClient = {\n grant_type: configContent['grant_type'],\n client_id: configContent['client_id'],\n client_secret: configContent['client_secret']\n };\n\n if (configContentClient !== clientDataStatic) {\n configContent = {\n ...configContent,\n ...clientDataStatic\n };\n }\n } catch (e) {\n throw e;\n }\n inquirer.prompt(questions).then((answers) => {\n const clientData = {\n grant_type: configContent.grant_type,\n client_id: configContent.client_id,\n client_secret: configContent.client_secret\n };\n const data = {\n username: answers.email,\n password: answers.password,\n ...clientData\n };\n let bodyContent = '';\n const entries = Object.entries(data);\n for (let i = 0; i < entries.length; i++) {\n const [name, value] = entries[i];\n bodyContent += `${name}=${value}`;\n if (i !== entries.length - 1) {\n bodyContent += '&';\n }\n }\n let headersList = {\n Accept: '*/*',\n 'Content-Type': 'application/x-www-form-urlencoded'\n };\n axios\n .post(\n 'https://auth.procamp.dev/realms/procamp/protocol/openid-connect/token',\n bodyContent,\n {\n headers: headersList\n }\n )\n .then(async (res) => {\n let decoded: object;\n\n if ('access_token' in res.data)\n decoded = jwt_decode(res.data.access_token);\n\n await fs.writeJSON(\n configPath,\n {\n ...clientData,\n api_key: decoded['api-key'],\n userId: decoded['sub']\n },\n { spaces: 2 }\n );\n console.log('You are \\x1b[32m%s\\x1b[0m', 'connected');\n })\n .catch((e) => {\n if ('response' in e)\n if ('data' in e.response)\n if ('error_description' in e.response.data) {\n error(`${e.response.data.error_description}`);\n return;\n }\n throw e;\n });\n });\n}\n"]}
@@ -39,7 +39,7 @@ exports.zipCourse = void 0;
39
39
  const adm_zip_1 = __importDefault(require("adm-zip"));
40
40
  const fs = __importStar(require("fs-extra"));
41
41
  const path = __importStar(require("path"));
42
- const error_1 = require("../utils/error");
42
+ const output_1 = require("../utils/output");
43
43
  function zipCourse(options) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
45
  console.log(`Compressing ${options.directory}...`);
@@ -61,7 +61,7 @@ function zipCourse(options) {
61
61
  console.log(`${sourceDirectory} compressed to ${output} in directory ${sourceDirectory}`);
62
62
  }
63
63
  else {
64
- (0, error_1.error)(`${options.directory} does not exist`);
64
+ (0, output_1.error)(`${options.directory} does not exist`);
65
65
  }
66
66
  });
67
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pack.js","sourceRoot":"","sources":["../../src/command/pack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA6B;AAC7B,6CAA+B;AAC/B,2CAA6B;AAC7B,0CAAuC;AAEvC,SAAsB,SAAS,CAAC,OAAO;;QACrC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,SAAS,KAAK,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,aAAa,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,iBAAM,EAAE,CAAC;QACzB,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;YACpC,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YAClD,GAAG,CAAC,cAAc,CAAC,eAAe,EAAE,EAAE,EAAE,UAAU,QAAQ;gBACxD,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE;oBACjC,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;wBAC9B,OAAO,KAAK,CAAC;qBACd;iBACF;gBACD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YAC1D,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;YAC7B,OAAO,CAAC,GAAG,CACT,GAAG,eAAe,kBAAkB,MAAM,iBAAiB,eAAe,EAAE,CAC7E,CAAC;SACH;aAAM;YACL,IAAA,aAAK,EAAC,GAAG,OAAO,CAAC,SAAS,iBAAiB,CAAC,CAAC;SAC9C;IACH,CAAC;CAAA;AAvBD,8BAuBC","sourcesContent":["import AdmZip from 'adm-zip';\nimport * as fs from 'fs-extra';\nimport * as path from 'path';\nimport { error } from '../utils/error';\n\nexport async function zipCourse(options) {\n console.log(`Compressing ${options.directory}...`);\n const output = '.output.zip';\n const zip = new AdmZip();\n const sourceDirectory = path.resolve(options.directory);\n if (await fs.exists(sourceDirectory)) {\n const filesToIgnore = ['_MACOSX', 'node_modules'];\n zip.addLocalFolder(sourceDirectory, '', function (filename) {\n for (const files of filesToIgnore) {\n if (filename.startsWith(files)) {\n return false;\n }\n }\n return !filename.startsWith('.');\n });\n const outputFilePath = path.join(sourceDirectory, output);\n zip.writeZip(outputFilePath);\n console.log(\n `${sourceDirectory} compressed to ${output} in directory ${sourceDirectory}`\n );\n } else {\n error(`${options.directory} does not exist`);\n }\n}\n"]}
1
+ {"version":3,"file":"pack.js","sourceRoot":"","sources":["../../src/command/pack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA6B;AAC7B,6CAA+B;AAC/B,2CAA6B;AAC7B,4CAAwC;AAExC,SAAsB,SAAS,CAAC,OAAO;;QACrC,OAAO,CAAC,GAAG,CAAC,eAAe,OAAO,CAAC,SAAS,KAAK,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,aAAa,CAAC;QAC7B,MAAM,GAAG,GAAG,IAAI,iBAAM,EAAE,CAAC;QACzB,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QACxD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE;YACpC,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YAClD,GAAG,CAAC,cAAc,CAAC,eAAe,EAAE,EAAE,EAAE,UAAU,QAAQ;gBACxD,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE;oBACjC,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;wBAC9B,OAAO,KAAK,CAAC;qBACd;iBACF;gBACD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;YAC1D,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;YAC7B,OAAO,CAAC,GAAG,CACT,GAAG,eAAe,kBAAkB,MAAM,iBAAiB,eAAe,EAAE,CAC7E,CAAC;SACH;aAAM;YACL,IAAA,cAAK,EAAC,GAAG,OAAO,CAAC,SAAS,iBAAiB,CAAC,CAAC;SAC9C;IACH,CAAC;CAAA;AAvBD,8BAuBC","sourcesContent":["import AdmZip from 'adm-zip';\nimport * as fs from 'fs-extra';\nimport * as path from 'path';\nimport { error } from '../utils/output';\n\nexport async function zipCourse(options) {\n console.log(`Compressing ${options.directory}...`);\n const output = '.output.zip';\n const zip = new AdmZip();\n const sourceDirectory = path.resolve(options.directory);\n if (await fs.exists(sourceDirectory)) {\n const filesToIgnore = ['_MACOSX', 'node_modules'];\n zip.addLocalFolder(sourceDirectory, '', function (filename) {\n for (const files of filesToIgnore) {\n if (filename.startsWith(files)) {\n return false;\n }\n }\n return !filename.startsWith('.');\n });\n const outputFilePath = path.join(sourceDirectory, output);\n zip.writeZip(outputFilePath);\n console.log(\n `${sourceDirectory} compressed to ${output} in directory ${sourceDirectory}`\n );\n } else {\n error(`${options.directory} does not exist`);\n }\n}\n"]}
@@ -42,7 +42,7 @@ const form_data_1 = __importDefault(require("form-data"));
42
42
  const fs = __importStar(require("fs-extra"));
43
43
  const os = __importStar(require("os"));
44
44
  const path = __importStar(require("path"));
45
- const error_1 = require("../utils/error");
45
+ const output_1 = require("../utils/output");
46
46
  const pack_1 = require("./pack");
47
47
  function publishCourse() {
48
48
  return __awaiter(this, void 0, void 0, function* () {
@@ -69,7 +69,7 @@ function publishCourse() {
69
69
  }
70
70
  }
71
71
  else
72
- return (0, error_1.error)("I don't find config file.Please log in ");
72
+ return (0, output_1.error)("I don't find config file.Please log in ");
73
73
  yield (0, course_validator_1.validateCourse)(directory);
74
74
  const postZipfile = () => __awaiter(this, void 0, void 0, function* () {
75
75
  if (yield fs.exists(filePathZip)) {
@@ -90,7 +90,7 @@ function publishCourse() {
90
90
  if ('data' in err.response) {
91
91
  const data = err.response.data;
92
92
  if ('statusCode' in data && 'message' in data)
93
- (0, error_1.error)('Error publishing folder: ' +
93
+ (0, output_1.error)('Error publishing folder: ' +
94
94
  data.message +
95
95
  '. Error ' +
96
96
  data.statusCode);
@@ -108,12 +108,12 @@ function publishCourse() {
108
108
  return yield postZipfile();
109
109
  }
110
110
  else {
111
- return (0, error_1.error)("Course Id key don't exist or null in meta.json.\n" +
111
+ return (0, output_1.error)("Course Id key don't exist or null in meta.json.\n" +
112
112
  'Please complete course id');
113
113
  }
114
114
  }
115
115
  else {
116
- return (0, error_1.error)('meta.json file does not exist');
116
+ return (0, output_1.error)('meta.json file does not exist');
117
117
  }
118
118
  });
119
119
  }
@@ -1 +1 @@
1
- {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/command/publish.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA2D;AAC3D,kDAA0B;AAC1B,0DAAiC;AACjC,6CAA+B;AAC/B,uCAAyB;AACzB,2CAA6B;AAC7B,0CAAuC;AACvC,iCAAmC;AAInC,SAAsB,aAAa;;QACjC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEvD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;YACjC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;YACpE,MAAM,IAAI,GAAe,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC1C,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC/C,MAAM,QAAQ,GAAW,IAAI,CAAC,QAAQ,CAAC;gBACvC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;gBACxD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAA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KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;4BACb,IAAI,UAAU,IAAI,GAAG;gCACnB,IAAI,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE;oCAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;oCAC/B,IAAI,YAAY,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI;wCAC3C,IAAA,aAAK,EACH,2BAA2B;4CACzB,IAAI,CAAC,OAAO;4CACZ,UAAU;4CACV,IAAI,CAAC,UAAU,CAClB,CAAC;iCACL;wBACL,CAAC,CAAC,CAAC;qBACN;gBACH,CAAC,CAAA,CAAC;gBAEF,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE;oBACnC,MAAM,IAAA,gBAAS,EAAC;wBACd,SAAS,EAAE,SAAS;qBACrB,CAAC,CAAC;oBACH,MAAM,WAAW,EAAE,CAAC;oBACpB,OAAO;iBACR;gBAED,OAAO,MAAM,WAAW,EAAE,CAAC;aAC5B;iBAAM;gBACL,OAAO,IAAA,aAAK,EACV,mDAAmD;oBACjD,2BAA2B,CAC9B,CAAC;aACH;SACF;aAAM;YACL,OAAO,IAAA,aAAK,EAAC,+BAA+B,CAAC,CAAC;SAC/C;IACH,CAAC;CAAA;AAjFD,sCAiFC","sourcesContent":["import { validateCourse } from '@procamp/course-validator';\nimport axios from 'axios';\nimport FormData from 'form-data';\nimport * as fs from 'fs-extra';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { error } from '../utils/error';\nimport { zipCourse } from './pack';\nimport { procampConfig } from '../interfaces/procamp_config';\nimport { courseInfo } from '../interfaces/course';\n\nexport async function publishCourse() {\n const directory = process.cwd();\n const filenameConf = path.join(directory, 'meta.json');\n\n if (await fs.exists(filenameConf)) {\n const data = await fs.readFile(filenameConf, { encoding: 'utf-8' });\n const meta: courseInfo = JSON.parse(data);\n if (meta.courseId && meta.courseId.length !== 0) {\n const courseId: string = meta.courseId;\n const filePathZip = path.join(directory, '.output.zip');\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n let configContent: procampConfig;\n if (await fs.exists(configPath)) {\n try {\n configContent = await fs.readJSON(configPath);\n } catch (e) {\n throw e;\n }\n if (!('userId' in meta) || meta.userId.length !== 0) {\n if (configContent.userId)\n await fs.writeJson(\n filenameConf,\n { ...meta, userId: configContent['userId'] },\n { spaces: 2 }\n );\n }\n } else return error(\"I don't find config file.Please log in \");\n\n await validateCourse(directory);\n const postZipfile = async () => {\n if (await fs.exists(filePathZip)) {\n const fileStream = fs.createReadStream(filePathZip);\n const form = new FormData();\n form.append('file', fileStream);\n axios\n .post(\n `https://course-manager.procamp.dev/api/courses/${courseId}`,\n form,\n {\n headers: {\n 'x-api-key': configContent['api_key']\n }\n }\n )\n .then((response) => {\n console.log(response.data);\n })\n .catch((err) => {\n if ('response' in err)\n if ('data' in err.response) {\n const data = err.response.data;\n if ('statusCode' in data && 'message' in data)\n error(\n 'Error publishing folder: ' +\n data.message +\n '. Error ' +\n data.statusCode\n );\n }\n });\n }\n };\n\n if (!(await fs.exists(filePathZip))) {\n await zipCourse({\n directory: directory\n });\n await postZipfile();\n return;\n }\n\n return await postZipfile();\n } else {\n return error(\n \"Course Id key don't exist or null in meta.json.\\n\" +\n 'Please complete course id'\n );\n }\n } else {\n return error('meta.json file does not exist');\n }\n}\n"]}
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/command/publish.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA2D;AAC3D,kDAA0B;AAC1B,0DAAiC;AACjC,6CAA+B;AAC/B,uCAAyB;AACzB,2CAA6B;AAC7B,4CAAwC;AACxC,iCAAmC;AAInC,SAAsB,aAAa;;QACjC,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAChC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAA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ACjD,2BAA2B,CAC9B,CAAC;aACH;SACF;aAAM;YACL,OAAO,IAAA,cAAK,EAAC,+BAA+B,CAAC,CAAC;SAC/C;IACH,CAAC;CAAA;AAjFD,sCAiFC","sourcesContent":["import { validateCourse } from '@procamp/course-validator';\nimport axios from 'axios';\nimport FormData from 'form-data';\nimport * as fs from 'fs-extra';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { error } from '../utils/output';\nimport { zipCourse } from './pack';\nimport { procampConfig } from '../interfaces/procamp_config';\nimport { courseInfo } from '../interfaces/course';\n\nexport async function publishCourse() {\n const directory = process.cwd();\n const filenameConf = path.join(directory, 'meta.json');\n\n if (await fs.exists(filenameConf)) {\n const data = await fs.readFile(filenameConf, { encoding: 'utf-8' });\n const meta: courseInfo = JSON.parse(data);\n if (meta.courseId && meta.courseId.length !== 0) {\n const courseId: string = meta.courseId;\n const filePathZip = path.join(directory, '.output.zip');\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n let configContent: procampConfig;\n if (await fs.exists(configPath)) {\n try {\n configContent = await fs.readJSON(configPath);\n } catch (e) {\n throw e;\n }\n if (!('userId' in meta) || meta.userId.length !== 0) {\n if (configContent.userId)\n await fs.writeJson(\n filenameConf,\n { ...meta, userId: configContent['userId'] },\n { spaces: 2 }\n );\n }\n } else return error(\"I don't find config file.Please log in \");\n\n await validateCourse(directory);\n const postZipfile = async () => {\n if (await fs.exists(filePathZip)) {\n const fileStream = fs.createReadStream(filePathZip);\n const form = new FormData();\n form.append('file', fileStream);\n axios\n .post(\n `https://course-manager.procamp.dev/api/courses/${courseId}`,\n form,\n {\n headers: {\n 'x-api-key': configContent['api_key']\n }\n }\n )\n .then((response) => {\n console.log(response.data);\n })\n .catch((err) => {\n if ('response' in err)\n if ('data' in err.response) {\n const data = err.response.data;\n if ('statusCode' in data && 'message' in data)\n error(\n 'Error publishing folder: ' +\n data.message +\n '. Error ' +\n data.statusCode\n );\n }\n });\n }\n };\n\n if (!(await fs.exists(filePathZip))) {\n await zipCourse({\n directory: directory\n });\n await postZipfile();\n return;\n }\n\n return await postZipfile();\n } else {\n return error(\n \"Course Id key don't exist or null in meta.json.\\n\" +\n 'Please complete course id'\n );\n }\n } else {\n return error('meta.json file does not exist');\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export declare const setCourseId: (courseId: string) => Promise<void>;
2
+ export declare const setClientId: (clientId: string) => Promise<void>;
3
+ export declare const setClientSecret: (clientSecret: string) => Promise<void>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.setClientSecret = exports.setClientId = exports.setCourseId = void 0;
39
+ const process = __importStar(require("process"));
40
+ const path = __importStar(require("path"));
41
+ const fs = __importStar(require("fs-extra"));
42
+ const output_1 = require("../utils/output");
43
+ const os_1 = __importDefault(require("os"));
44
+ const setCourseId = (courseId) => __awaiter(void 0, void 0, void 0, function* () {
45
+ const directory = process.cwd();
46
+ const metaFile = path.join(directory, 'meta.json');
47
+ if (yield fs.exists(metaFile)) {
48
+ const metaContent = yield fs.readJSON(metaFile);
49
+ yield fs.writeJson(metaFile, Object.assign(Object.assign({}, metaContent), { courseId: courseId }));
50
+ (0, output_1.success)('Course id set with success');
51
+ }
52
+ else
53
+ return (0, output_1.error)('meta.json file does not exist');
54
+ });
55
+ exports.setCourseId = setCourseId;
56
+ const setClientId = (clientId) => __awaiter(void 0, void 0, void 0, function* () {
57
+ const configPath = path.join(os_1.default.homedir(), '.procamp-config.json');
58
+ if (yield fs.exists(configPath)) {
59
+ const configContent = yield fs.readJSON(configPath);
60
+ yield fs.writeJson(configPath, Object.assign(Object.assign({}, configContent), { client_id: clientId }));
61
+ (0, output_1.success)('Client id set with success');
62
+ }
63
+ else
64
+ return (0, output_1.error)('procamp config file not found');
65
+ });
66
+ exports.setClientId = setClientId;
67
+ const setClientSecret = (clientSecret) => __awaiter(void 0, void 0, void 0, function* () {
68
+ const configPath = path.join(os_1.default.homedir(), '.procamp-config.json');
69
+ if (yield fs.exists(configPath)) {
70
+ const configContent = yield fs.readJSON(configPath);
71
+ yield fs.writeJson(configPath, Object.assign(Object.assign({}, configContent), { client_secret: clientSecret }));
72
+ (0, output_1.success)('Client secret set with success');
73
+ }
74
+ else
75
+ return (0, output_1.error)('procamp config file not found');
76
+ });
77
+ exports.setClientSecret = setClientSecret;
78
+ //# sourceMappingURL=set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set.js","sourceRoot":"","sources":["../../src/command/set.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,2CAA6B;AAC7B,6CAA+B;AAC/B,4CAAiD;AACjD,4CAAoB;AAGb,MAAM,WAAW,GAAG,CAAO,QAAgB,EAAE,EAAE;IACpD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACnD,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;QAC7B,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,kCACtB,WAAW,KACd,QAAQ,EAAE,QAAQ,IAClB,CAAC;QACH,IAAA,gBAAO,EAAC,4BAA4B,CAAC,CAAC;KACvC;;QAAM,OAAO,IAAA,cAAK,EAAC,+BAA+B,CAAC,CAAC;AACvD,CAAC,CAAA,CAAC;AAXW,QAAA,WAAW,eAWtB;AAEK,MAAM,WAAW,GAAG,CAAO,QAAgB,EAAE,EAAE;IACpD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,sBAAsB,CAAC,CAAC;IACnE,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QAC/B,MAAM,aAAa,GAAkB,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,kCACxB,aAAa,KAChB,SAAS,EAAE,QAAQ,IACnB,CAAC;QACH,IAAA,gBAAO,EAAC,4BAA4B,CAAC,CAAC;KACvC;;QAAM,OAAO,IAAA,cAAK,EAAC,+BAA+B,CAAC,CAAC;AACvD,CAAC,CAAA,CAAC;AAVW,QAAA,WAAW,eAUtB;AAEK,MAAM,eAAe,GAAG,CAAO,YAAoB,EAAE,EAAE;IAC5D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,YAAE,CAAC,OAAO,EAAE,EAAE,sBAAsB,CAAC,CAAC;IACnE,IAAI,MAAM,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QAC/B,MAAM,aAAa,GAAkB,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACnE,MAAM,EAAE,CAAC,SAAS,CAAC,UAAU,kCACxB,aAAa,KAChB,aAAa,EAAE,YAAY,IAC3B,CAAC;QACH,IAAA,gBAAO,EAAC,gCAAgC,CAAC,CAAC;KAC3C;;QAAM,OAAO,IAAA,cAAK,EAAC,+BAA+B,CAAC,CAAC;AACvD,CAAC,CAAA,CAAC;AAVW,QAAA,eAAe,mBAU1B","sourcesContent":["import * as process from 'process';\nimport * as path from 'path';\nimport * as fs from 'fs-extra';\nimport { error, success } from '../utils/output';\nimport os from 'os';\nimport { procampConfig } from '../interfaces/procamp_config';\n\nexport const setCourseId = async (courseId: string) => {\n const directory = process.cwd();\n const metaFile = path.join(directory, 'meta.json');\n if (await fs.exists(metaFile)) {\n const metaContent = await fs.readJSON(metaFile);\n await fs.writeJson(metaFile, {\n ...metaContent,\n courseId: courseId\n });\n success('Course id set with success');\n } else return error('meta.json file does not exist');\n};\n\nexport const setClientId = async (clientId: string) => {\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n if (await fs.exists(configPath)) {\n const configContent: procampConfig = await fs.readJSON(configPath);\n await fs.writeJson(configPath, {\n ...configContent,\n client_id: clientId\n });\n success('Client id set with success');\n } else return error('procamp config file not found');\n};\n\nexport const setClientSecret = async (clientSecret: string) => {\n const configPath = path.join(os.homedir(), '.procamp-config.json');\n if (await fs.exists(configPath)) {\n const configContent: procampConfig = await fs.readJSON(configPath);\n await fs.writeJson(configPath, {\n ...configContent,\n client_secret: clientSecret\n });\n success('Client secret set with success');\n } else return error('procamp config file not found');\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function error(err: string): void;
2
+ export declare function success(res: string): void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.success = exports.error = void 0;
4
+ function error(err) {
5
+ console.error('camp \x1b[31m%s\x1b[0m', 'ERR!', err);
6
+ }
7
+ exports.error = error;
8
+ function success(res) {
9
+ console.error('camp \x1b[32m%s\x1b[0m', 'SUCCESS!', res);
10
+ }
11
+ exports.success = success;
12
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/utils/output.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAC,GAAW;IAC/B,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACvD,CAAC;AAFD,sBAEC;AAED,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;AAC3D,CAAC;AAFD,0BAEC","sourcesContent":["export function error(err: string) {\n console.error('camp \\x1b[31m%s\\x1b[0m', 'ERR!', err);\n}\n\nexport function success(res: string) {\n console.error('camp \\x1b[32m%s\\x1b[0m', 'SUCCESS!', res);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@procamp/cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Procamp CLI",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -36,7 +36,6 @@
36
36
  "@types/node": "^18.16.4",
37
37
  "@types/rimraf": "^4.0.5",
38
38
  "husky": "^8.0.3",
39
- "jwt-decode": "^3.1.2",
40
39
  "prettier": "^2.8.8",
41
40
  "rimraf": "^5.0.0",
42
41
  "typescript": "^5.0.4"
@@ -50,6 +49,7 @@
50
49
  "fs-extra": "^11.1.1",
51
50
  "inquirer": "^8.2.5",
52
51
  "js-yaml": "^4.1.0",
52
+ "jwt-decode": "^3.1.2",
53
53
  "ts-jest": "^29.1.0"
54
54
  }
55
55
  }
package/readme.md CHANGED
@@ -1,32 +1,296 @@
1
- # Getting started with Cmp cli
1
+ # Camp CLI - Init Command
2
2
 
3
- This project was bootstrapped with [Cmp CLI](https://github.com/facebook/create-react-app)
3
+ The `init` command allows you to initialize the project configuration for your camp.
4
4
 
5
- ### ENV
5
+ ## Usage
6
6
 
7
- Copy content from .example.env to .env
8
- ## Available Scripts
7
+ ```bash
8
+ camp init [options]
9
+ ```
9
10
 
10
- You can create the course directory with:
11
- ### `cmp new`
11
+ ## Description
12
12
 
13
- In the course directory, you can run:
13
+ The `init` command initializes the project configuration by prompting you to provide information about the camp. It creates a `meta.json` file with the provided details in the specified directory.
14
14
 
15
- ### `cmp init`
15
+ ## Options
16
16
 
17
- This command allows you to create a meta.json file that
18
- contains race configurations such as the title, id .
17
+ - `-d, --directory <directory>`: The directory to initialize the project. If not specified, the current working directory will be used.
19
18
 
20
- ### `cmp pack`
19
+ ## Prompts
21
20
 
22
- Archive the course, by default it archives
23
- the current folder. The -d or --directory option
24
- adds the path of the archived folder
21
+ During the initialization process, the following prompts will be presented:
25
22
 
26
- ### `cmp publish`
27
- Publishes the course on the course manager platform. It uses the id in the meta.json
28
- file for publishing the course
23
+ 1. **title**: The title of the folder. This will be used as the default if not provided.
24
+ 2. **author**: The author of the camp. Leave it empty if not applicable.
25
+ 3. **description**: The description of the camp. Leave it empty if not applicable.
26
+ 4. **version**: The version of the camp. Defaults to "1.0" if not provided.
27
+ 5. **courseId**: The ID of the course. This field is mandatory and must not be left empty.
29
28
 
30
- ### `cmp g course`
31
- Create course with blueprint.yaml
29
+ ## Example
32
30
 
31
+ To initialize the project configuration for your camp, run the following command:
32
+
33
+ ```bash
34
+ camp init -d /path/to/project
35
+ ```
36
+
37
+ This will prompt you to provide the required information and create a `meta.json` file in the specified directory.
38
+
39
+ ---
40
+
41
+ # Camp CLI - New Command
42
+
43
+ The `new` command generates a new course project with the specified name.
44
+
45
+ ## Usage
46
+
47
+ ```bash
48
+ camp new <projectName>
49
+ ```
50
+
51
+ ## Description
52
+
53
+ The `new` command generates a new course project with the given `<projectName>`. It creates a new directory with the project name and prompts for confirmation before proceeding.
54
+
55
+ ## Arguments
56
+
57
+ - `<projectName>`: The name of the project to generate. This will be used as the directory name for the project.
58
+
59
+ ## Example
60
+
61
+ To generate a new course project with the name "myproject", run the following command:
62
+
63
+ ```bash
64
+ camp new myproject
65
+ ```
66
+
67
+ This will create a new directory named "myproject" and initialize the project configuration within it using the `init` command.
68
+
69
+ ---
70
+
71
+ # Camp CLI - Pack Command
72
+
73
+ The `pack` command compresses files in the specified directory.
74
+
75
+ ## Usage
76
+
77
+ ```bash
78
+ camp pack [options]
79
+ ```
80
+
81
+ ## Description
82
+
83
+ The `pack` command compresses the files in the specified directory using the ZIP format. It excludes certain files and directories from compression, such as "_MACOSX" and "node_modules".
84
+
85
+ ## Options
86
+
87
+ - `-d, --directory <directory>`: The directory to compress. If not specified, the current working directory will be used.
88
+
89
+ ## Example
90
+
91
+ To compress files in the current working directory, run the following command:
92
+
93
+ ```bash
94
+ camp pack
95
+ ```
96
+
97
+ This will create a compressed ZIP file named ".output.zip" in the same directory.
98
+
99
+ To compress files in a specific directory, provide the directory path using the `-d` or `--directory` option:
100
+
101
+ ```bash
102
+ camp pack -d /path/to/directory
103
+ ```
104
+
105
+ This will create a compressed ZIP file named ".output.zip" in the specified directory.
106
+
107
+ ---
108
+
109
+ # Camp CLI - Login Command
110
+
111
+ The `login` command allows you to log in to Procamp.
112
+
113
+ ## Usage
114
+
115
+ ```bash
116
+ camp login
117
+ ```
118
+
119
+ ## Description
120
+
121
+ The `login` command prompts you to enter your email and password to log in to Procamp. It then retrieves the access token and stores it securely in the config file.
122
+
123
+ ## Example
124
+
125
+ To log in to Procamp, run the following command:
126
+
127
+ ```bash
128
+ camp login
129
+ ```
130
+
131
+ This command performs the following steps:
132
+
133
+ 1. Prompts you to enter your email and password.
134
+ 2. Sends a request to the Procamp authentication server to retrieve the access token.
135
+ 3. Stores the access token, client ID, and other necessary information securely in the config file.
136
+ 4. Displays a success message indicating that you are logged in.
137
+
138
+ ---
139
+
140
+ # Camp CLI - Publish Command
141
+
142
+ The `publish` command publishes the files to the service.
143
+
144
+ ## Usage
145
+
146
+ ```bash
147
+ camp publish
148
+ ```
149
+
150
+ ## Description
151
+
152
+ The `publish` command publishes the files to the service by compressing the files, validating the course, and then sending the compressed file to the service endpoint.
153
+
154
+ ## Prerequisites
155
+
156
+ Before running the `publish` command, make sure you have completed the following steps:
157
+
158
+ 1. Ensure that the `meta.json` file exists in the current directory.
159
+ 2. Make sure you are logged in by setting up the config file with your credentials.
160
+
161
+ ## Example
162
+
163
+ To publish the course files to the service, run the following command:
164
+
165
+ ```bash
166
+ camp publish
167
+ ```
168
+
169
+ This command performs the following steps:
170
+
171
+ 1. Checks if the `meta.json` file exists in the current directory.
172
+ 2. Validates the course files in the directory.
173
+ 3. Compresses the files into a ZIP file.
174
+ 4. Sends the ZIP file to the service endpoint using the course ID specified in the `meta.json` file.
175
+ 5. Displays the response from the service.
176
+
177
+ Note: Make sure you are logged in by setting up the config file with your credentials before running the `publish` command.
178
+
179
+ ---
180
+
181
+ # Camp CLI - Validate Command
182
+
183
+ The `validate` command validates the course folder structure.
184
+
185
+ ## Usage
186
+
187
+ ```bash
188
+ camp validate
189
+ ```
190
+
191
+ ## Description
192
+
193
+ The `validate` command validates the course folder structure to ensure it meets the required format and structure. It checks for any missing or incorrectly organized files and directories.
194
+
195
+ ## Example
196
+
197
+ To validate the course folder structure, run the following command:
198
+
199
+ ```bash
200
+ camp validate
201
+ ```
202
+
203
+ This command performs the following steps:
204
+
205
+ 1. Validates the course folder structure in the current directory.
206
+ 2. Checks for any missing or incorrectly organized files and directories.
207
+ 3. Displays the validation results.
208
+
209
+ ---
210
+
211
+ # Camp CLI - Generate Command
212
+
213
+ The `generate` command generates a course based on the provided blueprint.yaml file.
214
+
215
+ ## Usage
216
+
217
+ ```bash
218
+ camp generate <key> <value>
219
+ ```
220
+
221
+ ## Description
222
+
223
+ The `generate` command generates a course with the specified structure using the blueprint.yaml file. It creates directories and files based on the blueprint configuration.
224
+
225
+ ## Arguments
226
+
227
+ - `<key>`: The key to specify the type of generation. Currently supported key: `course`.
228
+ - `<value>`: The value associated with the key.
229
+
230
+ ## Example
231
+
232
+ To generate a course structure based on the blueprint.yaml file, run the following command:
233
+
234
+ ```bash
235
+ camp generate course .
236
+ ```
237
+
238
+ This command performs the following steps:
239
+
240
+ 1. Reads the `blueprint.yaml` file in the current directory.
241
+ 2. Creates directories and files based on the blueprint configuration.
242
+ 3. Sets the course title, author, description, version, and courseId in the `meta.json` file.
243
+ 4. Creates `README.md` files in each directory.
244
+ 5. Generates the folder structure for chapters, lessons, and assessments based on the blueprint configuration.
245
+
246
+ Note: Make sure you have the `blueprint.yaml` file in the current directory before running the `generate` command.
247
+
248
+ ---
249
+
250
+ # Camp CLI - Set Command
251
+
252
+ The `set` command allows you to set values for specific keys.
253
+
254
+ ## Usage
255
+
256
+ ```bash
257
+ camp set <key> <value>
258
+ ```
259
+
260
+ ## Description
261
+
262
+ The `set` command sets values for specific keys in the configuration files.
263
+
264
+ ## Available Keys
265
+
266
+ - `courseId`: Sets the course ID in the `meta.json` file.
267
+ - `clientId`: Sets the client ID in the config file.
268
+ - `clientSecret`: Sets the client secret in the config file.
269
+
270
+ ## Examples
271
+
272
+ To set the course ID, run the following command:
273
+
274
+ ```bash
275
+ camp set courseId <courseId>
276
+ ```
277
+
278
+ This command sets the provided `<courseId>` in the `meta.json` file.
279
+
280
+ To set the client ID, run the following command:
281
+
282
+ ```bash
283
+ camp set clientId <clientId>
284
+ ```
285
+
286
+ This command sets the provided `<clientId>` in the config file.
287
+
288
+ To set the client secret, run the following command:
289
+
290
+ ```bash
291
+ camp set clientSecret <clientSecret>
292
+ ```
293
+
294
+ This command sets the provided `<clientSecret>` in the config file.
295
+
296
+ ---
@@ -1 +0,0 @@
1
- export declare function error(err: string): void;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.error = void 0;
4
- function error(err) {
5
- console.error('cmp \x1b[31m%s\x1b[0m', 'ERR!', err);
6
- }
7
- exports.error = error;
8
- //# sourceMappingURL=error.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAC,GAAW;IAC/B,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AAFD,sBAEC","sourcesContent":["export function error(err: string) {\n console.error('cmp \\x1b[31m%s\\x1b[0m', 'ERR!', err);\n}\n"]}