@learnpack/learnpack 2.1.26 → 2.1.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. package/README.md +10 -10
  2. package/oclif.manifest.json +1 -1
  3. package/package.json +2 -1
  4. package/src/commands/audit.ts +113 -113
  5. package/src/commands/clean.ts +10 -10
  6. package/src/commands/download.ts +18 -18
  7. package/src/commands/init.ts +39 -39
  8. package/src/commands/login.ts +13 -13
  9. package/src/commands/logout.ts +9 -9
  10. package/src/commands/publish.ts +25 -25
  11. package/src/commands/start.ts +101 -75
  12. package/src/commands/test.ts +34 -34
  13. package/src/managers/config/allowed_files.ts +2 -2
  14. package/src/managers/config/defaults.ts +2 -2
  15. package/src/managers/config/exercise.ts +79 -79
  16. package/src/managers/config/index.ts +145 -145
  17. package/src/managers/file.ts +74 -65
  18. package/src/managers/server/index.ts +32 -31
  19. package/src/managers/server/routes.ts +139 -90
  20. package/src/managers/session.ts +53 -24
  21. package/src/managers/socket.ts +92 -79
  22. package/src/models/action.ts +8 -1
  23. package/src/models/config-manager.ts +2 -2
  24. package/src/models/config.ts +7 -2
  25. package/src/models/exercise-obj.ts +6 -3
  26. package/src/models/plugin-config.ts +2 -2
  27. package/src/models/session.ts +5 -2
  28. package/src/models/socket.ts +12 -6
  29. package/src/models/status.ts +15 -14
  30. package/src/plugin/command/compile.ts +10 -10
  31. package/src/plugin/command/test.ts +14 -14
  32. package/src/plugin/index.ts +5 -5
  33. package/src/plugin/plugin.ts +26 -26
  34. package/src/plugin/utils.ts +23 -23
  35. package/src/utils/BaseCommand.ts +16 -16
  36. package/src/utils/api.ts +143 -91
  37. package/src/utils/audit.ts +93 -96
  38. package/src/utils/exercisesQueue.ts +15 -15
  39. package/src/utils/fileQueue.ts +85 -85
  40. package/src/utils/watcher.ts +14 -14
  41. package/lib/commands/audit.d.ts +0 -6
  42. package/lib/commands/audit.js +0 -342
  43. package/lib/commands/clean.d.ts +0 -8
  44. package/lib/commands/clean.js +0 -25
  45. package/lib/commands/download.d.ts +0 -13
  46. package/lib/commands/download.js +0 -55
  47. package/lib/commands/init.d.ts +0 -9
  48. package/lib/commands/init.js +0 -123
  49. package/lib/commands/login.d.ts +0 -14
  50. package/lib/commands/login.js +0 -37
  51. package/lib/commands/logout.d.ts +0 -14
  52. package/lib/commands/logout.js +0 -37
  53. package/lib/commands/publish.d.ts +0 -14
  54. package/lib/commands/publish.js +0 -82
  55. package/lib/commands/start.d.ts +0 -7
  56. package/lib/commands/start.js +0 -165
  57. package/lib/commands/test.d.ts +0 -6
  58. package/lib/commands/test.js +0 -62
  59. package/lib/index.d.ts +0 -1
  60. package/lib/index.js +0 -4
  61. package/lib/managers/config/allowed_files.d.ts +0 -5
  62. package/lib/managers/config/allowed_files.js +0 -30
  63. package/lib/managers/config/defaults.d.ts +0 -39
  64. package/lib/managers/config/defaults.js +0 -40
  65. package/lib/managers/config/exercise.d.ts +0 -36
  66. package/lib/managers/config/exercise.js +0 -233
  67. package/lib/managers/config/index.d.ts +0 -3
  68. package/lib/managers/config/index.js +0 -320
  69. package/lib/managers/file.d.ts +0 -13
  70. package/lib/managers/file.js +0 -134
  71. package/lib/managers/gitpod.d.ts +0 -3
  72. package/lib/managers/gitpod.js +0 -67
  73. package/lib/managers/server/index.d.ts +0 -6
  74. package/lib/managers/server/index.js +0 -58
  75. package/lib/managers/server/routes.d.ts +0 -4
  76. package/lib/managers/server/routes.js +0 -167
  77. package/lib/managers/session.d.ts +0 -3
  78. package/lib/managers/session.js +0 -104
  79. package/lib/managers/socket.d.ts +0 -3
  80. package/lib/managers/socket.js +0 -164
  81. package/lib/managers/test.d.ts +0 -0
  82. package/lib/managers/test.js +0 -84
  83. package/lib/models/action.d.ts +0 -2
  84. package/lib/models/action.js +0 -2
  85. package/lib/models/audit.d.ts +0 -15
  86. package/lib/models/audit.js +0 -2
  87. package/lib/models/config-manager.d.ts +0 -21
  88. package/lib/models/config-manager.js +0 -2
  89. package/lib/models/config.d.ts +0 -62
  90. package/lib/models/config.js +0 -2
  91. package/lib/models/counter.d.ts +0 -11
  92. package/lib/models/counter.js +0 -2
  93. package/lib/models/errors.d.ts +0 -15
  94. package/lib/models/errors.js +0 -2
  95. package/lib/models/exercise-obj.d.ts +0 -27
  96. package/lib/models/exercise-obj.js +0 -2
  97. package/lib/models/file.d.ts +0 -5
  98. package/lib/models/file.js +0 -2
  99. package/lib/models/findings.d.ts +0 -17
  100. package/lib/models/findings.js +0 -2
  101. package/lib/models/flags.d.ts +0 -10
  102. package/lib/models/flags.js +0 -2
  103. package/lib/models/front-matter.d.ts +0 -11
  104. package/lib/models/front-matter.js +0 -2
  105. package/lib/models/gitpod-data.d.ts +0 -16
  106. package/lib/models/gitpod-data.js +0 -2
  107. package/lib/models/language.d.ts +0 -4
  108. package/lib/models/language.js +0 -2
  109. package/lib/models/package.d.ts +0 -7
  110. package/lib/models/package.js +0 -2
  111. package/lib/models/plugin-config.d.ts +0 -16
  112. package/lib/models/plugin-config.js +0 -2
  113. package/lib/models/session.d.ts +0 -23
  114. package/lib/models/session.js +0 -2
  115. package/lib/models/socket.d.ts +0 -31
  116. package/lib/models/socket.js +0 -2
  117. package/lib/models/status.d.ts +0 -1
  118. package/lib/models/status.js +0 -2
  119. package/lib/models/success-types.d.ts +0 -1
  120. package/lib/models/success-types.js +0 -2
  121. package/lib/plugin/command/compile.d.ts +0 -6
  122. package/lib/plugin/command/compile.js +0 -18
  123. package/lib/plugin/command/test.d.ts +0 -6
  124. package/lib/plugin/command/test.js +0 -25
  125. package/lib/plugin/index.d.ts +0 -27
  126. package/lib/plugin/index.js +0 -7
  127. package/lib/plugin/plugin.d.ts +0 -8
  128. package/lib/plugin/plugin.js +0 -68
  129. package/lib/plugin/utils.d.ts +0 -16
  130. package/lib/plugin/utils.js +0 -58
  131. package/lib/ui/download.d.ts +0 -5
  132. package/lib/ui/download.js +0 -61
  133. package/lib/utils/BaseCommand.d.ts +0 -8
  134. package/lib/utils/BaseCommand.js +0 -41
  135. package/lib/utils/SessionCommand.d.ts +0 -10
  136. package/lib/utils/SessionCommand.js +0 -47
  137. package/lib/utils/api.d.ts +0 -12
  138. package/lib/utils/api.js +0 -173
  139. package/lib/utils/audit.d.ts +0 -16
  140. package/lib/utils/audit.js +0 -302
  141. package/lib/utils/console.d.ts +0 -12
  142. package/lib/utils/console.js +0 -19
  143. package/lib/utils/errors.d.ts +0 -17
  144. package/lib/utils/errors.js +0 -100
  145. package/lib/utils/exercisesQueue.d.ts +0 -9
  146. package/lib/utils/exercisesQueue.js +0 -38
  147. package/lib/utils/fileQueue.d.ts +0 -40
  148. package/lib/utils/fileQueue.js +0 -168
  149. package/lib/utils/misc.d.ts +0 -1
  150. package/lib/utils/misc.js +0 -23
  151. package/lib/utils/validators.d.ts +0 -5
  152. package/lib/utils/validators.js +0 -17
  153. package/lib/utils/watcher.d.ts +0 -2
  154. package/lib/utils/watcher.js +0 -23
@@ -1,15 +0,0 @@
1
- export interface ISolution {
2
- video?: string;
3
- message: string;
4
- slug?: string;
5
- gif: string;
6
- }
7
- export interface IError extends TypeError {
8
- status?: number;
9
- type?: "validation-error" | "not-found-error" | "compiler-error" | "testing-error" | "auth-error" | "internal-error";
10
- slug?: string;
11
- video?: string;
12
- message: string;
13
- gif?: string;
14
- stdout?: string;
15
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +0,0 @@
1
- /// <reference types="node" />
2
- import { IFile } from "./file";
3
- import { IConfig } from "./config";
4
- import { ISocket } from "./socket";
5
- export interface IExercise {
6
- position?: number;
7
- files: Array<IFile>;
8
- slug: string;
9
- path: string;
10
- done: boolean;
11
- language?: string | null;
12
- entry?: string | null;
13
- graded?: boolean;
14
- translations?: {
15
- [key: string]: string;
16
- };
17
- title: string;
18
- getReadme?: (lang: string | null) => any;
19
- getFile?: (name: string) => string | Buffer;
20
- saveFile?: (name: string, content: string) => void;
21
- getTestReport?: () => any;
22
- test?: (sessionConfig: any, config: IConfig, socket: ISocket) => void;
23
- }
24
- export interface IExerciseData {
25
- exerciseSlug: string;
26
- files: string[];
27
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- export interface IFile {
2
- path: string;
3
- name: string;
4
- hidden: boolean;
5
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,17 +0,0 @@
1
- interface IFindingOption {
2
- content: string;
3
- absUrl: string;
4
- mdUrl: string;
5
- relUrl: string;
6
- }
7
- interface ILinks {
8
- [key: string]: IFindingOption;
9
- }
10
- export interface IFindings {
11
- relativeImages?: ILinks;
12
- externalImages?: ILinks;
13
- markdownLinks?: ILinks;
14
- url?: ILinks;
15
- uploadcare?: ILinks;
16
- }
17
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- export interface IStartFlags {
2
- port?: string | unknown;
3
- host?: string | unknown;
4
- disableGrading?: boolean | unknown;
5
- watch?: boolean | unknown;
6
- editor?: string | unknown;
7
- version?: string | unknown;
8
- grading?: string | unknown;
9
- debug?: boolean | unknown;
10
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- interface IAttributes {
2
- intro: string;
3
- tutorial: string;
4
- }
5
- export interface IFrontmatter {
6
- attributes?: IAttributes;
7
- body?: string;
8
- bodyBegin?: number;
9
- frontmatter?: string;
10
- }
11
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import { Server } from 'socket.io';
2
- import { IConfigObj } from './config';
3
- export declare type TFile = string;
4
- export interface IGitpodData {
5
- files: Array<TFile>;
6
- }
7
- export interface IGitpod {
8
- socket: Server | null;
9
- config: IConfigObj | null;
10
- initialized: boolean;
11
- hasGPCommand: boolean;
12
- init: (config?: IConfigObj) => void;
13
- openFiles: (files: Array<TFile>) => Promise<boolean | undefined>;
14
- setup: (config?: IConfigObj) => void;
15
- autosave: (value: string) => void;
16
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- export interface ILanguage {
2
- title: string;
3
- slug: string;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- export interface IPackage {
2
- title: string;
3
- slug: string;
4
- difficulty: string;
5
- downloads: string;
6
- skills: Array<any>;
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- import { IConfig } from "./config";
2
- import { IExercise } from "./exercise-obj";
3
- export interface IPluginConfig {
4
- language: string;
5
- compile?: {
6
- run: () => void;
7
- validate: (args: IValidate) => boolean;
8
- dependencies: string[];
9
- };
10
- test?: () => void;
11
- }
12
- interface IValidate {
13
- exercise: IExercise;
14
- configuration: IConfig;
15
- }
16
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +0,0 @@
1
- import { IConfig, IConfigObj } from './config';
2
- export interface IPayload {
3
- email: string;
4
- }
5
- export interface IStartProps {
6
- token: string;
7
- payload: IPayload | null;
8
- }
9
- export interface ISession {
10
- sessionStarted: boolean;
11
- token: string | null;
12
- config: IConfig | null;
13
- currentCohort: null;
14
- initialize: () => Promise<boolean>;
15
- setPayload: (value: IPayload) => Promise<boolean>;
16
- getPayload: () => Promise<any>;
17
- isActive: () => boolean;
18
- get: (config?: IConfigObj) => Promise<any>;
19
- login: () => Promise<void>;
20
- sync: () => Promise<void>;
21
- start: ({ token, payload }: IStartProps) => Promise<void>;
22
- destroy: () => Promise<void>;
23
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,31 +0,0 @@
1
- import { IConfig } from './config';
2
- import { Server } from 'socket.io';
3
- import { DefaultEventsMap } from 'socket.io/dist/typed-events';
4
- import { TAction, ICallback } from './action';
5
- import { TStatus } from './status';
6
- export declare type TPossibleActions = 'build' | 'test' | 'reset' | 'tutorial';
7
- export interface ISocket {
8
- socket: Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any> | null;
9
- config: IConfig | null;
10
- allowedActions: Array<TPossibleActions>;
11
- actionCallBacks: {
12
- [key: string]: ICallback;
13
- };
14
- possibleActions: Array<TPossibleActions>;
15
- isTestingEnvironment: boolean;
16
- addAllowed: (actions: any) => void;
17
- removeAllowed: (actions: any) => void;
18
- start: (config: IConfig, server: any, isTestingEnvironment: boolean) => void;
19
- on: (action: any, callBack: any) => void;
20
- clean: (_: string, logs: Array<any>) => void;
21
- ask: (questions: Array<string>) => void;
22
- reload: (files: Array<string> | null, exercises: Array<string>) => void;
23
- openWindow: (id: string) => void;
24
- log: (status: TStatus, messages?: string | Array<string>, report?: Array<string>, data?: any) => void;
25
- emit: (action: TAction, status: TStatus | string, logs: string | Array<string>, inputs?: Array<string>, report?: Array<string>, data?: any) => void;
26
- ready: (message: string) => void;
27
- error: (type: any, stdout: string) => void;
28
- fatal: (msg: string) => void;
29
- success: (type: any, stdout: string) => void;
30
- onTestingFinished: (obj: any) => void;
31
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare type TStatus = 'ready' | 'internal-error' | 'compiler-success' | 'testing-success' | 'compiling' | 'testing' | 'start_exercise' | 'initializing' | 'configuration_loaded' | 'connection_ended' | 'reset_exercise' | 'open_files' | 'open_window' | 'instructions_closed';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- export declare type TSuccessType = 'compiler-success' | 'testing-success';
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- import { IError } from "../../models/errors";
2
- declare const _default: {
3
- CompilationError: (messages: string) => IError;
4
- default: ({ action, ...rest }: any) => Promise<any>;
5
- };
6
- export default _default;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const CompilationError = (messages) => {
5
- const _err = new Error(messages);
6
- _err.status = 400;
7
- _err.stdout = messages;
8
- _err.type = "compiler-error";
9
- return _err;
10
- };
11
- exports.default = {
12
- CompilationError,
13
- default: async (_a) => {
14
- var { action } = _a, rest = tslib_1.__rest(_a, ["action"]);
15
- const stdout = await action.run(rest);
16
- return stdout;
17
- },
18
- };
@@ -1,6 +0,0 @@
1
- import { IError } from "../../models/errors";
2
- declare const _default: {
3
- TestingError: (messages: string) => IError;
4
- default: (args: any) => Promise<any>;
5
- };
6
- export default _default;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs = require("fs");
4
- const TestingError = (messages) => {
5
- const _err = new Error(messages);
6
- _err.status = 400;
7
- _err.stdout = messages;
8
- _err.type = "testing-error";
9
- return _err;
10
- };
11
- exports.default = {
12
- TestingError,
13
- default: async function (args) {
14
- const { action, configuration, socket, exercise } = args;
15
- if (!fs.existsSync(`${configuration.dirPath}/reports`)) {
16
- // reports directory
17
- fs.mkdirSync(`${configuration.dirPath}/reports`);
18
- }
19
- // compile
20
- const stdout = await action.run(args);
21
- // mark exercise as done
22
- exercise.done = true;
23
- return stdout;
24
- },
25
- };
@@ -1,27 +0,0 @@
1
- declare const _default: {
2
- CompilationError: {
3
- CompilationError: (messages: string) => import("../models/errors").IError;
4
- default: ({ action, ...rest }: any) => Promise<any>;
5
- };
6
- TestingError: {
7
- TestingError: (messages: string) => import("../models/errors").IError;
8
- default: (args: any) => Promise<any>;
9
- };
10
- Utils: {
11
- getMatches: (reg: RegExp, content: string) => (string | null)[];
12
- cleanStdout: (buffer: string, inputs: string[]) => string;
13
- indent: (string: string, options: any, count?: number) => string;
14
- Console: {
15
- _debug: boolean;
16
- startDebug: () => void;
17
- log: (msg: string, ...args: any[]) => void;
18
- error: (msg: string, ...args: any[]) => void;
19
- success: (msg: string, ...args: any[]) => void;
20
- info: (msg: string, ...args: any[]) => void;
21
- help: (msg: string) => void;
22
- debug(...args: any[]): void;
23
- };
24
- };
25
- plugin: (pluginConfig: import("../models/plugin-config").IPluginConfig) => (args: any) => Promise<any>;
26
- };
27
- export default _default;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const compile_1 = require("./command/compile");
4
- const test_1 = require("./command/test");
5
- const utils_1 = require("./utils");
6
- const plugin_1 = require("./plugin");
7
- exports.default = { CompilationError: compile_1.default, TestingError: test_1.default, Utils: utils_1.default, plugin: plugin_1.default };
@@ -1,8 +0,0 @@
1
- import { IPluginConfig } from "../models/plugin-config";
2
- declare const _default: (pluginConfig: IPluginConfig) => (args: any) => Promise<any>;
3
- /**
4
- * Main Plugin Runner, it defines the behavior of a learnpack plugin
5
- * dividing it in "actions" like: Compile, test, etc.
6
- * @param {object} pluginConfig Configuration object that must defined language and each possible action.
7
- */
8
- export default _default;
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const shell = require("shelljs");
4
- /**
5
- * Main Plugin Runner, it defines the behavior of a learnpack plugin
6
- * dividing it in "actions" like: Compile, test, etc.
7
- * @param {object} pluginConfig Configuration object that must defined language and each possible action.
8
- */
9
- exports.default = (pluginConfig) => {
10
- return async (args) => {
11
- const { action, exercise, socket, configuration } = args;
12
- if (pluginConfig.language === undefined)
13
- throw new Error(`Missing language on the plugin configuration object`);
14
- if (typeof action !== "string") {
15
- throw new TypeError("Missing action property on hook details");
16
- }
17
- if (!exercise || exercise === undefined) {
18
- throw new Error("Missing exercise information");
19
- }
20
- // if the action does not exist I don't do anything
21
- if (pluginConfig[action] === undefined) {
22
- console.log(`Ignoring ${action}`);
23
- return () => null;
24
- }
25
- // ignore if the plugin language its not the same as the exercise language
26
- if (exercise.language !== pluginConfig.language) {
27
- return () => null;
28
- }
29
- if (!exercise.files || exercise.files.length === 0) {
30
- throw new Error(`No files to process`);
31
- }
32
- try {
33
- const _action = pluginConfig[action];
34
- if (_action === null || typeof _action !== "object")
35
- throw new Error(`The ${pluginConfig.language} ${action} module must export an object configuration`);
36
- if (_action.validate === undefined)
37
- throw new Error(`Missing validate method for ${pluginConfig.language} ${action}`);
38
- if (_action.run === undefined)
39
- throw new Error(`Missing run method for ${pluginConfig.language} ${action}`);
40
- if (_action.dependencies !== undefined) {
41
- if (!Array.isArray(_action.dependencies))
42
- throw new Error(`${action}.dependencies must be an array of package names`);
43
- for (const packageName of _action.dependencies) {
44
- if (!shell.which(packageName)) {
45
- throw new Error(`🚫 You need to have ${packageName} installed to run test the exercises`);
46
- }
47
- }
48
- }
49
- const valid = await _action.validate({ exercise, configuration });
50
- if (valid) {
51
- // look for the command standard implementation and execute it
52
- const execute = require("./command/" + action + ".js").default;
53
- // no matter the command, the response must always be a stdout
54
- const stdout = await execute(Object.assign(Object.assign({}, args), { action: _action, configuration }));
55
- // Map the action names to socket messaging standards
56
- const actionToSuccessMapper = { compile: "compiler", test: "testing" };
57
- socket.success(actionToSuccessMapper[action], stdout);
58
- return stdout;
59
- }
60
- }
61
- catch (error) {
62
- if (error.type === undefined)
63
- socket.fatal(error);
64
- else
65
- socket.error(error.type, error.stdout);
66
- }
67
- };
68
- };
@@ -1,16 +0,0 @@
1
- declare const _default: {
2
- getMatches: (reg: RegExp, content: string) => (string | null)[];
3
- cleanStdout: (buffer: string, inputs: string[]) => string;
4
- indent: (string: string, options: any, count?: number) => string;
5
- Console: {
6
- _debug: boolean;
7
- startDebug: () => void;
8
- log: (msg: string, ...args: any[]) => void;
9
- error: (msg: string, ...args: any[]) => void;
10
- success: (msg: string, ...args: any[]) => void;
11
- info: (msg: string, ...args: any[]) => void;
12
- help: (msg: string) => void;
13
- debug(...args: any[]): void;
14
- };
15
- };
16
- export default _default;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chalk = require("chalk");
4
- const getMatches = (reg, content) => {
5
- const inputs = [];
6
- let m;
7
- while ((m = reg.exec(content)) !== null) {
8
- // This is necessary to avoid infinite loops with zero-width matches
9
- if (m.index === reg.lastIndex)
10
- reg.lastIndex++;
11
- // The result can be accessed through the `m`-variable.
12
- inputs.push(m[1] || null);
13
- }
14
- return inputs;
15
- };
16
- const cleanStdout = (buffer, inputs) => {
17
- if (Array.isArray(inputs))
18
- for (let i = 0; i < inputs.length; i++)
19
- if (inputs[i])
20
- buffer = buffer.replace(inputs[i], "");
21
- return buffer;
22
- };
23
- const indent = (string, options, count = 1) => {
24
- options = Object.assign({ indent: " ", includeEmptyLines: false }, options);
25
- if (typeof string !== "string") {
26
- throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof string}\``);
27
- }
28
- if (typeof count !== "number") {
29
- throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
30
- }
31
- if (count < 0) {
32
- throw new RangeError(`Expected \`count\` to be at least 0, got \`${count}\``);
33
- }
34
- if (typeof options.indent !== "string") {
35
- throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``);
36
- }
37
- if (count === 0) {
38
- return string;
39
- }
40
- const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
41
- return string.replace(regex, options.indent.repeat(count));
42
- };
43
- const Console = {
44
- // _debug: true,
45
- _debug: process.env.DEBUG === "true",
46
- startDebug: function () {
47
- this._debug = true;
48
- },
49
- log: (msg, ...args) => console.log(chalk.gray(msg), ...args),
50
- error: (msg, ...args) => console.log(chalk.red("⨉ " + msg), ...args),
51
- success: (msg, ...args) => console.log(chalk.green("✓ " + msg), ...args),
52
- info: (msg, ...args) => console.log(chalk.blue("ⓘ " + msg), ...args),
53
- help: (msg) => console.log(`${chalk.white.bold("⚠ help:")} ${chalk.white(msg)}`),
54
- debug(...args) {
55
- this._debug && console.log(chalk.magentaBright(`⚠ debug: `), args);
56
- },
57
- };
58
- exports.default = { getMatches, cleanStdout, indent, Console };
@@ -1,5 +0,0 @@
1
- export declare const askPackage: () => Promise<unknown>;
2
- declare const _default: {
3
- askPackage: () => Promise<unknown>;
4
- };
5
- export default _default;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.askPackage = void 0;
4
- const enquirer_1 = require("enquirer");
5
- const console_1 = require("../utils/console");
6
- const api_1 = require("../utils/api");
7
- exports.askPackage = async () => {
8
- console_1.default.info('No package was specified');
9
- const languages = await api_1.default.getLangs();
10
- return new Promise((resolve, reject) => {
11
- if (languages.length === 0) {
12
- // reject(new Error('No categories available'))
13
- reject('No categories available');
14
- // return null;
15
- }
16
- // let packages = []
17
- enquirer_1.prompt([
18
- {
19
- type: 'select',
20
- name: 'lang',
21
- message: 'What language do you want to practice?',
22
- choices: languages.map((l) => ({
23
- message: l.title,
24
- name: l.slug,
25
- })),
26
- },
27
- ])
28
- .then(({ lang }) => {
29
- return (async () => {
30
- const response = await api_1.default.getAllPackages({ lang });
31
- const packages = response.results;
32
- if (packages.length === 0) {
33
- const error = new Error(`No packages found for language ${lang}`);
34
- console_1.default.error(error.message); // TODO: Look this
35
- return error;
36
- }
37
- return enquirer_1.prompt([
38
- {
39
- type: 'select',
40
- name: 'pack',
41
- message: 'Choose one of the packages available',
42
- choices: packages.map((l) => ({
43
- message: `${l.title}, difficulty: ${l.difficulty}, downloads: ${l.downloads} ${l.skills.length > 0 ? `(Skills: ${l.skills.join(',')})` : ''}`,
44
- name: l.slug,
45
- })),
46
- },
47
- ]);
48
- })();
49
- })
50
- .then((resp) => {
51
- if (!resp)
52
- reject(resp.message || resp);
53
- else
54
- resolve(resp.pack);
55
- })
56
- .catch(error => {
57
- console_1.default.error(error.message || error);
58
- });
59
- });
60
- };
61
- exports.default = { askPackage: exports.askPackage };
@@ -1,8 +0,0 @@
1
- import { Command } from "@oclif/command";
2
- declare class BaseCommand extends Command {
3
- catch(err: any): Promise<void>;
4
- init(): Promise<void>;
5
- finally(): Promise<void>;
6
- run(): Promise<void>;
7
- }
8
- export default BaseCommand;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const command_1 = require("@oclif/command");
4
- const console_1 = require("./console");
5
- const readline_1 = require("readline");
6
- // import SessionManager from '../managers/session'
7
- class BaseCommand extends command_1.Command {
8
- async catch(err) {
9
- console_1.default.debug("COMMAND CATCH", err);
10
- throw err;
11
- }
12
- async init() {
13
- const { flags, args } = this.parse(BaseCommand);
14
- console_1.default.debug("COMMAND INIT");
15
- console_1.default.debug("These are your flags: ", flags);
16
- console_1.default.debug("These are your args: ", args);
17
- // quick fix for listening to the process termination on windows
18
- if (process.platform === "win32") {
19
- const rl = readline_1.createInterface({
20
- input: process.stdin,
21
- output: process.stdout,
22
- });
23
- rl.on("SIGINT", function () {
24
- // process.emit('SIGINT')
25
- // process.emit('SIGINT')
26
- });
27
- }
28
- process.on("SIGINT", function () {
29
- console_1.default.debug("Terminated (SIGINT)");
30
- process.exit();
31
- });
32
- }
33
- async finally() {
34
- console_1.default.debug("COMMAND FINALLY");
35
- // called after run and catch regardless of whether or not the command errored
36
- }
37
- async run() {
38
- // console.log('running my command')
39
- }
40
- }
41
- exports.default = BaseCommand;
@@ -1,10 +0,0 @@
1
- import BaseCommand from './BaseCommand';
2
- import { IConfigManager } from '../models/config-manager';
3
- export default class SessionCommand extends BaseCommand {
4
- session: any;
5
- configManager: IConfigManager | null;
6
- static flags: any;
7
- initSession(flags: any, _private?: boolean): Promise<void>;
8
- buildConfig(flags: any): Promise<void>;
9
- catch(err: any): Promise<void>;
10
- }