@hubspot/cli 3.0.12 → 3.0.13-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/bin/cli.js +28 -2
  2. package/commands/accounts/use.js +82 -0
  3. package/commands/accounts.js +2 -0
  4. package/commands/config/set/allowUsageTracking.js +12 -19
  5. package/commands/config/set/defaultMode.js +11 -35
  6. package/commands/config/set/httpTimeout.js +27 -24
  7. package/commands/config/set.js +81 -13
  8. package/commands/logs.js +1 -7
  9. package/commands/module/marketplace-validate.js +77 -0
  10. package/commands/module.js +17 -0
  11. package/commands/project/logs.js +124 -60
  12. package/commands/project/open.js +75 -0
  13. package/commands/project.js +2 -0
  14. package/commands/sandbox/create.js +2 -2
  15. package/commands/sandbox.js +3 -1
  16. package/commands/theme/marketplace-validate.js +4 -2
  17. package/commands/upload.js +21 -10
  18. package/lib/projects.js +10 -7
  19. package/lib/prompts/personalAccessKeyPrompt.js +1 -1
  20. package/lib/prompts/projectNamePrompt.js +29 -0
  21. package/lib/prompts/projectsLogsPrompt.js +57 -0
  22. package/lib/serverlessLogs.js +25 -11
  23. package/lib/validators/__tests__/{BaseValidator.js → AbsoluteValidator.js} +3 -3
  24. package/lib/validators/__tests__/ModuleDependencyValidator.js +79 -0
  25. package/lib/validators/__tests__/ModuleValidator.js +22 -55
  26. package/lib/validators/__tests__/RelativeValidator.js +28 -0
  27. package/lib/validators/__tests__/TemplateValidator.js +1 -1
  28. package/lib/validators/__tests__/ThemeConfigValidator.js +1 -1
  29. package/lib/validators/__tests__/{DependencyValidator.js → ThemeDependencyValidator.js} +14 -12
  30. package/lib/validators/__tests__/ThemeModuleValidator.js +84 -0
  31. package/lib/validators/__tests__/validatorTestUtils.js +2 -0
  32. package/lib/validators/applyValidators.js +20 -4
  33. package/lib/validators/constants.js +4 -2
  34. package/lib/validators/index.js +8 -4
  35. package/lib/validators/marketplaceValidators/{BaseValidator.js → AbsoluteValidator.js} +8 -8
  36. package/lib/validators/marketplaceValidators/RelativeValidator.js +46 -0
  37. package/lib/validators/marketplaceValidators/module/ModuleDependencyValidator.js +101 -0
  38. package/lib/validators/marketplaceValidators/module/ModuleValidator.js +102 -0
  39. package/lib/validators/marketplaceValidators/theme/SectionValidator.js +2 -2
  40. package/lib/validators/marketplaceValidators/theme/TemplateValidator.js +2 -2
  41. package/lib/validators/marketplaceValidators/theme/ThemeConfigValidator.js +3 -3
  42. package/lib/validators/marketplaceValidators/theme/{DependencyValidator.js → ThemeDependencyValidator.js} +15 -12
  43. package/lib/validators/marketplaceValidators/theme/{ModuleValidator.js → ThemeModuleValidator.js} +5 -5
  44. package/package.json +4 -5
  45. package/bin/hubspot +0 -3
  46. package/commands/config/set/defaultAccount.js +0 -94
  47. package/commands/server.js +0 -80
  48. package/lib/server/updateContext.js +0 -105
@@ -1,5 +1,5 @@
1
1
  const https = require('https');
2
-
2
+ const Spinnies = require('spinnies');
3
3
  const { logger } = require('@hubspot/cli-lib/logger');
4
4
  const { outputLogs } = require('@hubspot/cli-lib/lib/logs');
5
5
  const {
@@ -8,18 +8,32 @@ const {
8
8
  ApiErrorContext,
9
9
  } = require('@hubspot/cli-lib/errorHandlers');
10
10
  const { base64EncodeString } = require('@hubspot/cli-lib/lib/encoding');
11
- const { handleKeypress } = require('@hubspot/cli-lib/lib/process');
11
+ const { handleExit, handleKeypress } = require('@hubspot/cli-lib/lib/process');
12
12
 
13
13
  const { EXIT_CODES } = require('../lib/enums/exitCodes');
14
14
 
15
15
  const TAIL_DELAY = 5000;
16
16
 
17
+ const handleUserInput = spinnies => {
18
+ const onTerminate = async () => {
19
+ spinnies.remove('tailLogs');
20
+ process.exit(EXIT_CODES.SUCCESS);
21
+ };
22
+
23
+ handleExit(onTerminate);
24
+ handleKeypress(key => {
25
+ if ((key.ctrl && key.name == 'c') || key.name === 'q') {
26
+ onTerminate();
27
+ }
28
+ });
29
+ };
30
+
17
31
  const tailLogs = async ({
18
32
  accountId,
19
33
  compact,
20
- spinnies,
21
34
  fetchLatest,
22
35
  tailCall,
36
+ name,
23
37
  }) => {
24
38
  let initialAfter;
25
39
 
@@ -44,7 +58,6 @@ const tailLogs = async ({
44
58
  latestLog = await tailCall(after);
45
59
  nextAfter = latestLog.paging.next.after;
46
60
  } catch (e) {
47
- spinnies.fail('tailLogs', { text: 'Stopped polling due to error.' });
48
61
  if (e.statusCode !== 404) {
49
62
  logApiErrorInstance(
50
63
  e,
@@ -62,18 +75,19 @@ const tailLogs = async ({
62
75
  });
63
76
  }
64
77
 
65
- setTimeout(() => {
66
- tail(nextAfter);
78
+ setTimeout(async () => {
79
+ await tail(nextAfter);
67
80
  }, TAIL_DELAY);
68
81
  };
69
82
 
70
- handleKeypress(key => {
71
- if ((key.ctrl && key.name == 'c') || key.name === 'escape') {
72
- spinnies.succeed('tailLogs', { text: `Stopped polling` });
73
- process.exit(EXIT_CODES.SUCCESS);
74
- }
83
+ const spinnies = new Spinnies();
84
+
85
+ spinnies.add('tailLogs', {
86
+ text: `Following logs for ${name}. Press "Q" to stop following`,
75
87
  });
76
88
 
89
+ handleUserInput(spinnies);
90
+
77
91
  await tail(initialAfter);
78
92
  };
79
93
 
@@ -1,12 +1,12 @@
1
- const BaseValidator = require('../marketplaceValidators/BaseValidator');
1
+ const AbsoluteValidator = require('../marketplaceValidators/AbsoluteValidator');
2
2
  const { VALIDATION_RESULT } = require('../constants');
3
3
 
4
- const Validator = new BaseValidator({
4
+ const Validator = new AbsoluteValidator({
5
5
  name: 'Test validator',
6
6
  key: 'validatorKey',
7
7
  });
8
8
 
9
- describe('validators/marketplaceValidators/BaseValidator', () => {
9
+ describe('validators/marketplaceValidators/AbsoluteValidator', () => {
10
10
  it('getSuccess returns expected object', async () => {
11
11
  const success = Validator.getSuccess();
12
12
 
@@ -0,0 +1,79 @@
1
+ const marketplace = require('@hubspot/cli-lib/api/marketplace');
2
+ const path = require('path');
3
+
4
+ const ModuleDependencyValidator = require('../marketplaceValidators/module/ModuleDependencyValidator');
5
+ const { VALIDATION_RESULT } = require('../constants');
6
+ const { MODULE_PATH } = require('./validatorTestUtils');
7
+
8
+ jest.mock('@hubspot/cli-lib/api/marketplace');
9
+
10
+ const getMockDependencyResult = (customPaths = []) => {
11
+ const result = {
12
+ dependencies: [...customPaths],
13
+ };
14
+ return Promise.resolve(result);
15
+ };
16
+
17
+ describe('validators/marketplaceValidators/module/ModuleDependencyValidator', () => {
18
+ beforeEach(() => {
19
+ ModuleDependencyValidator.setRelativePath(MODULE_PATH);
20
+ });
21
+
22
+ describe('isExternalDep', () => {
23
+ beforeEach(() => {
24
+ ModuleDependencyValidator.setRelativePath(MODULE_PATH);
25
+ });
26
+
27
+ it('returns true if dep is external to the provided absolute path', () => {
28
+ const isExternal = ModuleDependencyValidator.isExternalDep(
29
+ MODULE_PATH,
30
+ 'SomeOtherFolder/In/The/DesignManager.css'
31
+ );
32
+ expect(isExternal).toBe(true);
33
+ });
34
+
35
+ it('returns false if dep is not external to the provided absolute path', () => {
36
+ const isExternal = ModuleDependencyValidator.isExternalDep(
37
+ MODULE_PATH,
38
+ `${path.parse(MODULE_PATH).dir}/Internal/Folder/style.css`
39
+ );
40
+ expect(isExternal).toBe(false);
41
+ });
42
+ });
43
+
44
+ describe('validate', () => {
45
+ it('returns error if any referenced path is absolute', async () => {
46
+ marketplace.fetchModuleDependencies.mockReturnValue(
47
+ getMockDependencyResult(['/absolute/path'])
48
+ );
49
+ const validationErrors = await ModuleDependencyValidator.validate(
50
+ MODULE_PATH
51
+ );
52
+
53
+ expect(validationErrors.length).toBe(1);
54
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
55
+ });
56
+
57
+ it('returns error if any referenced path is external to the theme', async () => {
58
+ marketplace.fetchModuleDependencies.mockReturnValue(
59
+ getMockDependencyResult(['../../external/file-3.js'])
60
+ );
61
+ const validationErrors = await ModuleDependencyValidator.validate(
62
+ MODULE_PATH
63
+ );
64
+
65
+ expect(validationErrors.length).toBe(1);
66
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
67
+ });
68
+
69
+ it('returns no errors if paths are relative and internal', async () => {
70
+ marketplace.fetchModuleDependencies.mockReturnValue(
71
+ getMockDependencyResult(['module/style.css', 'module/another/test.js'])
72
+ );
73
+ const validationErrors = await ModuleDependencyValidator.validate(
74
+ MODULE_PATH
75
+ );
76
+ expect(validationErrors.length).toBe(0);
77
+ });
78
+ });
79
+ });
@@ -1,84 +1,51 @@
1
- const fs = require('fs');
2
- const ModuleValidator = require('../marketplaceValidators/theme/ModuleValidator');
1
+ const ModuleValidator = require('../marketplaceValidators/module/ModuleValidator');
3
2
  const { VALIDATION_RESULT } = require('../constants');
4
- const {
5
- generateModulesList,
6
- makeFindError,
7
- THEME_PATH,
8
- } = require('./validatorTestUtils');
3
+ const { MODULE_PATH } = require('./validatorTestUtils');
4
+ const marketplace = require('@hubspot/cli-lib/api/marketplace');
9
5
 
10
- jest.mock('fs');
6
+ jest.mock('@hubspot/cli-lib/api/marketplace');
11
7
 
12
- const MODULE_LIMIT = 50;
13
-
14
- const findError = makeFindError('module');
15
-
16
- describe('validators/marketplaceValidators/theme/ModuleValidator', () => {
8
+ describe('validators/marketplaceValidators/module/ModuleValidator', () => {
17
9
  beforeEach(() => {
18
- ModuleValidator.setThemePath(THEME_PATH);
19
- });
20
-
21
- it('returns error if module limit is exceeded', async () => {
22
- const validationErrors = ModuleValidator.validate(
23
- generateModulesList(MODULE_LIMIT + 1)
24
- );
25
- const limitError = findError(validationErrors, 'limitExceeded');
26
- expect(limitError).toBeDefined();
27
- expect(limitError.result).toBe(VALIDATION_RESULT.FATAL);
28
- });
29
-
30
- it('returns no limit error if module limit is not exceeded', async () => {
31
- const validationErrors = ModuleValidator.validate(
32
- generateModulesList(MODULE_LIMIT)
33
- );
34
- const limitError = findError(validationErrors, 'limitExceeded');
35
- expect(limitError).not.toBeDefined();
36
- });
37
-
38
- it('returns error if no module meta.json file exists', async () => {
39
- const validationErrors = ModuleValidator.validate([
40
- 'module.module/module.html',
41
- ]);
42
- expect(validationErrors.length).toBe(1);
43
- expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
10
+ ModuleValidator.setRelativePath(MODULE_PATH);
44
11
  });
45
12
 
46
13
  it('returns error if module meta.json file has invalid json', async () => {
47
- fs.readFileSync.mockReturnValue('{} bad json }');
14
+ marketplace.fetchModuleMeta.mockReturnValue(
15
+ Promise.resolve({ source: '{} bad json }' })
16
+ );
48
17
 
49
- const validationErrors = ModuleValidator.validate([
50
- 'module.module/meta.json',
51
- ]);
18
+ const validationErrors = await ModuleValidator.validate(MODULE_PATH);
52
19
  expect(validationErrors.length).toBe(1);
53
20
  expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
54
21
  });
55
22
 
56
23
  it('returns error if module meta.json file is missing a label field', async () => {
57
- fs.readFileSync.mockReturnValue('{ "icon": "woo" }');
24
+ marketplace.fetchModuleMeta.mockReturnValue(
25
+ Promise.resolve({ source: '{ "icon": "woo" }' })
26
+ );
58
27
 
59
- const validationErrors = ModuleValidator.validate([
60
- 'module.module/meta.json',
61
- ]);
28
+ const validationErrors = await ModuleValidator.validate(MODULE_PATH);
62
29
  expect(validationErrors.length).toBe(1);
63
30
  expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
64
31
  });
65
32
 
66
33
  it('returns error if module meta.json file is missing an icon field', async () => {
67
- fs.readFileSync.mockReturnValue('{ "label": "yay" }');
34
+ marketplace.fetchModuleMeta.mockReturnValue(
35
+ Promise.resolve({ source: '{ "label": "yay" }' })
36
+ );
68
37
 
69
- const validationErrors = ModuleValidator.validate([
70
- 'module.module/meta.json',
71
- ]);
38
+ const validationErrors = await ModuleValidator.validate(MODULE_PATH);
72
39
  expect(validationErrors.length).toBe(1);
73
40
  expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
74
41
  });
75
42
 
76
43
  it('returns no error if module meta.json file exists and has all required fields', async () => {
77
- fs.readFileSync.mockReturnValue('{ "label": "yay", "icon": "woo" }');
44
+ marketplace.fetchModuleMeta.mockReturnValue(
45
+ Promise.resolve({ source: '{ "label": "yay", "icon": "woo" }' })
46
+ );
78
47
 
79
- const validationErrors = ModuleValidator.validate([
80
- 'module.module/meta.json',
81
- ]);
48
+ const validationErrors = await ModuleValidator.validate(MODULE_PATH);
82
49
  expect(validationErrors.length).toBe(0);
83
50
  });
84
51
  });
@@ -0,0 +1,28 @@
1
+ const RelativeValidator = require('../marketplaceValidators/RelativeValidator');
2
+ const { VALIDATION_RESULT } = require('../constants');
3
+
4
+ const Validator = new RelativeValidator({
5
+ name: 'Test validator',
6
+ key: 'validatorKey',
7
+ });
8
+
9
+ describe('validators/marketplaceValidators/RelativeValidator', () => {
10
+ it('getSuccess returns expected object', async () => {
11
+ const success = Validator.getSuccess();
12
+
13
+ expect(success.validatorKey).toBe('validatorKey');
14
+ expect(success.validatorName).toBe('Test validator');
15
+ expect(success.result).toBe(VALIDATION_RESULT.SUCCESS);
16
+ });
17
+
18
+ it('getError returns expected object', async () => {
19
+ const errorObj = { key: 'errorkey', getCopy: () => 'Some error copy' };
20
+ const success = Validator.getError(errorObj);
21
+
22
+ expect(success.validatorKey).toBe('validatorKey');
23
+ expect(success.validatorName).toBe('Test validator');
24
+ expect(success.error).toBe('Some error copy');
25
+ expect(success.result).toBe(VALIDATION_RESULT.FATAL);
26
+ expect(success.key).toBe('validatorKey.errorkey');
27
+ });
28
+ });
@@ -29,7 +29,7 @@ const findError = makeFindError('template');
29
29
 
30
30
  describe('validators/marketplaceValidators/theme/TemplateValidator', () => {
31
31
  beforeEach(() => {
32
- TemplateValidator.setThemePath(THEME_PATH);
32
+ TemplateValidator.setAbsolutePath(THEME_PATH);
33
33
  templates.isCodedFile.mockReturnValue(true);
34
34
  });
35
35
 
@@ -10,7 +10,7 @@ jest.mock('path');
10
10
 
11
11
  describe('validators/marketplaceValidators/theme/ThemeConfigValidator', () => {
12
12
  beforeEach(() => {
13
- ThemeConfigValidator.setThemePath(THEME_PATH);
13
+ ThemeConfigValidator.setAbsolutePath(THEME_PATH);
14
14
  });
15
15
 
16
16
  it('returns error if no theme.json file exists', async () => {
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs-extra');
2
2
  const marketplace = require('@hubspot/cli-lib/api/marketplace');
3
3
 
4
- const DependencyValidator = require('../marketplaceValidators/theme/DependencyValidator');
4
+ const ThemeDependencyValidator = require('../marketplaceValidators/theme/ThemeDependencyValidator');
5
5
  const { VALIDATION_RESULT } = require('../constants');
6
6
  const { THEME_PATH } = require('./validatorTestUtils');
7
7
 
@@ -15,20 +15,20 @@ const getMockDependencyResult = (customPaths = []) => {
15
15
  return Promise.resolve(result);
16
16
  };
17
17
 
18
- describe('validators/marketplaceValidators/theme/DependencyValidator', () => {
18
+ describe('validators/marketplaceValidators/theme/ThemeDependencyValidator', () => {
19
19
  beforeEach(() => {
20
- DependencyValidator.setThemePath(THEME_PATH);
20
+ ThemeDependencyValidator.setAbsolutePath(THEME_PATH);
21
21
  });
22
22
 
23
23
  describe('isExternalDep', () => {
24
24
  beforeEach(() => {
25
- DependencyValidator.setThemePath(THEME_PATH);
25
+ ThemeDependencyValidator.setAbsolutePath(THEME_PATH);
26
26
  });
27
27
 
28
28
  it('returns true if dep is external to the provided absolute path', () => {
29
29
  const absoluteFilePath = `${THEME_PATH}/file.js`;
30
30
  const relativeDepPath = '../external/dep/path/file2.js';
31
- const isExternal = DependencyValidator.isExternalDep(
31
+ const isExternal = ThemeDependencyValidator.isExternalDep(
32
32
  absoluteFilePath,
33
33
  relativeDepPath
34
34
  );
@@ -38,7 +38,7 @@ describe('validators/marketplaceValidators/theme/DependencyValidator', () => {
38
38
  it('returns false if dep is not external to the provided absolute path', () => {
39
39
  const absoluteFilePath = `${THEME_PATH}/file.js`;
40
40
  const relativeDepPath = './internal/dep/path/file2.js';
41
- const isExternal = DependencyValidator.isExternalDep(
41
+ const isExternal = ThemeDependencyValidator.isExternalDep(
42
42
  absoluteFilePath,
43
43
  relativeDepPath
44
44
  );
@@ -52,10 +52,10 @@ describe('validators/marketplaceValidators/theme/DependencyValidator', () => {
52
52
  });
53
53
 
54
54
  it('returns error if any referenced path is absolute', async () => {
55
- marketplace.fetchDependencies.mockReturnValue(
55
+ marketplace.fetchTemplateDependencies.mockReturnValue(
56
56
  getMockDependencyResult(['/absolute/file-3.js'])
57
57
  );
58
- const validationErrors = await DependencyValidator.validate([
58
+ const validationErrors = await ThemeDependencyValidator.validate([
59
59
  `${THEME_PATH}/template.html`,
60
60
  ]);
61
61
 
@@ -64,10 +64,10 @@ describe('validators/marketplaceValidators/theme/DependencyValidator', () => {
64
64
  });
65
65
 
66
66
  it('returns error if any referenced path is external to the theme', async () => {
67
- marketplace.fetchDependencies.mockReturnValue(
67
+ marketplace.fetchTemplateDependencies.mockReturnValue(
68
68
  getMockDependencyResult(['../../external/file-3.js'])
69
69
  );
70
- const validationErrors = await DependencyValidator.validate([
70
+ const validationErrors = await ThemeDependencyValidator.validate([
71
71
  `${THEME_PATH}/template.html`,
72
72
  ]);
73
73
 
@@ -76,8 +76,10 @@ describe('validators/marketplaceValidators/theme/DependencyValidator', () => {
76
76
  });
77
77
 
78
78
  it('returns no errors if paths are relative and internal', async () => {
79
- marketplace.fetchDependencies.mockReturnValue(getMockDependencyResult());
80
- const validationErrors = await DependencyValidator.validate([
79
+ marketplace.fetchTemplateDependencies.mockReturnValue(
80
+ getMockDependencyResult()
81
+ );
82
+ const validationErrors = await ThemeDependencyValidator.validate([
81
83
  `${THEME_PATH}/template.html`,
82
84
  ]);
83
85
 
@@ -0,0 +1,84 @@
1
+ const fs = require('fs');
2
+ const ThemeModuleValidator = require('../marketplaceValidators/theme/ThemeModuleValidator');
3
+ const { VALIDATION_RESULT } = require('../constants');
4
+ const {
5
+ generateModulesList,
6
+ makeFindError,
7
+ THEME_PATH,
8
+ } = require('./validatorTestUtils');
9
+
10
+ jest.mock('fs');
11
+
12
+ const MODULE_LIMIT = 50;
13
+
14
+ const findError = makeFindError('themeModule');
15
+
16
+ describe('validators/marketplaceValidators/theme/ThemeModuleValidator', () => {
17
+ beforeEach(() => {
18
+ ThemeModuleValidator.setAbsolutePath(THEME_PATH);
19
+ });
20
+
21
+ it('returns error if module limit is exceeded', async () => {
22
+ const validationErrors = ThemeModuleValidator.validate(
23
+ generateModulesList(MODULE_LIMIT + 1)
24
+ );
25
+ const limitError = findError(validationErrors, 'limitExceeded');
26
+ expect(limitError).toBeDefined();
27
+ expect(limitError.result).toBe(VALIDATION_RESULT.FATAL);
28
+ });
29
+
30
+ it('returns no limit error if module limit is not exceeded', async () => {
31
+ const validationErrors = ThemeModuleValidator.validate(
32
+ generateModulesList(MODULE_LIMIT)
33
+ );
34
+ const limitError = findError(validationErrors, 'limitExceeded');
35
+ expect(limitError).not.toBeDefined();
36
+ });
37
+
38
+ it('returns error if no module meta.json file exists', async () => {
39
+ const validationErrors = ThemeModuleValidator.validate([
40
+ 'module.module/module.html',
41
+ ]);
42
+ expect(validationErrors.length).toBe(1);
43
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
44
+ });
45
+
46
+ it('returns error if module meta.json file has invalid json', async () => {
47
+ fs.readFileSync.mockReturnValue('{} bad json }');
48
+
49
+ const validationErrors = ThemeModuleValidator.validate([
50
+ 'module.module/meta.json',
51
+ ]);
52
+ expect(validationErrors.length).toBe(1);
53
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
54
+ });
55
+
56
+ it('returns error if module meta.json file is missing a label field', async () => {
57
+ fs.readFileSync.mockReturnValue('{ "icon": "woo" }');
58
+
59
+ const validationErrors = ThemeModuleValidator.validate([
60
+ 'module.module/meta.json',
61
+ ]);
62
+ expect(validationErrors.length).toBe(1);
63
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
64
+ });
65
+
66
+ it('returns error if module meta.json file is missing an icon field', async () => {
67
+ fs.readFileSync.mockReturnValue('{ "label": "yay" }');
68
+
69
+ const validationErrors = ThemeModuleValidator.validate([
70
+ 'module.module/meta.json',
71
+ ]);
72
+ expect(validationErrors.length).toBe(1);
73
+ expect(validationErrors[0].result).toBe(VALIDATION_RESULT.FATAL);
74
+ });
75
+
76
+ it('returns no error if module meta.json file exists and has all required fields', async () => {
77
+ fs.readFileSync.mockReturnValue('{ "label": "yay", "icon": "woo" }');
78
+
79
+ const validationErrors = ThemeModuleValidator.validate([
80
+ 'module.module/meta.json',
81
+ ]);
82
+ expect(validationErrors.length).toBe(0);
83
+ });
84
+ });
@@ -2,6 +2,7 @@
2
2
  test.skip('skip', () => null);
3
3
 
4
4
  const THEME_PATH = '/path/to/a/theme';
5
+ const MODULE_PATH = 'module/path';
5
6
 
6
7
  const makeFindError = baseKey => (errors, errorKey) =>
7
8
  errors.find(error => error.key === `${baseKey}.${errorKey}`);
@@ -31,4 +32,5 @@ module.exports = {
31
32
  generateTemplatesList,
32
33
  makeFindError,
33
34
  THEME_PATH,
35
+ MODULE_PATH,
34
36
  };
@@ -1,9 +1,9 @@
1
- async function applyValidators(validators, absoluteThemePath, ...args) {
1
+ async function applyAbsoluteValidators(validators, absolutePath, ...args) {
2
2
  return Promise.all(
3
3
  validators.map(async Validator => {
4
- Validator.setThemePath(absoluteThemePath);
4
+ Validator.setAbsolutePath(absolutePath);
5
5
  const validationResult = await Validator.validate(...args);
6
- Validator.clearThemePath();
6
+ Validator.clearAbsolutePath();
7
7
 
8
8
  if (!validationResult.length) {
9
9
  // Return a success obj so we can log the successes
@@ -14,4 +14,20 @@ async function applyValidators(validators, absoluteThemePath, ...args) {
14
14
  );
15
15
  }
16
16
 
17
- module.exports = { applyValidators };
17
+ async function applyRelativeValidators(validators, relativePath, ...args) {
18
+ return Promise.all(
19
+ validators.map(async Validator => {
20
+ Validator.setRelativePath(relativePath);
21
+ const validationResult = await Validator.validate(...args);
22
+ Validator.clearRelativePath();
23
+
24
+ if (!validationResult.length) {
25
+ // Return a success obj so we can log the successes
26
+ return [Validator.getSuccess()];
27
+ }
28
+ return validationResult;
29
+ })
30
+ );
31
+ }
32
+
33
+ module.exports = { applyAbsoluteValidators, applyRelativeValidators };
@@ -4,11 +4,13 @@ const SUCCESS = 'SUCCESS';
4
4
 
5
5
  const VALIDATION_RESULT = { WARNING, FATAL, SUCCESS };
6
6
  const VALIDATOR_KEYS = {
7
- dependency: 'dependency',
8
- module: 'module',
7
+ themeDependency: 'themeDependency',
8
+ themeModule: 'themeModule',
9
9
  section: 'section',
10
10
  template: 'template',
11
11
  themeConfig: 'themeConfig',
12
+ module: 'module',
13
+ moduleDependency: 'moduleDependency',
12
14
  };
13
15
 
14
16
  module.exports = { VALIDATOR_KEYS, VALIDATION_RESULT };
@@ -1,17 +1,21 @@
1
1
  const ThemeConfigValidator = require('./marketplaceValidators/theme/ThemeConfigValidator');
2
2
  const SectionValidator = require('./marketplaceValidators/theme/SectionValidator');
3
3
  const TemplateValidator = require('./marketplaceValidators/theme/TemplateValidator');
4
- const ModuleValidator = require('./marketplaceValidators/theme/ModuleValidator');
5
- const DependencyValidator = require('./marketplaceValidators/theme/DependencyValidator');
4
+ const ThemeModuleValidator = require('./marketplaceValidators/theme/ThemeModuleValidator');
5
+ const ThemeDependencyValidator = require('./marketplaceValidators/theme/ThemeDependencyValidator');
6
+
7
+ const ModuleValidator = require('./marketplaceValidators/module/ModuleValidator');
8
+ const ModuleDependencyValidator = require('./marketplaceValidators/module/ModuleDependencyValidator');
6
9
 
7
10
  const MARKETPLACE_VALIDATORS = {
8
11
  theme: [
9
12
  ThemeConfigValidator,
10
13
  SectionValidator,
11
14
  TemplateValidator,
12
- ModuleValidator,
13
- DependencyValidator,
15
+ ThemeModuleValidator,
16
+ ThemeDependencyValidator,
14
17
  ],
18
+ module: [ModuleValidator, ModuleDependencyValidator],
15
19
  };
16
20
 
17
21
  module.exports = MARKETPLACE_VALIDATORS;
@@ -2,23 +2,23 @@ const path = require('path');
2
2
 
3
3
  const { VALIDATION_RESULT } = require('../constants');
4
4
 
5
- class BaseValidator {
5
+ class AbsoluteValidator {
6
6
  constructor({ name, key }) {
7
7
  this.name = name;
8
8
  this.key = key;
9
9
  }
10
10
 
11
- clearThemePath() {
12
- this._absoluteThemePath = null;
11
+ clearAbsolutePath() {
12
+ this._absolutePath = null;
13
13
  }
14
14
 
15
- setThemePath(path) {
16
- this._absoluteThemePath = path;
15
+ setAbsolutePath(path) {
16
+ this._absolutePath = path;
17
17
  }
18
18
 
19
19
  getRelativePath(filePath) {
20
- return this._absoluteThemePath
21
- ? path.relative(this._absoluteThemePath, filePath)
20
+ return this._absolutePath
21
+ ? path.relative(this._absolutePath, filePath)
22
22
  : filePath;
23
23
  }
24
24
 
@@ -47,4 +47,4 @@ class BaseValidator {
47
47
  }
48
48
  }
49
49
 
50
- module.exports = BaseValidator;
50
+ module.exports = AbsoluteValidator;
@@ -0,0 +1,46 @@
1
+ const { VALIDATION_RESULT } = require('../constants');
2
+
3
+ class RelativeValidator {
4
+ constructor({ name, key }) {
5
+ this.name = name;
6
+ this.key = key;
7
+ }
8
+
9
+ clearRelativePath() {
10
+ this._relativePath = null;
11
+ }
12
+
13
+ setRelativePath(path) {
14
+ this._relativePath = path;
15
+ }
16
+
17
+ getRelativePath() {
18
+ return this._relativePath;
19
+ }
20
+
21
+ getSuccess() {
22
+ return {
23
+ validatorKey: this.key,
24
+ validatorName: this.name,
25
+ result: VALIDATION_RESULT.SUCCESS,
26
+ };
27
+ }
28
+
29
+ getError(errorObj, file, extraContext = {}) {
30
+ const relativeFilePath = this.getRelativePath();
31
+ const context = {
32
+ filePath: relativeFilePath,
33
+ ...extraContext,
34
+ };
35
+ return {
36
+ validatorKey: this.key,
37
+ validatorName: this.name,
38
+ error: errorObj.getCopy(context),
39
+ result: errorObj.severity || VALIDATION_RESULT.FATAL,
40
+ key: `${this.key}.${errorObj.key}`,
41
+ context,
42
+ };
43
+ }
44
+ }
45
+
46
+ module.exports = RelativeValidator;