@jakubmazanec/carson 3.0.4-next.fac374fa → 3.0.4-unstable.2468857d

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 (177) hide show
  1. package/build/commands/create-project/CreateProject.js +117 -105
  2. package/build/commands/create-project/CreateProjectInput.js +25 -32
  3. package/build/commands/create-project/createProjectCommand.js +25 -35
  4. package/build/commands/create-project/runCreateProject.js +24 -27
  5. package/build/commands/create-workspace/CreateWorkspace.js +80 -63
  6. package/build/commands/create-workspace/CreateWorkspaceInput.js +12 -17
  7. package/build/commands/create-workspace/createWorkspaceCommand.js +16 -21
  8. package/build/commands/create-workspace/runCreateWorkspace.js +24 -21
  9. package/build/commands/internals/packageNameToDirectory.js +9 -11
  10. package/build/commands/update-workspace/UpdateWorkspace.js +56 -33
  11. package/build/commands/update-workspace/runUpdateWorkspace.js +20 -17
  12. package/build/commands/update-workspace/updateWorkspaceCommand.js +21 -29
  13. package/build/constants.js +14 -11
  14. package/build/main.js +28 -5
  15. package/build/run.js +14 -12
  16. package/build/template/CarsonTemplateConfig.js +6 -7
  17. package/build/template/CarsonTemplateError.js +18 -16
  18. package/build/template/TemplateAttributes.js +12 -11
  19. package/build/template/TemplateData.js +10 -7
  20. package/build/template/applyTemplateRenders.js +64 -93
  21. package/build/template/internals/TemplateRenderSnapshot.js +10 -7
  22. package/build/template/internals/TemplateRenderSnapshots.js +6 -3
  23. package/build/template/internals/createUsingTemplateRender.js +36 -39
  24. package/build/template/internals/deleteUsingTemplateRenderSnapshot.js +18 -21
  25. package/build/template/internals/importCarsonTemplate.js +9 -6
  26. package/build/template/internals/insertUsingTemplateRender.js +30 -37
  27. package/build/template/internals/loadTemplateRenderSnapshots.js +13 -14
  28. package/build/template/internals/merge.js +16 -28
  29. package/build/template/internals/mergeUsingTemplateRender.js +38 -45
  30. package/build/template/internals/overwriteUsingTemplateRender.js +11 -8
  31. package/build/template/internals/parseCarsonTemplateId.js +9 -10
  32. package/build/template/internals/prettify.js +18 -17
  33. package/build/template/internals/readCarsonTemplate.js +33 -41
  34. package/build/template/internals/resolveModule.js +9 -7
  35. package/build/template/internals/saveTemplateRenderSnapshots.js +54 -57
  36. package/build/template/internals/simplify.js +14 -19
  37. package/build/template/internals/uninsertUsingTemplateRenderSnapshot.js +22 -28
  38. package/build/template/internals/unmerge.js +21 -31
  39. package/build/template/internals/unmergeUsingTemplateRenderSnapshot.js +30 -31
  40. package/build/template/renderCarsonTemplate.js +42 -46
  41. package/build/workspace/Project.js +154 -205
  42. package/build/workspace/ProjectConfig.js +6 -5
  43. package/build/workspace/ProjectError.js +18 -16
  44. package/build/workspace/Workspace.js +382 -553
  45. package/build/workspace/WorkspaceConfig.js +8 -5
  46. package/build/workspace/WorkspaceDependencies.js +117 -143
  47. package/build/workspace/WorkspaceError.js +24 -22
  48. package/build/workspace/internals/compareProjectPath.js +8 -9
  49. package/build/workspace/internals/compareSemver.js +22 -18
  50. package/build/workspace/internals/compareWorkspaceDependencyProjectName.js +8 -9
  51. package/build/workspace/internals/containsProject.js +15 -21
  52. package/build/workspace/internals/containsWorkspace.js +11 -18
  53. package/build/workspace/internals/getPackageJsonWorkspaces.js +17 -25
  54. package/build/workspace/internals/getRepositoryBranches.js +21 -23
  55. package/build/workspace/internals/getRepositoryUrl.js +16 -17
  56. package/build/workspace/saveProjectConfig.js +17 -13
  57. package/build/workspace/saveWorkspaceConfig.js +17 -20
  58. package/package.json +12 -12
  59. package/build/commands/create-project/CreateProject.js.map +0 -7
  60. package/build/commands/create-project/CreateProjectInput.js.map +0 -7
  61. package/build/commands/create-project/createProjectCommand.js.map +0 -7
  62. package/build/commands/create-project/runCreateProject.js.map +0 -7
  63. package/build/commands/create-project.js +0 -6
  64. package/build/commands/create-project.js.map +0 -7
  65. package/build/commands/create-workspace/CreateWorkspace.js.map +0 -7
  66. package/build/commands/create-workspace/CreateWorkspaceInput.js.map +0 -7
  67. package/build/commands/create-workspace/createWorkspaceCommand.js.map +0 -7
  68. package/build/commands/create-workspace/runCreateWorkspace.js.map +0 -7
  69. package/build/commands/create-workspace.js +0 -6
  70. package/build/commands/create-workspace.js.map +0 -7
  71. package/build/commands/internals/CommandStatus.js +0 -2
  72. package/build/commands/internals/CommandStatus.js.map +0 -7
  73. package/build/commands/internals/packageNameToDirectory.js.map +0 -7
  74. package/build/commands/internals.js +0 -3
  75. package/build/commands/internals.js.map +0 -7
  76. package/build/commands/update-workspace/UpdateWorkspace.js.map +0 -7
  77. package/build/commands/update-workspace/runUpdateWorkspace.js.map +0 -7
  78. package/build/commands/update-workspace/updateWorkspaceCommand.js.map +0 -7
  79. package/build/commands/update-workspace.js +0 -5
  80. package/build/commands/update-workspace.js.map +0 -7
  81. package/build/commands.js +0 -5
  82. package/build/commands.js.map +0 -7
  83. package/build/constants.js.map +0 -7
  84. package/build/main.js.map +0 -7
  85. package/build/modules.d.js +0 -2
  86. package/build/modules.d.js.map +0 -7
  87. package/build/run.js.map +0 -7
  88. package/build/template/CarsonTemplate.js +0 -2
  89. package/build/template/CarsonTemplate.js.map +0 -7
  90. package/build/template/CarsonTemplateConfig.js.map +0 -7
  91. package/build/template/CarsonTemplateError.js.map +0 -7
  92. package/build/template/TemplateAttributes.js.map +0 -7
  93. package/build/template/TemplateData.js.map +0 -7
  94. package/build/template/TemplateRender.js +0 -2
  95. package/build/template/TemplateRender.js.map +0 -7
  96. package/build/template/TemplateRenders.js +0 -2
  97. package/build/template/TemplateRenders.js.map +0 -7
  98. package/build/template/applyTemplateRenders.js.map +0 -7
  99. package/build/template/internals/TemplateRenderSnapshot.js.map +0 -7
  100. package/build/template/internals/TemplateRenderSnapshots.js.map +0 -7
  101. package/build/template/internals/createUsingTemplateRender.js.map +0 -7
  102. package/build/template/internals/deleteUsingTemplateRenderSnapshot.js.map +0 -7
  103. package/build/template/internals/importCarsonTemplate.js.map +0 -7
  104. package/build/template/internals/insertUsingTemplateRender.js.map +0 -7
  105. package/build/template/internals/loadTemplateRenderSnapshots.js.map +0 -7
  106. package/build/template/internals/merge.js.map +0 -7
  107. package/build/template/internals/mergeUsingTemplateRender.js.map +0 -7
  108. package/build/template/internals/overwriteUsingTemplateRender.js.map +0 -7
  109. package/build/template/internals/parseCarsonTemplateId.js.map +0 -7
  110. package/build/template/internals/prettify.js.map +0 -7
  111. package/build/template/internals/readCarsonTemplate.js.map +0 -7
  112. package/build/template/internals/resolveModule.js.map +0 -7
  113. package/build/template/internals/saveTemplateRenderSnapshots.js.map +0 -7
  114. package/build/template/internals/simplify.js.map +0 -7
  115. package/build/template/internals/uninsertUsingTemplateRenderSnapshot.js.map +0 -7
  116. package/build/template/internals/unmerge.js.map +0 -7
  117. package/build/template/internals/unmergeUsingTemplateRenderSnapshot.js.map +0 -7
  118. package/build/template/internals.js +0 -21
  119. package/build/template/internals.js.map +0 -7
  120. package/build/template/renderCarsonTemplate.js.map +0 -7
  121. package/build/template.js +0 -8
  122. package/build/template.js.map +0 -7
  123. package/build/workspace/Project.js.map +0 -7
  124. package/build/workspace/ProjectConfig.js.map +0 -7
  125. package/build/workspace/ProjectCreateOptions.js +0 -2
  126. package/build/workspace/ProjectCreateOptions.js.map +0 -7
  127. package/build/workspace/ProjectError.js.map +0 -7
  128. package/build/workspace/ProjectOptions.js +0 -2
  129. package/build/workspace/ProjectOptions.js.map +0 -7
  130. package/build/workspace/ProjectUpdateOptions.js +0 -2
  131. package/build/workspace/ProjectUpdateOptions.js.map +0 -7
  132. package/build/workspace/Workspace.js.map +0 -7
  133. package/build/workspace/WorkspaceConfig.js.map +0 -7
  134. package/build/workspace/WorkspaceCreateOptions.js +0 -2
  135. package/build/workspace/WorkspaceCreateOptions.js.map +0 -7
  136. package/build/workspace/WorkspaceCreateProjectOptions.js +0 -2
  137. package/build/workspace/WorkspaceCreateProjectOptions.js.map +0 -7
  138. package/build/workspace/WorkspaceDependencies.js.map +0 -7
  139. package/build/workspace/WorkspaceDependenciesFromWorkspaceOptions.js +0 -2
  140. package/build/workspace/WorkspaceDependenciesFromWorkspaceOptions.js.map +0 -7
  141. package/build/workspace/WorkspaceDependenciesGetVersionsOptions.js +0 -2
  142. package/build/workspace/WorkspaceDependenciesGetVersionsOptions.js.map +0 -7
  143. package/build/workspace/WorkspaceDependency.js +0 -2
  144. package/build/workspace/WorkspaceDependency.js.map +0 -7
  145. package/build/workspace/WorkspaceDependencyProject.js +0 -2
  146. package/build/workspace/WorkspaceDependencyProject.js.map +0 -7
  147. package/build/workspace/WorkspaceError.js.map +0 -7
  148. package/build/workspace/WorkspaceFindAndReadOptions.js +0 -2
  149. package/build/workspace/WorkspaceFindAndReadOptions.js.map +0 -7
  150. package/build/workspace/WorkspaceOptions.js +0 -2
  151. package/build/workspace/WorkspaceOptions.js.map +0 -7
  152. package/build/workspace/WorkspaceOptionsProject.js +0 -2
  153. package/build/workspace/WorkspaceOptionsProject.js.map +0 -7
  154. package/build/workspace/WorkspacePackageJson.js +0 -2
  155. package/build/workspace/WorkspacePackageJson.js.map +0 -7
  156. package/build/workspace/WorkspaceProjectGlobs.js +0 -2
  157. package/build/workspace/WorkspaceProjectGlobs.js.map +0 -7
  158. package/build/workspace/WorkspaceProjects.js +0 -2
  159. package/build/workspace/WorkspaceProjects.js.map +0 -7
  160. package/build/workspace/WorkspaceRepository.js +0 -2
  161. package/build/workspace/WorkspaceRepository.js.map +0 -7
  162. package/build/workspace/WorkspaceUpdateOptions.js +0 -2
  163. package/build/workspace/WorkspaceUpdateOptions.js.map +0 -7
  164. package/build/workspace/internals/compareProjectPath.js.map +0 -7
  165. package/build/workspace/internals/compareSemver.js.map +0 -7
  166. package/build/workspace/internals/compareWorkspaceDependencyProjectName.js.map +0 -7
  167. package/build/workspace/internals/containsProject.js.map +0 -7
  168. package/build/workspace/internals/containsWorkspace.js.map +0 -7
  169. package/build/workspace/internals/getPackageJsonWorkspaces.js.map +0 -7
  170. package/build/workspace/internals/getRepositoryBranches.js.map +0 -7
  171. package/build/workspace/internals/getRepositoryUrl.js.map +0 -7
  172. package/build/workspace/internals.js +0 -10
  173. package/build/workspace/internals.js.map +0 -7
  174. package/build/workspace/saveProjectConfig.js.map +0 -7
  175. package/build/workspace/saveWorkspaceConfig.js.map +0 -7
  176. package/build/workspace.js +0 -11
  177. package/build/workspace.js.map +0 -7
@@ -1,111 +1,123 @@
1
- "use strict";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { colors, Header, icons, useProgram } from "@jakubmazanec/cli";
1
+ import { packageNameToDirectory } from "../internals/packageNameToDirectory.js";
2
+ import { CreateProjectInput } from "./CreateProjectInput.js";
3
+ import { runCreateProject } from "./runCreateProject.js";
4
+ import { Header, colors, icons, useProgram } from "@jakubmazanec/cli";
4
5
  import chalk from "chalk";
5
6
  import { Box, Text } from "ink";
6
7
  import path from "node:path";
7
8
  import { useEffect, useState } from "react";
8
- import { packageNameToDirectory } from "../internals.js";
9
- import { CreateProjectInput } from "./CreateProjectInput.js";
10
- import { runCreateProject } from "./runCreateProject.js";
9
+ import { jsx, jsxs } from "react/jsx-runtime";
10
+
11
+ //#region source/commands/create-project/CreateProject.tsx
11
12
  const ONLY_ONE_STAR_REGEXP = /^(?!(.*?\*){2,}|.*? |\*$).*?\*.*$/;
12
- export function CreateProject({ args, workspace }) {
13
- let [status, setStatus] = useState("not-started");
14
- let [subscription, setSubscription] = useState(null);
15
- let [jobs, setJobs] = useState([]);
16
- let [createProjectInputResult, setCreateProjectInputResult] = useState(
17
- () => ({
18
- projectName: { value: args.options.name ?? "", isComplete: !!args.options.name },
19
- projectPath: { value: "", isComplete: false },
20
- templateId: { value: args.options.template ?? "", isComplete: !!args.options.template }
21
- })
22
- );
23
- let { exit } = useProgram();
24
- useEffect(() => {
25
- if (Object.entries(createProjectInputResult).every(([, result]) => result.isComplete)) {
26
- setStatus("in-progress");
27
- }
28
- }, [createProjectInputResult]);
29
- useEffect(() => {
30
- if (status === "in-progress" && !subscription) {
31
- let newSubscription = runCreateProject({
32
- projectPath: createProjectInputResult.projectPath.value,
33
- templateId: createProjectInputResult.templateId.value,
34
- projectName: createProjectInputResult.projectName.value,
35
- workspace,
36
- args
37
- }).subscribe({
38
- next(value) {
39
- setJobs((previousJobs) => [...previousJobs, value]);
40
- },
41
- error(error) {
42
- exit(error);
43
- },
44
- complete() {
45
- newSubscription.unsubscribe();
46
- setStatus("finished");
47
- }
48
- });
49
- setSubscription(newSubscription);
50
- }
51
- return () => {
52
- if (subscription) {
53
- subscription.unsubscribe();
54
- }
55
- };
56
- }, [args, createProjectInputResult, exit, status, subscription, workspace]);
57
- let possiblePaths = [];
58
- if (createProjectInputResult.projectName.value) {
59
- let destinationDirectory = packageNameToDirectory(createProjectInputResult.projectName.value);
60
- if (workspace.projectGlobs) {
61
- possiblePaths = workspace.projectGlobs.filter((projectGlob) => ONLY_ONE_STAR_REGEXP.test(projectGlob)).map((projectGlob) => projectGlob.replace(/\*/, destinationDirectory)).map((projectGlob) => path.join(workspace.path, projectGlob)).map((projectPath) => ({
62
- value: projectPath,
63
- label: path.relative(workspace.path, projectPath).replace("\\", "/")
64
- }));
65
- if (!possiblePaths.length) {
66
- possiblePaths = workspace.projectGlobs.filter((projectGlob) => !ONLY_ONE_STAR_REGEXP.test(projectGlob)).map((projectGlob) => path.join(workspace.path, projectGlob)).map((projectPath) => ({
67
- value: projectPath,
68
- label: path.relative(workspace.path, projectPath).replace("\\", "/")
69
- }));
70
- }
71
- if (!possiblePaths.length) {
72
- possiblePaths = [
73
- {
74
- value: workspace.path,
75
- label: workspace.path
76
- }
77
- ];
78
- }
79
- } else {
80
- possiblePaths = [
81
- {
82
- value: workspace.path,
83
- label: workspace.path
84
- }
85
- ];
86
- }
87
- }
88
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
89
- /* @__PURE__ */ jsx(Text, { color: colors.body, children: `Creating project in the workspace at ${chalk[colors.info](workspace.path)}.` }),
90
- /* @__PURE__ */ jsx(
91
- CreateProjectInput,
92
- {
93
- rows: {
94
- projectPath: {
95
- choices: possiblePaths
96
- }
97
- },
98
- marginTop: 1,
99
- values: createProjectInputResult,
100
- onChange: setCreateProjectInputResult,
101
- onComplete: setCreateProjectInputResult
102
- }
103
- ),
104
- status === "in-progress" || status === "finished" ? /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginTop: 1, children: [
105
- /* @__PURE__ */ jsx(Header, { icon: icons.success, marginBottom: 1, showSpinner: status === "in-progress", children: /* @__PURE__ */ jsx(Text, { children: "Creating project..." }) }),
106
- jobs.map((job) => /* @__PURE__ */ jsx(Text, { children: `${icons.info} ${job}` }, job))
107
- ] }) : null,
108
- status === "finished" ? /* @__PURE__ */ jsx(Header, { icon: icons.success, marginTop: 1, children: /* @__PURE__ */ jsx(Text, { children: "Done." }) }) : null
109
- ] });
13
+ function CreateProject({ args, workspace }) {
14
+ let [status, setStatus] = useState("not-started");
15
+ let [subscription, setSubscription] = useState(null);
16
+ let [jobs, setJobs] = useState([]);
17
+ let [createProjectInputResult, setCreateProjectInputResult] = useState(() => ({
18
+ projectName: {
19
+ value: args.options.name ?? "",
20
+ isComplete: !!args.options.name
21
+ },
22
+ projectPath: {
23
+ value: "",
24
+ isComplete: false
25
+ },
26
+ templateId: {
27
+ value: args.options.template ?? "",
28
+ isComplete: !!args.options.template
29
+ }
30
+ }));
31
+ let { exit } = useProgram();
32
+ useEffect(() => {
33
+ if (Object.entries(createProjectInputResult).every(([, result]) => result.isComplete)) setStatus("in-progress");
34
+ }, [createProjectInputResult]);
35
+ useEffect(() => {
36
+ if (status === "in-progress" && !subscription) {
37
+ let newSubscription = runCreateProject({
38
+ projectPath: createProjectInputResult.projectPath.value,
39
+ templateId: createProjectInputResult.templateId.value,
40
+ projectName: createProjectInputResult.projectName.value,
41
+ workspace,
42
+ args
43
+ }).subscribe({
44
+ next(value) {
45
+ setJobs((previousJobs) => [...previousJobs, value]);
46
+ },
47
+ error(error) {
48
+ exit(error);
49
+ },
50
+ complete() {
51
+ newSubscription.unsubscribe();
52
+ setStatus("finished");
53
+ }
54
+ });
55
+ setSubscription(newSubscription);
56
+ }
57
+ return () => {
58
+ if (subscription) subscription.unsubscribe();
59
+ };
60
+ }, [
61
+ args,
62
+ createProjectInputResult,
63
+ exit,
64
+ status,
65
+ subscription,
66
+ workspace
67
+ ]);
68
+ let possiblePaths = [];
69
+ if (createProjectInputResult.projectName.value) {
70
+ let destinationDirectory = packageNameToDirectory(createProjectInputResult.projectName.value);
71
+ if (workspace.projectGlobs) {
72
+ possiblePaths = workspace.projectGlobs.filter((projectGlob) => ONLY_ONE_STAR_REGEXP.test(projectGlob)).map((projectGlob) => projectGlob.replace(/\*/, destinationDirectory)).map((projectGlob) => path.join(workspace.path, projectGlob)).map((projectPath) => ({
73
+ value: projectPath,
74
+ label: path.relative(workspace.path, projectPath).replace("\\", "/")
75
+ }));
76
+ if (!possiblePaths.length) possiblePaths = workspace.projectGlobs.filter((projectGlob) => !ONLY_ONE_STAR_REGEXP.test(projectGlob)).map((projectGlob) => path.join(workspace.path, projectGlob)).map((projectPath) => ({
77
+ value: projectPath,
78
+ label: path.relative(workspace.path, projectPath).replace("\\", "/")
79
+ }));
80
+ if (!possiblePaths.length) possiblePaths = [{
81
+ value: workspace.path,
82
+ label: workspace.path
83
+ }];
84
+ } else possiblePaths = [{
85
+ value: workspace.path,
86
+ label: workspace.path
87
+ }];
88
+ }
89
+ return /* @__PURE__ */ jsxs(Box, {
90
+ flexDirection: "column",
91
+ children: [
92
+ /* @__PURE__ */ jsx(Text, {
93
+ color: colors.body,
94
+ children: `Creating project in the workspace at ${chalk[colors.info](workspace.path)}.`
95
+ }),
96
+ /* @__PURE__ */ jsx(CreateProjectInput, {
97
+ rows: { projectPath: { choices: possiblePaths } },
98
+ marginTop: 1,
99
+ values: createProjectInputResult,
100
+ onChange: setCreateProjectInputResult,
101
+ onComplete: setCreateProjectInputResult
102
+ }),
103
+ status === "in-progress" || status === "finished" ? /* @__PURE__ */ jsxs(Box, {
104
+ flexDirection: "column",
105
+ marginTop: 1,
106
+ children: [/* @__PURE__ */ jsx(Header, {
107
+ icon: icons.success,
108
+ marginBottom: 1,
109
+ showSpinner: status === "in-progress",
110
+ children: /* @__PURE__ */ jsx(Text, { children: "Creating project..." })
111
+ }), jobs.map((job) => /* @__PURE__ */ jsx(Text, { children: `${icons.info} ${job}` }, job))]
112
+ }) : null,
113
+ status === "finished" ? /* @__PURE__ */ jsx(Header, {
114
+ icon: icons.success,
115
+ marginTop: 1,
116
+ children: /* @__PURE__ */ jsx(Text, { children: "Done." })
117
+ }) : null
118
+ ]
119
+ });
110
120
  }
111
- //# sourceMappingURL=CreateProject.js.map
121
+
122
+ //#endregion
123
+ export { CreateProject };
@@ -1,35 +1,28 @@
1
- "use strict";
2
1
  import { createForm } from "@jakubmazanec/cli";
2
+
3
+ //#region source/commands/create-project/CreateProjectInput.ts
3
4
  const TEMPLATE_ID_REGEXP = /^.+:.+$/;
4
5
  const PROJECT_NAME_ID_REGEXP = /^[\d./@a-z-]+$/;
5
- export const CreateProjectInput = createForm({
6
- rows: {
7
- templateId: {
8
- type: "text",
9
- label: "What template do you want to use?",
10
- validate: (value) => {
11
- if (!TEMPLATE_ID_REGEXP.test(value)) {
12
- throw new Error(
13
- "Template ID must consist of a module ID and a template name separated by a colon."
14
- );
15
- }
16
- }
17
- },
18
- projectName: {
19
- type: "text",
20
- label: "What is the project name?",
21
- validate: (value) => {
22
- if (!PROJECT_NAME_ID_REGEXP.test(value)) {
23
- throw new Error(
24
- "Project name can contain only lowercase letters, numbers, hyphen, @, dot or /."
25
- );
26
- }
27
- }
28
- },
29
- projectPath: {
30
- type: "select",
31
- label: "What is the project location?"
32
- }
33
- }
34
- });
35
- //# sourceMappingURL=CreateProjectInput.js.map
6
+ const CreateProjectInput = createForm({ rows: {
7
+ templateId: {
8
+ type: "text",
9
+ label: "What template do you want to use?",
10
+ validate: (value) => {
11
+ if (!TEMPLATE_ID_REGEXP.test(value)) throw new Error("Template ID must consist of a module ID and a template name separated by a colon.");
12
+ }
13
+ },
14
+ projectName: {
15
+ type: "text",
16
+ label: "What is the project name?",
17
+ validate: (value) => {
18
+ if (!PROJECT_NAME_ID_REGEXP.test(value)) throw new Error("Project name can contain only lowercase letters, numbers, hyphen, @, dot or /.");
19
+ }
20
+ },
21
+ projectPath: {
22
+ type: "select",
23
+ label: "What is the project location?"
24
+ }
25
+ } });
26
+
27
+ //#endregion
28
+ export { CreateProjectInput };
@@ -1,37 +1,27 @@
1
- "use strict";
2
- import { jsx } from "react/jsx-runtime";
1
+ import { CreateProject } from "./CreateProject.js";
2
+ import { Workspace } from "../../workspace/Workspace.js";
3
3
  import { Command } from "@jakubmazanec/cli";
4
4
  import path from "node:path";
5
- import { Workspace } from "../../workspace.js";
6
- import { CreateProject } from "./CreateProject.js";
7
- export const createProjectCommand = new Command(
8
- "create project",
9
- async (args, program) => {
10
- let targetPath = path.resolve(process.cwd(), args.options.path ?? "");
11
- let workspace = await Workspace.findAndRead(targetPath, { throwIfNotFound: true });
12
- if (workspace.errors[0]) {
13
- throw workspace.errors[0];
14
- }
15
- for (let project of workspace.projects) {
16
- if (project.errors[0]) {
17
- throw project.errors[0];
18
- }
19
- }
20
- await program.renderElement(/* @__PURE__ */ jsx(CreateProject, { args, workspace }));
21
- },
22
- {
23
- description: "Creates a new project in an existing workspace.",
24
- options: {
25
- path: {
26
- type: "string"
27
- },
28
- template: {
29
- type: "string"
30
- },
31
- name: {
32
- type: "string"
33
- }
34
- }
35
- }
36
- );
37
- //# sourceMappingURL=createProjectCommand.js.map
5
+ import { jsx } from "react/jsx-runtime";
6
+
7
+ //#region source/commands/create-project/createProjectCommand.tsx
8
+ const createProjectCommand = new Command("create project", async (args, program) => {
9
+ let targetPath = path.resolve(process.cwd(), args.options.path ?? "");
10
+ let workspace = await Workspace.findAndRead(targetPath, { throwIfNotFound: true });
11
+ if (workspace.errors[0]) throw workspace.errors[0];
12
+ for (let project of workspace.projects) if (project.errors[0]) throw project.errors[0];
13
+ await program.renderElement(/* @__PURE__ */ jsx(CreateProject, {
14
+ args,
15
+ workspace
16
+ }));
17
+ }, {
18
+ description: "Creates a new project in an existing workspace.",
19
+ options: {
20
+ path: { type: "string" },
21
+ template: { type: "string" },
22
+ name: { type: "string" }
23
+ }
24
+ });
25
+
26
+ //#endregion
27
+ export { createProjectCommand };
@@ -1,29 +1,26 @@
1
- "use strict";
2
1
  import Observable from "zen-observable";
3
- export function runCreateProject({
4
- projectPath,
5
- templateId,
6
- projectName,
7
- workspace,
8
- args
9
- }) {
10
- return new Observable((observer) => {
11
- (async () => {
12
- observer.next("Creating files");
13
- let project = await workspace.createProject({
14
- projectPath,
15
- projectName,
16
- templateId,
17
- args
18
- });
19
- observer.next("Updating the new project");
20
- project.config.template ??= templateId;
21
- await project.update({ args });
22
- })().then(() => {
23
- observer.complete();
24
- }).catch((error) => {
25
- observer.error(error);
26
- });
27
- });
2
+
3
+ //#region source/commands/create-project/runCreateProject.ts
4
+ function runCreateProject({ projectPath, templateId, projectName, workspace, args }) {
5
+ return new Observable((observer) => {
6
+ (async () => {
7
+ observer.next("Creating files");
8
+ let project = await workspace.createProject({
9
+ projectPath,
10
+ projectName,
11
+ templateId,
12
+ args
13
+ });
14
+ observer.next("Updating the new project");
15
+ project.config.template ??= templateId;
16
+ await project.update({ args });
17
+ })().then(() => {
18
+ observer.complete();
19
+ }).catch((error) => {
20
+ observer.error(error);
21
+ });
22
+ });
28
23
  }
29
- //# sourceMappingURL=runCreateProject.js.map
24
+
25
+ //#endregion
26
+ export { runCreateProject };
@@ -1,68 +1,85 @@
1
- "use strict";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- import { colors, Header, icons, useProgram } from "@jakubmazanec/cli";
1
+ import { CreateWorkspaceInput } from "./CreateWorkspaceInput.js";
2
+ import { runCreateWorkspace } from "./runCreateWorkspace.js";
3
+ import { Header, colors, icons, useProgram } from "@jakubmazanec/cli";
4
4
  import chalk from "chalk";
5
5
  import { Box, Text } from "ink";
6
6
  import path from "node:path";
7
7
  import { useEffect, useState } from "react";
8
- import { CreateWorkspaceInput } from "./CreateWorkspaceInput.js";
9
- import { runCreateWorkspace } from "./runCreateWorkspace.js";
10
- export function CreateWorkspace({ args }) {
11
- let [status, setStatus] = useState("not-started");
12
- let [subscription, setSubscription] = useState(null);
13
- let [jobs, setJobs] = useState([]);
14
- let [createWorkspaceInputResult, setCreateWorkspaceInputResult] = useState(() => ({
15
- templateId: { value: args.options.template ?? "", isComplete: !!args.options.template }
16
- }));
17
- let { exit } = useProgram();
18
- let workspacePath = path.resolve(process.cwd(), args.options.path ?? "");
19
- useEffect(() => {
20
- if (Object.entries(createWorkspaceInputResult).every(([, result]) => result.isComplete)) {
21
- setStatus("in-progress");
22
- }
23
- }, [createWorkspaceInputResult]);
24
- useEffect(() => {
25
- if (status === "in-progress" && !subscription) {
26
- let newSubscription = runCreateWorkspace({
27
- workspacePath,
28
- templateId: createWorkspaceInputResult.templateId.value,
29
- args
30
- }).subscribe({
31
- next(value) {
32
- setJobs((previousJobs) => [...previousJobs, value]);
33
- },
34
- error(error) {
35
- exit(error);
36
- },
37
- complete() {
38
- newSubscription.unsubscribe();
39
- setStatus("finished");
40
- }
41
- });
42
- setSubscription(newSubscription);
43
- }
44
- return () => {
45
- if (subscription) {
46
- subscription.unsubscribe();
47
- }
48
- };
49
- }, [createWorkspaceInputResult, status, subscription, args, exit, workspacePath]);
50
- return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [
51
- /* @__PURE__ */ jsx(Text, { children: `Creating workspace at ${chalk[colors.info](workspacePath)}.` }),
52
- /* @__PURE__ */ jsx(
53
- CreateWorkspaceInput,
54
- {
55
- marginTop: 1,
56
- values: createWorkspaceInputResult,
57
- onChange: setCreateWorkspaceInputResult,
58
- onComplete: setCreateWorkspaceInputResult
59
- }
60
- ),
61
- status === "in-progress" || status === "finished" ? /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginTop: 1, children: [
62
- /* @__PURE__ */ jsx(Header, { icon: icons.success, marginBottom: 1, showSpinner: status === "in-progress", children: /* @__PURE__ */ jsx(Text, { children: "Creating workspace..." }) }),
63
- jobs.map((job) => /* @__PURE__ */ jsx(Text, { children: `${icons.info} ${job}` }, job))
64
- ] }) : null,
65
- status === "finished" ? /* @__PURE__ */ jsx(Header, { icon: icons.success, marginTop: 1, children: /* @__PURE__ */ jsx(Text, { children: "Done." }) }) : null
66
- ] });
8
+ import { jsx, jsxs } from "react/jsx-runtime";
9
+
10
+ //#region source/commands/create-workspace/CreateWorkspace.tsx
11
+ function CreateWorkspace({ args }) {
12
+ let [status, setStatus] = useState("not-started");
13
+ let [subscription, setSubscription] = useState(null);
14
+ let [jobs, setJobs] = useState([]);
15
+ let [createWorkspaceInputResult, setCreateWorkspaceInputResult] = useState(() => ({ templateId: {
16
+ value: args.options.template ?? "",
17
+ isComplete: !!args.options.template
18
+ } }));
19
+ let { exit } = useProgram();
20
+ let workspacePath = path.resolve(process.cwd(), args.options.path ?? "");
21
+ useEffect(() => {
22
+ if (Object.entries(createWorkspaceInputResult).every(([, result]) => result.isComplete)) setStatus("in-progress");
23
+ }, [createWorkspaceInputResult]);
24
+ useEffect(() => {
25
+ if (status === "in-progress" && !subscription) {
26
+ let newSubscription = runCreateWorkspace({
27
+ workspacePath,
28
+ templateId: createWorkspaceInputResult.templateId.value,
29
+ args
30
+ }).subscribe({
31
+ next(value) {
32
+ setJobs((previousJobs) => [...previousJobs, value]);
33
+ },
34
+ error(error) {
35
+ exit(error);
36
+ },
37
+ complete() {
38
+ newSubscription.unsubscribe();
39
+ setStatus("finished");
40
+ }
41
+ });
42
+ setSubscription(newSubscription);
43
+ }
44
+ return () => {
45
+ if (subscription) subscription.unsubscribe();
46
+ };
47
+ }, [
48
+ createWorkspaceInputResult,
49
+ status,
50
+ subscription,
51
+ args,
52
+ exit,
53
+ workspacePath
54
+ ]);
55
+ return /* @__PURE__ */ jsxs(Box, {
56
+ flexDirection: "column",
57
+ children: [
58
+ /* @__PURE__ */ jsx(Text, { children: `Creating workspace at ${chalk[colors.info](workspacePath)}.` }),
59
+ /* @__PURE__ */ jsx(CreateWorkspaceInput, {
60
+ marginTop: 1,
61
+ values: createWorkspaceInputResult,
62
+ onChange: setCreateWorkspaceInputResult,
63
+ onComplete: setCreateWorkspaceInputResult
64
+ }),
65
+ status === "in-progress" || status === "finished" ? /* @__PURE__ */ jsxs(Box, {
66
+ flexDirection: "column",
67
+ marginTop: 1,
68
+ children: [/* @__PURE__ */ jsx(Header, {
69
+ icon: icons.success,
70
+ marginBottom: 1,
71
+ showSpinner: status === "in-progress",
72
+ children: /* @__PURE__ */ jsx(Text, { children: "Creating workspace..." })
73
+ }), jobs.map((job) => /* @__PURE__ */ jsx(Text, { children: `${icons.info} ${job}` }, job))]
74
+ }) : null,
75
+ status === "finished" ? /* @__PURE__ */ jsx(Header, {
76
+ icon: icons.success,
77
+ marginTop: 1,
78
+ children: /* @__PURE__ */ jsx(Text, { children: "Done." })
79
+ }) : null
80
+ ]
81
+ });
67
82
  }
68
- //# sourceMappingURL=CreateWorkspace.js.map
83
+
84
+ //#endregion
85
+ export { CreateWorkspace };
@@ -1,19 +1,14 @@
1
- "use strict";
2
1
  import { createForm } from "@jakubmazanec/cli";
2
+
3
+ //#region source/commands/create-workspace/CreateWorkspaceInput.ts
3
4
  const TEMPLATE_ID_REGEXP = /^.+:.+$/;
4
- export const CreateWorkspaceInput = createForm({
5
- rows: {
6
- templateId: {
7
- type: "text",
8
- label: "Enter template ID:",
9
- validate: (value) => {
10
- if (!TEMPLATE_ID_REGEXP.test(value)) {
11
- throw new Error(
12
- "Template ID must consist of a module ID and a template name separated by a colon."
13
- );
14
- }
15
- }
16
- }
17
- }
18
- });
19
- //# sourceMappingURL=CreateWorkspaceInput.js.map
5
+ const CreateWorkspaceInput = createForm({ rows: { templateId: {
6
+ type: "text",
7
+ label: "Enter template ID:",
8
+ validate: (value) => {
9
+ if (!TEMPLATE_ID_REGEXP.test(value)) throw new Error("Template ID must consist of a module ID and a template name separated by a colon.");
10
+ }
11
+ } } });
12
+
13
+ //#endregion
14
+ export { CreateWorkspaceInput };
@@ -1,22 +1,17 @@
1
- "use strict";
2
- import { jsx } from "react/jsx-runtime";
3
- import { Command } from "@jakubmazanec/cli";
4
1
  import { CreateWorkspace } from "./CreateWorkspace.js";
5
- export const createWorkspaceCommand = new Command(
6
- "create workspace",
7
- async (args, program) => {
8
- await program.renderElement(/* @__PURE__ */ jsx(CreateWorkspace, { args }));
9
- },
10
- {
11
- description: "Creates a new workspacee.",
12
- options: {
13
- path: {
14
- type: "string"
15
- },
16
- template: {
17
- type: "string"
18
- }
19
- }
20
- }
21
- );
22
- //# sourceMappingURL=createWorkspaceCommand.js.map
2
+ import { Command } from "@jakubmazanec/cli";
3
+ import { jsx } from "react/jsx-runtime";
4
+
5
+ //#region source/commands/create-workspace/createWorkspaceCommand.tsx
6
+ const createWorkspaceCommand = new Command("create workspace", async (args, program) => {
7
+ await program.renderElement(/* @__PURE__ */ jsx(CreateWorkspace, { args }));
8
+ }, {
9
+ description: "Creates a new workspacee.",
10
+ options: {
11
+ path: { type: "string" },
12
+ template: { type: "string" }
13
+ }
14
+ });
15
+
16
+ //#endregion
17
+ export { createWorkspaceCommand };