@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.
- package/build/commands/create-project/CreateProject.js +117 -105
- package/build/commands/create-project/CreateProjectInput.js +25 -32
- package/build/commands/create-project/createProjectCommand.js +25 -35
- package/build/commands/create-project/runCreateProject.js +24 -27
- package/build/commands/create-workspace/CreateWorkspace.js +80 -63
- package/build/commands/create-workspace/CreateWorkspaceInput.js +12 -17
- package/build/commands/create-workspace/createWorkspaceCommand.js +16 -21
- package/build/commands/create-workspace/runCreateWorkspace.js +24 -21
- package/build/commands/internals/packageNameToDirectory.js +9 -11
- package/build/commands/update-workspace/UpdateWorkspace.js +56 -33
- package/build/commands/update-workspace/runUpdateWorkspace.js +20 -17
- package/build/commands/update-workspace/updateWorkspaceCommand.js +21 -29
- package/build/constants.js +14 -11
- package/build/main.js +28 -5
- package/build/run.js +14 -12
- package/build/template/CarsonTemplateConfig.js +6 -7
- package/build/template/CarsonTemplateError.js +18 -16
- package/build/template/TemplateAttributes.js +12 -11
- package/build/template/TemplateData.js +10 -7
- package/build/template/applyTemplateRenders.js +64 -93
- package/build/template/internals/TemplateRenderSnapshot.js +10 -7
- package/build/template/internals/TemplateRenderSnapshots.js +6 -3
- package/build/template/internals/createUsingTemplateRender.js +36 -39
- package/build/template/internals/deleteUsingTemplateRenderSnapshot.js +18 -21
- package/build/template/internals/importCarsonTemplate.js +9 -6
- package/build/template/internals/insertUsingTemplateRender.js +30 -37
- package/build/template/internals/loadTemplateRenderSnapshots.js +13 -14
- package/build/template/internals/merge.js +16 -28
- package/build/template/internals/mergeUsingTemplateRender.js +38 -45
- package/build/template/internals/overwriteUsingTemplateRender.js +11 -8
- package/build/template/internals/parseCarsonTemplateId.js +9 -10
- package/build/template/internals/prettify.js +18 -17
- package/build/template/internals/readCarsonTemplate.js +33 -41
- package/build/template/internals/resolveModule.js +9 -7
- package/build/template/internals/saveTemplateRenderSnapshots.js +54 -57
- package/build/template/internals/simplify.js +14 -19
- package/build/template/internals/uninsertUsingTemplateRenderSnapshot.js +22 -28
- package/build/template/internals/unmerge.js +21 -31
- package/build/template/internals/unmergeUsingTemplateRenderSnapshot.js +30 -31
- package/build/template/renderCarsonTemplate.js +42 -46
- package/build/workspace/Project.js +154 -205
- package/build/workspace/ProjectConfig.js +6 -5
- package/build/workspace/ProjectError.js +18 -16
- package/build/workspace/Workspace.js +382 -553
- package/build/workspace/WorkspaceConfig.js +8 -5
- package/build/workspace/WorkspaceDependencies.js +117 -143
- package/build/workspace/WorkspaceError.js +24 -22
- package/build/workspace/internals/compareProjectPath.js +8 -9
- package/build/workspace/internals/compareSemver.js +22 -18
- package/build/workspace/internals/compareWorkspaceDependencyProjectName.js +8 -9
- package/build/workspace/internals/containsProject.js +15 -21
- package/build/workspace/internals/containsWorkspace.js +11 -18
- package/build/workspace/internals/getPackageJsonWorkspaces.js +17 -25
- package/build/workspace/internals/getRepositoryBranches.js +21 -23
- package/build/workspace/internals/getRepositoryUrl.js +16 -17
- package/build/workspace/saveProjectConfig.js +17 -13
- package/build/workspace/saveWorkspaceConfig.js +17 -20
- package/package.json +12 -12
- package/build/commands/create-project/CreateProject.js.map +0 -7
- package/build/commands/create-project/CreateProjectInput.js.map +0 -7
- package/build/commands/create-project/createProjectCommand.js.map +0 -7
- package/build/commands/create-project/runCreateProject.js.map +0 -7
- package/build/commands/create-project.js +0 -6
- package/build/commands/create-project.js.map +0 -7
- package/build/commands/create-workspace/CreateWorkspace.js.map +0 -7
- package/build/commands/create-workspace/CreateWorkspaceInput.js.map +0 -7
- package/build/commands/create-workspace/createWorkspaceCommand.js.map +0 -7
- package/build/commands/create-workspace/runCreateWorkspace.js.map +0 -7
- package/build/commands/create-workspace.js +0 -6
- package/build/commands/create-workspace.js.map +0 -7
- package/build/commands/internals/CommandStatus.js +0 -2
- package/build/commands/internals/CommandStatus.js.map +0 -7
- package/build/commands/internals/packageNameToDirectory.js.map +0 -7
- package/build/commands/internals.js +0 -3
- package/build/commands/internals.js.map +0 -7
- package/build/commands/update-workspace/UpdateWorkspace.js.map +0 -7
- package/build/commands/update-workspace/runUpdateWorkspace.js.map +0 -7
- package/build/commands/update-workspace/updateWorkspaceCommand.js.map +0 -7
- package/build/commands/update-workspace.js +0 -5
- package/build/commands/update-workspace.js.map +0 -7
- package/build/commands.js +0 -5
- package/build/commands.js.map +0 -7
- package/build/constants.js.map +0 -7
- package/build/main.js.map +0 -7
- package/build/modules.d.js +0 -2
- package/build/modules.d.js.map +0 -7
- package/build/run.js.map +0 -7
- package/build/template/CarsonTemplate.js +0 -2
- package/build/template/CarsonTemplate.js.map +0 -7
- package/build/template/CarsonTemplateConfig.js.map +0 -7
- package/build/template/CarsonTemplateError.js.map +0 -7
- package/build/template/TemplateAttributes.js.map +0 -7
- package/build/template/TemplateData.js.map +0 -7
- package/build/template/TemplateRender.js +0 -2
- package/build/template/TemplateRender.js.map +0 -7
- package/build/template/TemplateRenders.js +0 -2
- package/build/template/TemplateRenders.js.map +0 -7
- package/build/template/applyTemplateRenders.js.map +0 -7
- package/build/template/internals/TemplateRenderSnapshot.js.map +0 -7
- package/build/template/internals/TemplateRenderSnapshots.js.map +0 -7
- package/build/template/internals/createUsingTemplateRender.js.map +0 -7
- package/build/template/internals/deleteUsingTemplateRenderSnapshot.js.map +0 -7
- package/build/template/internals/importCarsonTemplate.js.map +0 -7
- package/build/template/internals/insertUsingTemplateRender.js.map +0 -7
- package/build/template/internals/loadTemplateRenderSnapshots.js.map +0 -7
- package/build/template/internals/merge.js.map +0 -7
- package/build/template/internals/mergeUsingTemplateRender.js.map +0 -7
- package/build/template/internals/overwriteUsingTemplateRender.js.map +0 -7
- package/build/template/internals/parseCarsonTemplateId.js.map +0 -7
- package/build/template/internals/prettify.js.map +0 -7
- package/build/template/internals/readCarsonTemplate.js.map +0 -7
- package/build/template/internals/resolveModule.js.map +0 -7
- package/build/template/internals/saveTemplateRenderSnapshots.js.map +0 -7
- package/build/template/internals/simplify.js.map +0 -7
- package/build/template/internals/uninsertUsingTemplateRenderSnapshot.js.map +0 -7
- package/build/template/internals/unmerge.js.map +0 -7
- package/build/template/internals/unmergeUsingTemplateRenderSnapshot.js.map +0 -7
- package/build/template/internals.js +0 -21
- package/build/template/internals.js.map +0 -7
- package/build/template/renderCarsonTemplate.js.map +0 -7
- package/build/template.js +0 -8
- package/build/template.js.map +0 -7
- package/build/workspace/Project.js.map +0 -7
- package/build/workspace/ProjectConfig.js.map +0 -7
- package/build/workspace/ProjectCreateOptions.js +0 -2
- package/build/workspace/ProjectCreateOptions.js.map +0 -7
- package/build/workspace/ProjectError.js.map +0 -7
- package/build/workspace/ProjectOptions.js +0 -2
- package/build/workspace/ProjectOptions.js.map +0 -7
- package/build/workspace/ProjectUpdateOptions.js +0 -2
- package/build/workspace/ProjectUpdateOptions.js.map +0 -7
- package/build/workspace/Workspace.js.map +0 -7
- package/build/workspace/WorkspaceConfig.js.map +0 -7
- package/build/workspace/WorkspaceCreateOptions.js +0 -2
- package/build/workspace/WorkspaceCreateOptions.js.map +0 -7
- package/build/workspace/WorkspaceCreateProjectOptions.js +0 -2
- package/build/workspace/WorkspaceCreateProjectOptions.js.map +0 -7
- package/build/workspace/WorkspaceDependencies.js.map +0 -7
- package/build/workspace/WorkspaceDependenciesFromWorkspaceOptions.js +0 -2
- package/build/workspace/WorkspaceDependenciesFromWorkspaceOptions.js.map +0 -7
- package/build/workspace/WorkspaceDependenciesGetVersionsOptions.js +0 -2
- package/build/workspace/WorkspaceDependenciesGetVersionsOptions.js.map +0 -7
- package/build/workspace/WorkspaceDependency.js +0 -2
- package/build/workspace/WorkspaceDependency.js.map +0 -7
- package/build/workspace/WorkspaceDependencyProject.js +0 -2
- package/build/workspace/WorkspaceDependencyProject.js.map +0 -7
- package/build/workspace/WorkspaceError.js.map +0 -7
- package/build/workspace/WorkspaceFindAndReadOptions.js +0 -2
- package/build/workspace/WorkspaceFindAndReadOptions.js.map +0 -7
- package/build/workspace/WorkspaceOptions.js +0 -2
- package/build/workspace/WorkspaceOptions.js.map +0 -7
- package/build/workspace/WorkspaceOptionsProject.js +0 -2
- package/build/workspace/WorkspaceOptionsProject.js.map +0 -7
- package/build/workspace/WorkspacePackageJson.js +0 -2
- package/build/workspace/WorkspacePackageJson.js.map +0 -7
- package/build/workspace/WorkspaceProjectGlobs.js +0 -2
- package/build/workspace/WorkspaceProjectGlobs.js.map +0 -7
- package/build/workspace/WorkspaceProjects.js +0 -2
- package/build/workspace/WorkspaceProjects.js.map +0 -7
- package/build/workspace/WorkspaceRepository.js +0 -2
- package/build/workspace/WorkspaceRepository.js.map +0 -7
- package/build/workspace/WorkspaceUpdateOptions.js +0 -2
- package/build/workspace/WorkspaceUpdateOptions.js.map +0 -7
- package/build/workspace/internals/compareProjectPath.js.map +0 -7
- package/build/workspace/internals/compareSemver.js.map +0 -7
- package/build/workspace/internals/compareWorkspaceDependencyProjectName.js.map +0 -7
- package/build/workspace/internals/containsProject.js.map +0 -7
- package/build/workspace/internals/containsWorkspace.js.map +0 -7
- package/build/workspace/internals/getPackageJsonWorkspaces.js.map +0 -7
- package/build/workspace/internals/getRepositoryBranches.js.map +0 -7
- package/build/workspace/internals/getRepositoryUrl.js.map +0 -7
- package/build/workspace/internals.js +0 -10
- package/build/workspace/internals.js.map +0 -7
- package/build/workspace/saveProjectConfig.js.map +0 -7
- package/build/workspace/saveWorkspaceConfig.js.map +0 -7
- package/build/workspace.js +0 -11
- package/build/workspace.js.map +0 -7
|
@@ -1,111 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
2
|
-
import {
|
|
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 {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { runCreateProject };
|
|
@@ -1,68 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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 };
|