@dittowords/cli 4.4.0 → 4.5.0

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 (87) hide show
  1. package/.github/actions/install-node-dependencies/action.yml +24 -0
  2. package/.github/workflows/required-checks.yml +24 -0
  3. package/__mocks__/fs.js +2 -0
  4. package/bin/__mocks__/api.js +48 -0
  5. package/bin/__mocks__/api.js.map +1 -0
  6. package/bin/config.js +6 -4
  7. package/bin/config.js.map +1 -1
  8. package/bin/config.test.js +4 -3
  9. package/bin/config.test.js.map +1 -1
  10. package/bin/consts.js +19 -29
  11. package/bin/consts.js.map +1 -1
  12. package/bin/generate-suggestions.js +68 -58
  13. package/bin/generate-suggestions.js.map +1 -1
  14. package/bin/generate-suggestions.test.js +24 -13
  15. package/bin/generate-suggestions.test.js.map +1 -1
  16. package/bin/http/__mocks__/fetchComponentFolders.js +71 -0
  17. package/bin/http/__mocks__/fetchComponentFolders.js.map +1 -0
  18. package/bin/http/__mocks__/fetchComponents.js +73 -0
  19. package/bin/http/__mocks__/fetchComponents.js.map +1 -0
  20. package/bin/http/__mocks__/fetchVariants.js +71 -0
  21. package/bin/http/__mocks__/fetchVariants.js.map +1 -0
  22. package/bin/http/fetchComponentFolders.js +4 -4
  23. package/bin/http/fetchComponentFolders.js.map +1 -1
  24. package/bin/http/fetchComponents.js +4 -4
  25. package/bin/http/fetchComponents.js.map +1 -1
  26. package/bin/http/fetchVariants.js +2 -2
  27. package/bin/http/fetchVariants.js.map +1 -1
  28. package/bin/http/http.test.js +159 -0
  29. package/bin/http/http.test.js.map +1 -0
  30. package/bin/http/importComponents.js +9 -2
  31. package/bin/http/importComponents.js.map +1 -1
  32. package/bin/init/project.test.js +5 -28
  33. package/bin/init/project.test.js.map +1 -1
  34. package/bin/init/token.js +72 -27
  35. package/bin/init/token.js.map +1 -1
  36. package/bin/init/token.test.js +87 -9
  37. package/bin/init/token.test.js.map +1 -1
  38. package/bin/pull-lib.test.js +379 -0
  39. package/bin/pull-lib.test.js.map +1 -0
  40. package/bin/pull.js +13 -5
  41. package/bin/pull.js.map +1 -1
  42. package/bin/pull.test.js +100 -289
  43. package/bin/pull.test.js.map +1 -1
  44. package/bin/replace.js +22 -6
  45. package/bin/replace.js.map +1 -1
  46. package/bin/replace.test.js +53 -11
  47. package/bin/replace.test.js.map +1 -1
  48. package/bin/types.js +2 -2
  49. package/bin/types.js.map +1 -1
  50. package/bin/utils/determineModuleType.js +6 -7
  51. package/bin/utils/determineModuleType.js.map +1 -1
  52. package/bin/utils/determineModuleType.test.js +60 -0
  53. package/bin/utils/determineModuleType.test.js.map +1 -0
  54. package/bin/utils/getSelectedProjects.js +5 -5
  55. package/bin/utils/getSelectedProjects.js.map +1 -1
  56. package/bin/utils/quit.js +3 -3
  57. package/bin/utils/quit.js.map +1 -1
  58. package/jest.config.ts +16 -0
  59. package/lib/__mocks__/api.ts +12 -0
  60. package/lib/config.test.ts +3 -1
  61. package/lib/config.ts +4 -2
  62. package/lib/consts.ts +19 -17
  63. package/lib/generate-suggestions.test.ts +23 -11
  64. package/lib/generate-suggestions.ts +89 -79
  65. package/lib/http/__mocks__/fetchComponentFolders.ts +23 -0
  66. package/lib/http/__mocks__/fetchComponents.ts +24 -0
  67. package/lib/http/__mocks__/fetchVariants.ts +21 -0
  68. package/lib/http/fetchComponentFolders.ts +6 -4
  69. package/lib/http/fetchComponents.ts +5 -3
  70. package/lib/http/fetchVariants.ts +14 -3
  71. package/lib/http/http.test.ts +122 -0
  72. package/lib/http/importComponents.ts +8 -0
  73. package/lib/init/project.test.ts +4 -27
  74. package/lib/init/token.test.ts +55 -7
  75. package/lib/init/token.ts +76 -27
  76. package/lib/pull-lib.test.ts +367 -0
  77. package/lib/pull.test.ts +97 -310
  78. package/lib/pull.ts +11 -3
  79. package/lib/replace.test.ts +46 -10
  80. package/lib/replace.ts +20 -3
  81. package/lib/types.ts +5 -0
  82. package/lib/utils/determineModuleType.test.ts +48 -0
  83. package/lib/utils/determineModuleType.ts +4 -6
  84. package/lib/utils/getSelectedProjects.ts +3 -3
  85. package/lib/utils/quit.ts +1 -1
  86. package/package.json +4 -3
  87. package/jest.config.js +0 -6
@@ -9,18 +9,16 @@ export type ModuleType = "commonjs" | "module";
9
9
  * @returns "commonjs" or "module", defaulting to "module" if no `package.json` is found or if the found
10
10
  * file does not include a `type` property.
11
11
  */
12
- export function determineModuleType() {
13
- const value = getRawTypeFromPackageJson();
12
+ export function determineModuleType(currentDir: string | null = process.cwd()) {
13
+ const value = getRawTypeFromPackageJson(currentDir);
14
14
  return getTypeOrDefault(value);
15
15
  }
16
16
 
17
- function getRawTypeFromPackageJson() {
17
+ function getRawTypeFromPackageJson(currentDir: string | null) {
18
18
  if (process.env.DITTO_MODULE_TYPE) {
19
19
  return process.env.DITTO_MODULE_TYPE;
20
20
  }
21
21
 
22
- let currentDir: string | null = process.cwd(); // Get the current working directory
23
-
24
22
  while (currentDir) {
25
23
  const packageJsonPath = path.join(currentDir, "package.json");
26
24
  if (fs.existsSync(packageJsonPath)) {
@@ -36,7 +34,7 @@ function getRawTypeFromPackageJson() {
36
34
  }
37
35
 
38
36
  if (currentDir === "/") {
39
- return null;
37
+ break;
40
38
  }
41
39
 
42
40
  // Move up a directory and continue the search
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import yaml, { YAMLException } from "js-yaml";
3
3
 
4
- import { PROJECT_CONFIG_FILE } from "../consts";
4
+ import consts from "../consts";
5
5
  import { ConfigYAML, Project } from "../types";
6
6
  import Config, { DEFAULT_CONFIG_JSON } from "../config";
7
7
 
@@ -29,8 +29,8 @@ function yamlToJson(_yaml: string): ConfigYAML | null {
29
29
  * Returns an array containing all valid projects ({ id, name })
30
30
  * currently contained in the project config file.
31
31
  */
32
- export const getSelectedProjects = (configFile = PROJECT_CONFIG_FILE) =>
32
+ export const getSelectedProjects = (configFile = consts.PROJECT_CONFIG_FILE) =>
33
33
  Config.parseSourceInformation(configFile).validProjects;
34
34
 
35
- export const getIsUsingComponents = (configFile = PROJECT_CONFIG_FILE) =>
35
+ export const getIsUsingComponents = (configFile = consts.PROJECT_CONFIG_FILE) =>
36
36
  Config.parseSourceInformation(configFile).shouldFetchComponentLibrary;
package/lib/utils/quit.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export function quit(message: string | null, exitCode = 2) {
2
2
  if (message) console.log(`\n${message}\n`);
3
- process.exitCode = exitCode;
3
+ process.exit(exitCode);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittowords/cli",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Command Line Interface for Ditto (dittowords.com).",
5
5
  "license": "MIT",
6
6
  "main": "bin/index.js",
@@ -35,6 +35,7 @@
35
35
  "devDependencies": {
36
36
  "@babel/preset-env": "^7.20.2",
37
37
  "@babel/preset-typescript": "^7.18.6",
38
+ "@jest/globals": "^29.7.0",
38
39
  "@sentry/cli": "^2.20.5",
39
40
  "@tsconfig/node16": "^1.0.3",
40
41
  "@types/jest": "^26.0.9",
@@ -51,6 +52,7 @@
51
52
  "rewire": "^6.0.0",
52
53
  "source-map": "^0.7.3",
53
54
  "tempy": "^0.6.0",
55
+ "ts-node": "^10.9.2",
54
56
  "typescript": "^4.7.4"
55
57
  },
56
58
  "dependencies": {
@@ -60,7 +62,6 @@
60
62
  "@babel/types": "^7.21.4",
61
63
  "@sentry/node": "^7.64.0",
62
64
  "@types/babel-traverse": "^6.25.7",
63
- "@types/fs-extra": "^11.0.1",
64
65
  "axios": "^1.6.0",
65
66
  "boxen": "^5.1.2",
66
67
  "chalk": "^4.1.0",
@@ -68,9 +69,9 @@
68
69
  "enquirer": "^2.3.6",
69
70
  "faker": "^5.1.0",
70
71
  "form-data": "^4.0.0",
71
- "fs-extra": "^11.1.1",
72
72
  "glob": "^9.3.4",
73
73
  "js-yaml": "^4.1.0",
74
+ "memfs": "^4.7.7",
74
75
  "ora": "^5.0.0",
75
76
  "v8-compile-cache": "^2.1.1"
76
77
  },
package/jest.config.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- transformIgnorePatterns: [],
3
- maxWorkers: 1,
4
- verbose: true,
5
- collectCoverageFrom: ["lib/**/*.{js,jsx,ts,tsx}"],
6
- };