@learnpack/learnpack 5.0.6 → 5.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +17 -17
  2. package/bin/run +17 -17
  3. package/bin/run.cmd +3 -3
  4. package/lib/commands/audit.js +30 -21
  5. package/lib/commands/clean.js +3 -3
  6. package/lib/commands/download.js +3 -3
  7. package/lib/commands/init.js +29 -4
  8. package/lib/commands/login.js +3 -3
  9. package/lib/commands/logout.js +3 -3
  10. package/lib/utils/rigoActions.d.ts +5 -0
  11. package/lib/utils/rigoActions.js +15 -1
  12. package/oclif.manifest.json +1 -1
  13. package/package.json +152 -152
  14. package/src/commands/audit.ts +449 -443
  15. package/src/commands/clean.ts +29 -29
  16. package/src/commands/download.ts +61 -61
  17. package/src/commands/init.ts +40 -12
  18. package/src/commands/login.ts +42 -42
  19. package/src/commands/logout.ts +43 -43
  20. package/src/commands/test.ts +85 -85
  21. package/src/index.ts +1 -1
  22. package/src/managers/config/allowed_files.ts +29 -29
  23. package/src/managers/gitpod.ts +84 -84
  24. package/src/managers/server/index.ts +78 -78
  25. package/src/managers/telemetry.ts +353 -353
  26. package/src/managers/test.ts +83 -83
  27. package/src/models/audit.ts +16 -16
  28. package/src/models/config-manager.ts +23 -23
  29. package/src/models/counter.ts +11 -11
  30. package/src/models/errors.ts +22 -22
  31. package/src/models/exercise-obj.ts +29 -29
  32. package/src/models/file.ts +5 -5
  33. package/src/models/findings.ts +18 -18
  34. package/src/models/flags.ts +10 -10
  35. package/src/models/front-matter.ts +11 -11
  36. package/src/models/gitpod-data.ts +19 -19
  37. package/src/models/language.ts +4 -4
  38. package/src/models/package.ts +7 -7
  39. package/src/models/plugin-config.ts +17 -17
  40. package/src/models/success-types.ts +1 -1
  41. package/src/plugin/command/compile.ts +17 -17
  42. package/src/plugin/command/test.ts +30 -30
  43. package/src/plugin/index.ts +6 -6
  44. package/src/plugin/plugin.ts +94 -94
  45. package/src/plugin/utils.ts +87 -87
  46. package/src/types/node-fetch.d.ts +1 -1
  47. package/src/ui/download.ts +71 -71
  48. package/src/utils/BaseCommand.ts +48 -48
  49. package/src/utils/SessionCommand.ts +43 -43
  50. package/src/utils/audit.ts +393 -393
  51. package/src/utils/errors.ts +117 -117
  52. package/src/utils/exercisesQueue.ts +51 -51
  53. package/src/utils/fileQueue.ts +199 -199
  54. package/src/utils/misc.ts +23 -23
  55. package/src/utils/osOperations.ts +79 -79
  56. package/src/utils/rigoActions.ts +27 -0
  57. package/src/utils/templates/gitignore.txt +19 -19
  58. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
  59. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
  60. package/src/utils/templates/incremental/.vscode/schema.json +121 -121
  61. package/src/utils/templates/incremental/.vscode/settings.json +13 -13
  62. package/src/utils/templates/incremental/README.ejs +4 -4
  63. package/src/utils/templates/incremental/README.es.ejs +4 -4
  64. package/src/utils/templates/isolated/.vscode/schema.json +121 -121
  65. package/src/utils/templates/isolated/.vscode/settings.json +13 -13
  66. package/src/utils/templates/isolated/README.ejs +4 -4
  67. package/src/utils/templates/isolated/README.es.ejs +4 -4
  68. package/src/utils/templates/no-grading/README.ejs +4 -4
  69. package/src/utils/templates/no-grading/README.es.ejs +4 -4
  70. package/src/utils/validators.ts +18 -18
  71. package/src/utils/watcher.ts +27 -27
@@ -1,83 +1,83 @@
1
- /*
2
-
3
- import * as path from 'path'
4
- import * as shell from 'shelljs'
5
- import * as fs from 'fs'
6
- import { TestingError } from './errors'
7
- import Console from '../utils/console'
8
- import * as color from 'colors'
9
- import bcActivity from './bcActivity.js'
10
- import { CompilerError } from '../utils/errors'
11
- import { ISocket } from '../models/socket'
12
- import { IFile } from '../models/file'
13
- import { IConfig } from '@oclif/config'
14
-
15
- module.exports = async function ({ socket, files, config, slug }: {socket: ISocket, files: IFile[], config: IConfig, slug: string}) {
16
-
17
- const configPath = path.resolve(__dirname, `./config/tester/${config.tester}/${config.language}.config.js`);
18
- if (!fs.existsSync(configPath)) throw CompilerError(`Uknown testing engine for compiler: '${config.language}'`);
19
-
20
- const testingConfig = require(configPath)(files, config, slug);
21
- testingConfig.validate();
22
-
23
- if (config.ignoreTests) throw TestingError('Grading is disabled on learn.json file.');
24
-
25
- if (!fs.existsSync(`${config.dirPath}/reports`)) {
26
- fs.mkdirSync(`${config.dirPath}/reports`);
27
- Console.debug(`Creating the ${config.dirPath}/reports directory`);
28
- }
29
-
30
- Console.info('Running tests...');
31
-
32
- const command = await testingConfig.getCommand(socket)
33
- const { stdout, stderr, code } = shell.exec(command);
34
-
35
- if (code != 0) {
36
- const errors = typeof (testingConfig.getErrors === 'function') ? testingConfig.getErrors(stdout || stderr) : [];
37
- socket.log('testing-error', errors);
38
- console.log(errors.join('\n'))
39
-
40
- Console.error("There was an error while testing");
41
- bcActivity.error('exercise_error', {
42
- message: errors,
43
- name: `${config.tester}-error`,
44
- framework: config.tester,
45
- language: config.language,
46
- data: slug,
47
- compiler: config.compiler
48
- });
49
- }
50
- else {
51
- socket.log('testing-success', [stdout || stderr].concat(["😁Everything is amazing!"]));
52
- Console.success("Everything is amazing!");
53
-
54
- bcActivity.activity('exercise_success', {
55
- language: config.language,
56
- slug: slug,
57
- editor: config.editor,
58
- compiler: config.compiler
59
- });
60
- config.exercises = config.exercises.map(e => {
61
- if (e.slug === slug) e.done = true;
62
- return e;
63
- });
64
- }
65
-
66
- if (typeof testingConfig.cleanup !== "undefined") {
67
- if (typeof testingConfig.cleanup === 'function' || typeof testingConfig.cleanup === 'object') {
68
- const clean = await testingConfig.cleanup(socket);
69
- if (clean) {
70
- const { stdout, stderr, code } = shell.exec(clean);
71
- if (code == 0) {
72
- Console.debug("The cleanup command runned successfully");
73
- }
74
- else Console.warning("There is an error on the cleanup command for the test");
75
- }
76
-
77
- }
78
- }
79
-
80
- return true;
81
- };
82
-
83
- */
1
+ /*
2
+
3
+ import * as path from 'path'
4
+ import * as shell from 'shelljs'
5
+ import * as fs from 'fs'
6
+ import { TestingError } from './errors'
7
+ import Console from '../utils/console'
8
+ import * as color from 'colors'
9
+ import bcActivity from './bcActivity.js'
10
+ import { CompilerError } from '../utils/errors'
11
+ import { ISocket } from '../models/socket'
12
+ import { IFile } from '../models/file'
13
+ import { IConfig } from '@oclif/config'
14
+
15
+ module.exports = async function ({ socket, files, config, slug }: {socket: ISocket, files: IFile[], config: IConfig, slug: string}) {
16
+
17
+ const configPath = path.resolve(__dirname, `./config/tester/${config.tester}/${config.language}.config.js`);
18
+ if (!fs.existsSync(configPath)) throw CompilerError(`Uknown testing engine for compiler: '${config.language}'`);
19
+
20
+ const testingConfig = require(configPath)(files, config, slug);
21
+ testingConfig.validate();
22
+
23
+ if (config.ignoreTests) throw TestingError('Grading is disabled on learn.json file.');
24
+
25
+ if (!fs.existsSync(`${config.dirPath}/reports`)) {
26
+ fs.mkdirSync(`${config.dirPath}/reports`);
27
+ Console.debug(`Creating the ${config.dirPath}/reports directory`);
28
+ }
29
+
30
+ Console.info('Running tests...');
31
+
32
+ const command = await testingConfig.getCommand(socket)
33
+ const { stdout, stderr, code } = shell.exec(command);
34
+
35
+ if (code != 0) {
36
+ const errors = typeof (testingConfig.getErrors === 'function') ? testingConfig.getErrors(stdout || stderr) : [];
37
+ socket.log('testing-error', errors);
38
+ console.log(errors.join('\n'))
39
+
40
+ Console.error("There was an error while testing");
41
+ bcActivity.error('exercise_error', {
42
+ message: errors,
43
+ name: `${config.tester}-error`,
44
+ framework: config.tester,
45
+ language: config.language,
46
+ data: slug,
47
+ compiler: config.compiler
48
+ });
49
+ }
50
+ else {
51
+ socket.log('testing-success', [stdout || stderr].concat(["😁Everything is amazing!"]));
52
+ Console.success("Everything is amazing!");
53
+
54
+ bcActivity.activity('exercise_success', {
55
+ language: config.language,
56
+ slug: slug,
57
+ editor: config.editor,
58
+ compiler: config.compiler
59
+ });
60
+ config.exercises = config.exercises.map(e => {
61
+ if (e.slug === slug) e.done = true;
62
+ return e;
63
+ });
64
+ }
65
+
66
+ if (typeof testingConfig.cleanup !== "undefined") {
67
+ if (typeof testingConfig.cleanup === 'function' || typeof testingConfig.cleanup === 'object') {
68
+ const clean = await testingConfig.cleanup(socket);
69
+ if (clean) {
70
+ const { stdout, stderr, code } = shell.exec(clean);
71
+ if (code == 0) {
72
+ Console.debug("The cleanup command runned successfully");
73
+ }
74
+ else Console.warning("There is an error on the cleanup command for the test");
75
+ }
76
+
77
+ }
78
+ }
79
+
80
+ return true;
81
+ };
82
+
83
+ */
@@ -1,16 +1,16 @@
1
- export interface IAuditErrors {
2
- exercise?: string;
3
- msg: string;
4
- }
5
-
6
- type TType = "string" | "array" | "number" | "url" | "boolean";
7
-
8
- export interface ISchemaItem {
9
- key: string;
10
- mandatory: boolean;
11
- type: TType;
12
- max_size?: number;
13
- allowed_extensions?: string[];
14
- enum?: string[];
15
- max_item_size?: number;
16
- }
1
+ export interface IAuditErrors {
2
+ exercise?: string;
3
+ msg: string;
4
+ }
5
+
6
+ type TType = "string" | "array" | "number" | "url" | "boolean";
7
+
8
+ export interface ISchemaItem {
9
+ key: string;
10
+ mandatory: boolean;
11
+ type: TType;
12
+ max_size?: number;
13
+ allowed_extensions?: string[];
14
+ enum?: string[];
15
+ max_item_size?: number;
16
+ }
@@ -1,23 +1,23 @@
1
- import { IConfigObj, TGrading } from "./config"
2
- import { IExercise } from "./exercise-obj"
3
-
4
- export interface IConfigManagerAttributes {
5
- grading: TGrading;
6
- disableGrading: boolean;
7
- version: string;
8
- mode?: string;
9
- }
10
-
11
- export interface IConfigManager {
12
- validLanguages?: any;
13
- get: () => IConfigObj;
14
- clean: () => void;
15
- getExercise: (slug: string | undefined) => IExercise;
16
- startExercise: (slug: string) => IExercise;
17
- reset: (slug: string) => void;
18
- buildIndex: () => boolean | void;
19
- watchIndex: (onChange: (...args: Array<any>) => void) => void;
20
- save: () => void;
21
- noCurrentExercise: () => void;
22
- getAllExercises: () => IExercise[];
23
- }
1
+ import { IConfigObj, TGrading } from "./config"
2
+ import { IExercise } from "./exercise-obj"
3
+
4
+ export interface IConfigManagerAttributes {
5
+ grading: TGrading;
6
+ disableGrading: boolean;
7
+ version: string;
8
+ mode?: string;
9
+ }
10
+
11
+ export interface IConfigManager {
12
+ validLanguages?: any;
13
+ get: () => IConfigObj;
14
+ clean: () => void;
15
+ getExercise: (slug: string | undefined) => IExercise;
16
+ startExercise: (slug: string) => IExercise;
17
+ reset: (slug: string) => void;
18
+ buildIndex: () => boolean | void;
19
+ watchIndex: (onChange: (...args: Array<any>) => void) => void;
20
+ save: () => void;
21
+ noCurrentExercise: () => void;
22
+ getAllExercises: () => IExercise[];
23
+ }
@@ -1,11 +1,11 @@
1
- interface ILinks {
2
- error: number;
3
- total: number;
4
- }
5
-
6
- export interface ICounter {
7
- images: ILinks;
8
- links: ILinks;
9
- exercises: number;
10
- readmeFiles: number;
11
- }
1
+ interface ILinks {
2
+ error: number;
3
+ total: number;
4
+ }
5
+
6
+ export interface ICounter {
7
+ images: ILinks;
8
+ links: ILinks;
9
+ exercises: number;
10
+ readmeFiles: number;
11
+ }
@@ -1,22 +1,22 @@
1
- export interface ISolution {
2
- video?: string;
3
- message: string;
4
- slug?: string;
5
- gif: string;
6
- }
7
-
8
- export interface IError extends TypeError {
9
- status?: number;
10
- type?:
11
- | "validation-error"
12
- | "not-found-error"
13
- | "compiler-error"
14
- | "testing-error"
15
- | "auth-error"
16
- | "internal-error";
17
- slug?: string;
18
- video?: string;
19
- message: string;
20
- gif?: string;
21
- stdout?: string;
22
- }
1
+ export interface ISolution {
2
+ video?: string;
3
+ message: string;
4
+ slug?: string;
5
+ gif: string;
6
+ }
7
+
8
+ export interface IError extends TypeError {
9
+ status?: number;
10
+ type?:
11
+ | "validation-error"
12
+ | "not-found-error"
13
+ | "compiler-error"
14
+ | "testing-error"
15
+ | "auth-error"
16
+ | "internal-error";
17
+ slug?: string;
18
+ video?: string;
19
+ message: string;
20
+ gif?: string;
21
+ stdout?: string;
22
+ }
@@ -1,29 +1,29 @@
1
- import { IFile } from "./file"
2
- import { IConfig } from "./config"
3
- import { ISocket } from "./socket"
4
-
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?: { [key: string]: string };
15
- title: string;
16
- getReadme?: (lang: string | null) => any;
17
- getFile?: (name: string) => string | Buffer;
18
- saveFile?: (name: string, content: string) => void;
19
- getTestReport?: () => any;
20
- test?: (sessionConfig: any, config: IConfig, socket: ISocket) => void;
21
- }
22
-
23
- export interface IExerciseData {
24
- lastMessages?: any;
25
- userMessage?: string;
26
- exerciseSlug: string;
27
- entryPoint?: string;
28
- files: string[];
29
- }
1
+ import { IFile } from "./file"
2
+ import { IConfig } from "./config"
3
+ import { ISocket } from "./socket"
4
+
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?: { [key: string]: string };
15
+ title: string;
16
+ getReadme?: (lang: string | null) => any;
17
+ getFile?: (name: string) => string | Buffer;
18
+ saveFile?: (name: string, content: string) => void;
19
+ getTestReport?: () => any;
20
+ test?: (sessionConfig: any, config: IConfig, socket: ISocket) => void;
21
+ }
22
+
23
+ export interface IExerciseData {
24
+ lastMessages?: any;
25
+ userMessage?: string;
26
+ exerciseSlug: string;
27
+ entryPoint?: string;
28
+ files: string[];
29
+ }
@@ -1,5 +1,5 @@
1
- export interface IFile {
2
- path: string;
3
- name: string;
4
- hidden: boolean;
5
- }
1
+ export interface IFile {
2
+ path: string;
3
+ name: string;
4
+ hidden: boolean;
5
+ }
@@ -1,18 +1,18 @@
1
- interface IFindingOption {
2
- content: string;
3
- absUrl: string;
4
- mdUrl: string;
5
- relUrl: string;
6
- }
7
-
8
- interface ILinks {
9
- [key: string]: IFindingOption;
10
- }
11
-
12
- export interface IFindings {
13
- relativeImages?: ILinks;
14
- externalImages?: ILinks;
15
- markdownLinks?: ILinks;
16
- url?: ILinks;
17
- uploadcare?: ILinks;
18
- }
1
+ interface IFindingOption {
2
+ content: string;
3
+ absUrl: string;
4
+ mdUrl: string;
5
+ relUrl: string;
6
+ }
7
+
8
+ interface ILinks {
9
+ [key: string]: IFindingOption;
10
+ }
11
+
12
+ export interface IFindings {
13
+ relativeImages?: ILinks;
14
+ externalImages?: ILinks;
15
+ markdownLinks?: ILinks;
16
+ url?: ILinks;
17
+ uploadcare?: ILinks;
18
+ }
@@ -1,10 +1,10 @@
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
+ 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,11 +1,11 @@
1
- interface IAttributes {
2
- intro: string;
3
- tutorial: string;
4
- }
5
-
6
- export interface IFrontmatter {
7
- attributes?: IAttributes;
8
- body?: string;
9
- bodyBegin?: number;
10
- frontmatter?: string;
11
- }
1
+ interface IAttributes {
2
+ intro: string;
3
+ tutorial: string;
4
+ }
5
+
6
+ export interface IFrontmatter {
7
+ attributes?: IAttributes;
8
+ body?: string;
9
+ bodyBegin?: number;
10
+ frontmatter?: string;
11
+ }
@@ -1,19 +1,19 @@
1
- import {Server} from 'socket.io'
2
- import {IConfigObj} from './config'
3
-
4
- export type TFile = string;
5
-
6
- export interface IGitpodData {
7
- files: Array<TFile>;
8
- }
9
-
10
- export interface IGitpod {
11
- socket: Server | null;
12
- config: IConfigObj | null;
13
- initialized: boolean;
14
- hasGPCommand: boolean;
15
- init: (config?: IConfigObj) => void;
16
- openFiles: (files: Array<TFile>) => Promise<boolean | undefined>;
17
- setup: (config?: IConfigObj) => void;
18
- autosave: (value: string) => void;
19
- }
1
+ import {Server} from 'socket.io'
2
+ import {IConfigObj} from './config'
3
+
4
+ export type TFile = string;
5
+
6
+ export interface IGitpodData {
7
+ files: Array<TFile>;
8
+ }
9
+
10
+ export interface IGitpod {
11
+ socket: Server | null;
12
+ config: IConfigObj | null;
13
+ initialized: boolean;
14
+ hasGPCommand: boolean;
15
+ init: (config?: IConfigObj) => void;
16
+ openFiles: (files: Array<TFile>) => Promise<boolean | undefined>;
17
+ setup: (config?: IConfigObj) => void;
18
+ autosave: (value: string) => void;
19
+ }
@@ -1,4 +1,4 @@
1
- export interface ILanguage {
2
- title: string;
3
- slug: string;
4
- }
1
+ export interface ILanguage {
2
+ title: string;
3
+ slug: string;
4
+ }
@@ -1,7 +1,7 @@
1
- export interface IPackage {
2
- title: string;
3
- slug: string;
4
- difficulty: string;
5
- downloads: string;
6
- skills: Array<any>;
7
- }
1
+ export interface IPackage {
2
+ title: string;
3
+ slug: string;
4
+ difficulty: string;
5
+ downloads: string;
6
+ skills: Array<any>;
7
+ }
@@ -1,17 +1,17 @@
1
- import { IConfig } from "./config"
2
- import { IExercise } from "./exercise-obj"
3
-
4
- export interface IPluginConfig {
5
- language: string;
6
- compile?: {
7
- run: () => void;
8
- validate: (args: IValidate) => boolean;
9
- dependencies: string[];
10
- };
11
- test?: () => void;
12
- }
13
-
14
- interface IValidate {
15
- exercise: IExercise;
16
- configuration: IConfig;
17
- }
1
+ import { IConfig } from "./config"
2
+ import { IExercise } from "./exercise-obj"
3
+
4
+ export interface IPluginConfig {
5
+ language: string;
6
+ compile?: {
7
+ run: () => void;
8
+ validate: (args: IValidate) => boolean;
9
+ dependencies: string[];
10
+ };
11
+ test?: () => void;
12
+ }
13
+
14
+ interface IValidate {
15
+ exercise: IExercise;
16
+ configuration: IConfig;
17
+ }
@@ -1 +1 @@
1
- export type TSuccessType = 'compiler-success' | 'testing-success';
1
+ export type TSuccessType = 'compiler-success' | 'testing-success';
@@ -1,17 +1,17 @@
1
- import { IError } from "../../models/errors"
2
-
3
- const CompilationError = (messages: string) => {
4
- const _err: IError = new Error(messages)
5
- _err.status = 400
6
- _err.stdout = messages
7
- _err.type = "compiler-error"
8
- return _err
9
- }
10
-
11
- export default {
12
- CompilationError,
13
- default: async ({ action, ...rest }: any) => {
14
- const stdout = await action.run(rest)
15
- return stdout
16
- },
17
- }
1
+ import { IError } from "../../models/errors"
2
+
3
+ const CompilationError = (messages: string) => {
4
+ const _err: IError = new Error(messages)
5
+ _err.status = 400
6
+ _err.stdout = messages
7
+ _err.type = "compiler-error"
8
+ return _err
9
+ }
10
+
11
+ export default {
12
+ CompilationError,
13
+ default: async ({ action, ...rest }: any) => {
14
+ const stdout = await action.run(rest)
15
+ return stdout
16
+ },
17
+ }