@jakubmazanec/carson 0.1.0-11dd4a3
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/LICENSE.md +661 -0
- package/README.md +237 -0
- package/bin/carson.js +3 -0
- package/dist/commands/create-project/CreateProject.d.ts +8 -0
- package/dist/commands/create-project/CreateProject.js +138 -0
- package/dist/commands/create-project/CreateProject.js.map +1 -0
- package/dist/commands/create-project/CreateProjectInput.d.ts +20 -0
- package/dist/commands/create-project/CreateProjectInput.js +31 -0
- package/dist/commands/create-project/CreateProjectInput.js.map +1 -0
- package/dist/commands/create-project/createProjectCommand.d.ts +12 -0
- package/dist/commands/create-project/createProjectCommand.js +31 -0
- package/dist/commands/create-project/createProjectCommand.js.map +1 -0
- package/dist/commands/create-project/runCreateProject.d.ts +13 -0
- package/dist/commands/create-project/runCreateProject.js +34 -0
- package/dist/commands/create-project/runCreateProject.js.map +1 -0
- package/dist/commands/create-project.d.ts +4 -0
- package/dist/commands/create-project.js +6 -0
- package/dist/commands/create-project.js.map +1 -0
- package/dist/commands/create-workspace/CreateWorkspace.d.ts +7 -0
- package/dist/commands/create-workspace/CreateWorkspace.js +102 -0
- package/dist/commands/create-workspace/CreateWorkspace.js.map +1 -0
- package/dist/commands/create-workspace/CreateWorkspaceInput.d.ts +11 -0
- package/dist/commands/create-workspace/CreateWorkspaceInput.js +17 -0
- package/dist/commands/create-workspace/CreateWorkspaceInput.js.map +1 -0
- package/dist/commands/create-workspace/createWorkspaceCommand.d.ts +9 -0
- package/dist/commands/create-workspace/createWorkspaceCommand.js +30 -0
- package/dist/commands/create-workspace/createWorkspaceCommand.js.map +1 -0
- package/dist/commands/create-workspace/runCreateWorkspace.d.ts +10 -0
- package/dist/commands/create-workspace/runCreateWorkspace.js +33 -0
- package/dist/commands/create-workspace/runCreateWorkspace.js.map +1 -0
- package/dist/commands/create-workspace.d.ts +4 -0
- package/dist/commands/create-workspace.js +6 -0
- package/dist/commands/create-workspace.js.map +1 -0
- package/dist/commands/internals/packageNameToDirectory.d.ts +1 -0
- package/dist/commands/internals/packageNameToDirectory.js +12 -0
- package/dist/commands/internals/packageNameToDirectory.js.map +1 -0
- package/dist/commands/internals.d.ts +1 -0
- package/dist/commands/internals.js +3 -0
- package/dist/commands/internals.js.map +1 -0
- package/dist/commands/update-workspace/UpdateWorkspace.d.ts +8 -0
- package/dist/commands/update-workspace/UpdateWorkspace.js +71 -0
- package/dist/commands/update-workspace/UpdateWorkspace.js.map +1 -0
- package/dist/commands/update-workspace/runUpdateWorkspace.d.ts +10 -0
- package/dist/commands/update-workspace/runUpdateWorkspace.js +25 -0
- package/dist/commands/update-workspace/runUpdateWorkspace.js.map +1 -0
- package/dist/commands/update-workspace/updateWorkspaceCommand.d.ts +6 -0
- package/dist/commands/update-workspace/updateWorkspaceCommand.js +25 -0
- package/dist/commands/update-workspace/updateWorkspaceCommand.js.map +1 -0
- package/dist/commands/update-workspace.d.ts +3 -0
- package/dist/commands/update-workspace.js +5 -0
- package/dist/commands/update-workspace.js.map +1 -0
- package/dist/commands.d.ts +3 -0
- package/dist/commands.js +5 -0
- package/dist/commands.js.map +1 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +16 -0
- package/dist/constants.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.js +5 -0
- package/dist/main.js.map +1 -0
- package/dist/modules.d.js +2 -0
- package/dist/modules.d.js.map +1 -0
- package/dist/run.d.ts +1 -0
- package/dist/run.js +18 -0
- package/dist/run.js.map +1 -0
- package/dist/template/CarsonTemplate.d.ts +9 -0
- package/dist/template/CarsonTemplate.js +3 -0
- package/dist/template/CarsonTemplate.js.map +1 -0
- package/dist/template/CarsonTemplateConfig.d.ts +12 -0
- package/dist/template/CarsonTemplateConfig.js +7 -0
- package/dist/template/CarsonTemplateConfig.js.map +1 -0
- package/dist/template/TemplateAttributes.d.ts +9 -0
- package/dist/template/TemplateAttributes.js +16 -0
- package/dist/template/TemplateAttributes.js.map +1 -0
- package/dist/template/TemplateData.d.ts +35 -0
- package/dist/template/TemplateData.js +13 -0
- package/dist/template/TemplateData.js.map +1 -0
- package/dist/template/TemplateRender.d.ts +4 -0
- package/dist/template/TemplateRender.js +3 -0
- package/dist/template/TemplateRender.js.map +1 -0
- package/dist/template/TemplateRenderSnapshot.d.ts +27 -0
- package/dist/template/TemplateRenderSnapshot.js +11 -0
- package/dist/template/TemplateRenderSnapshot.js.map +1 -0
- package/dist/template/TemplateRenderSnapshots.d.ts +27 -0
- package/dist/template/TemplateRenderSnapshots.js +4 -0
- package/dist/template/TemplateRenderSnapshots.js.map +1 -0
- package/dist/template/TemplateRenders.d.ts +2 -0
- package/dist/template/TemplateRenders.js +3 -0
- package/dist/template/TemplateRenders.js.map +1 -0
- package/dist/template/applyTemplateRenders.d.ts +8 -0
- package/dist/template/applyTemplateRenders.js +60 -0
- package/dist/template/applyTemplateRenders.js.map +1 -0
- package/dist/template/createFileUsingTemplateRender.d.ts +2 -0
- package/dist/template/createFileUsingTemplateRender.js +12 -0
- package/dist/template/createFileUsingTemplateRender.js.map +1 -0
- package/dist/template/deleteFileUsingTemplateRender.d.ts +2 -0
- package/dist/template/deleteFileUsingTemplateRender.js +10 -0
- package/dist/template/deleteFileUsingTemplateRender.js.map +1 -0
- package/dist/template/importCarsonTemplate.d.ts +3 -0
- package/dist/template/importCarsonTemplate.js +8 -0
- package/dist/template/importCarsonTemplate.js.map +1 -0
- package/dist/template/insertUsingTemplateRender.d.ts +2 -0
- package/dist/template/insertUsingTemplateRender.js +29 -0
- package/dist/template/insertUsingTemplateRender.js.map +1 -0
- package/dist/template/internals/merge.d.ts +4 -0
- package/dist/template/internals/merge.js +30 -0
- package/dist/template/internals/merge.js.map +1 -0
- package/dist/template/internals/prettify.d.ts +1 -0
- package/dist/template/internals/prettify.js +25 -0
- package/dist/template/internals/prettify.js.map +1 -0
- package/dist/template/internals/unmerge.d.ts +4 -0
- package/dist/template/internals/unmerge.js +31 -0
- package/dist/template/internals/unmerge.js.map +1 -0
- package/dist/template/internals.d.ts +3 -0
- package/dist/template/internals.js +5 -0
- package/dist/template/internals.js.map +1 -0
- package/dist/template/loadTemplateRenderSnapshots.d.ts +7 -0
- package/dist/template/loadTemplateRenderSnapshots.js +14 -0
- package/dist/template/loadTemplateRenderSnapshots.js.map +1 -0
- package/dist/template/mergeFileUsingTemplateRender.d.ts +2 -0
- package/dist/template/mergeFileUsingTemplateRender.js +39 -0
- package/dist/template/mergeFileUsingTemplateRender.js.map +1 -0
- package/dist/template/overwriteFileUsingTemplateRender.d.ts +2 -0
- package/dist/template/overwriteFileUsingTemplateRender.js +12 -0
- package/dist/template/overwriteFileUsingTemplateRender.js.map +1 -0
- package/dist/template/parseTemplateId.d.ts +1 -0
- package/dist/template/parseTemplateId.js +12 -0
- package/dist/template/parseTemplateId.js.map +1 -0
- package/dist/template/readCarsonTemplate.d.ts +2 -0
- package/dist/template/readCarsonTemplate.js +39 -0
- package/dist/template/readCarsonTemplate.js.map +1 -0
- package/dist/template/renderTemplate.d.ts +7 -0
- package/dist/template/renderTemplate.js +19 -0
- package/dist/template/renderTemplate.js.map +1 -0
- package/dist/template/resolveTemplateModule.d.ts +1 -0
- package/dist/template/resolveTemplateModule.js +9 -0
- package/dist/template/resolveTemplateModule.js.map +1 -0
- package/dist/template/saveTemplateRenderSnapshots.d.ts +2 -0
- package/dist/template/saveTemplateRenderSnapshots.js +23 -0
- package/dist/template/saveTemplateRenderSnapshots.js.map +1 -0
- package/dist/template/uninsertUsingTemplateRender.d.ts +2 -0
- package/dist/template/uninsertUsingTemplateRender.js +29 -0
- package/dist/template/uninsertUsingTemplateRender.js.map +1 -0
- package/dist/template/unmergeFileUsingTemplateRender.d.ts +2 -0
- package/dist/template/unmergeFileUsingTemplateRender.js +39 -0
- package/dist/template/unmergeFileUsingTemplateRender.js.map +1 -0
- package/dist/template.d.ts +20 -0
- package/dist/template.js +22 -0
- package/dist/template.js.map +1 -0
- package/dist/workspace/Project.d.ts +33 -0
- package/dist/workspace/Project.js +184 -0
- package/dist/workspace/Project.js.map +1 -0
- package/dist/workspace/ProjectConfig.d.ts +9 -0
- package/dist/workspace/ProjectConfig.js +6 -0
- package/dist/workspace/ProjectConfig.js.map +1 -0
- package/dist/workspace/ProjectCreateOptions.d.ts +8 -0
- package/dist/workspace/ProjectCreateOptions.js +3 -0
- package/dist/workspace/ProjectCreateOptions.js.map +1 -0
- package/dist/workspace/ProjectError.d.ts +8 -0
- package/dist/workspace/ProjectError.js +11 -0
- package/dist/workspace/ProjectError.js.map +1 -0
- package/dist/workspace/ProjectOptions.d.ts +15 -0
- package/dist/workspace/ProjectOptions.js +3 -0
- package/dist/workspace/ProjectOptions.js.map +1 -0
- package/dist/workspace/ProjectUpdateOptions.d.ts +3 -0
- package/dist/workspace/ProjectUpdateOptions.js +3 -0
- package/dist/workspace/ProjectUpdateOptions.js.map +1 -0
- package/dist/workspace/Workspace.d.ts +68 -0
- package/dist/workspace/Workspace.js +426 -0
- package/dist/workspace/Workspace.js.map +1 -0
- package/dist/workspace/WorkspaceConfig.d.ts +9 -0
- package/dist/workspace/WorkspaceConfig.js +6 -0
- package/dist/workspace/WorkspaceConfig.js.map +1 -0
- package/dist/workspace/WorkspaceCreateOptions.d.ts +5 -0
- package/dist/workspace/WorkspaceCreateOptions.js +3 -0
- package/dist/workspace/WorkspaceCreateOptions.js.map +1 -0
- package/dist/workspace/WorkspaceCreateProjectOptions.d.ts +6 -0
- package/dist/workspace/WorkspaceCreateProjectOptions.js +3 -0
- package/dist/workspace/WorkspaceCreateProjectOptions.js.map +1 -0
- package/dist/workspace/WorkspaceDependencies.d.ts +30 -0
- package/dist/workspace/WorkspaceDependencies.js +126 -0
- package/dist/workspace/WorkspaceDependencies.js.map +1 -0
- package/dist/workspace/WorkspaceError.d.ts +8 -0
- package/dist/workspace/WorkspaceError.js +13 -0
- package/dist/workspace/WorkspaceError.js.map +1 -0
- package/dist/workspace/WorkspaceOptions.d.ts +25 -0
- package/dist/workspace/WorkspaceOptions.js +3 -0
- package/dist/workspace/WorkspaceOptions.js.map +1 -0
- package/dist/workspace/WorkspaceOptionsProjectOptions.d.ts +7 -0
- package/dist/workspace/WorkspaceOptionsProjectOptions.js +3 -0
- package/dist/workspace/WorkspaceOptionsProjectOptions.js.map +1 -0
- package/dist/workspace/WorkspacePackageJson.d.ts +2 -0
- package/dist/workspace/WorkspacePackageJson.js +3 -0
- package/dist/workspace/WorkspacePackageJson.js.map +1 -0
- package/dist/workspace/WorkspaceProjectGlobs.d.ts +1 -0
- package/dist/workspace/WorkspaceProjectGlobs.js +3 -0
- package/dist/workspace/WorkspaceProjectGlobs.js.map +1 -0
- package/dist/workspace/WorkspaceProjects.d.ts +2 -0
- package/dist/workspace/WorkspaceProjects.js +3 -0
- package/dist/workspace/WorkspaceProjects.js.map +1 -0
- package/dist/workspace/WorkspaceRepository.d.ts +4 -0
- package/dist/workspace/WorkspaceRepository.js +3 -0
- package/dist/workspace/WorkspaceRepository.js.map +1 -0
- package/dist/workspace/WorkspaceUpdateOptions.d.ts +3 -0
- package/dist/workspace/WorkspaceUpdateOptions.js +3 -0
- package/dist/workspace/WorkspaceUpdateOptions.js.map +1 -0
- package/dist/workspace/internals/compareSemver.d.ts +8 -0
- package/dist/workspace/internals/compareSemver.js +27 -0
- package/dist/workspace/internals/compareSemver.js.map +1 -0
- package/dist/workspace/internals/getPackageJsonWorkspaces.d.ts +2 -0
- package/dist/workspace/internals/getPackageJsonWorkspaces.js +11 -0
- package/dist/workspace/internals/getPackageJsonWorkspaces.js.map +1 -0
- package/dist/workspace/internals/getRepositoryBranches.d.ts +1 -0
- package/dist/workspace/internals/getRepositoryBranches.js +21 -0
- package/dist/workspace/internals/getRepositoryBranches.js.map +1 -0
- package/dist/workspace/internals/getRepositoryUrl.d.ts +1 -0
- package/dist/workspace/internals/getRepositoryUrl.js +21 -0
- package/dist/workspace/internals/getRepositoryUrl.js.map +1 -0
- package/dist/workspace/internals.d.ts +4 -0
- package/dist/workspace/internals.js +6 -0
- package/dist/workspace/internals.js.map +1 -0
- package/dist/workspace/saveProjectConfig.d.ts +6 -0
- package/dist/workspace/saveProjectConfig.js +13 -0
- package/dist/workspace/saveProjectConfig.js.map +1 -0
- package/dist/workspace/saveWorkspaceConfig.d.ts +6 -0
- package/dist/workspace/saveWorkspaceConfig.js +13 -0
- package/dist/workspace/saveWorkspaceConfig.js.map +1 -0
- package/dist/workspace.d.ts +10 -0
- package/dist/workspace.js +12 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +84 -0
- package/src/commands/create-project/CreateProject.tsx +130 -0
- package/src/commands/create-project/CreateProjectInput.ts +37 -0
- package/src/commands/create-project/createProjectCommand.tsx +33 -0
- package/src/commands/create-project/runCreateProject.ts +59 -0
- package/src/commands/create-project.ts +4 -0
- package/src/commands/create-workspace/CreateWorkspace.tsx +90 -0
- package/src/commands/create-workspace/CreateWorkspaceInput.ts +21 -0
- package/src/commands/create-workspace/createWorkspaceCommand.tsx +34 -0
- package/src/commands/create-workspace/runCreateWorkspace.ts +49 -0
- package/src/commands/create-workspace.ts +4 -0
- package/src/commands/internals/packageNameToDirectory.ts +13 -0
- package/src/commands/internals.ts +1 -0
- package/src/commands/update-workspace/UpdateWorkspace.tsx +59 -0
- package/src/commands/update-workspace/runUpdateWorkspace.ts +36 -0
- package/src/commands/update-workspace/updateWorkspaceCommand.tsx +27 -0
- package/src/commands/update-workspace.ts +3 -0
- package/src/commands.ts +3 -0
- package/src/constants.ts +21 -0
- package/src/main.ts +3 -0
- package/src/modules.d.ts +1 -0
- package/src/run.ts +21 -0
- package/src/template/CarsonTemplate.ts +11 -0
- package/src/template/CarsonTemplateConfig.ts +12 -0
- package/src/template/TemplateAttributes.ts +16 -0
- package/src/template/TemplateData.ts +17 -0
- package/src/template/TemplateRender.ts +9 -0
- package/src/template/TemplateRenderSnapshot.ts +13 -0
- package/src/template/TemplateRenderSnapshots.ts +7 -0
- package/src/template/TemplateRenders.ts +3 -0
- package/src/template/applyTemplateRenders.ts +89 -0
- package/src/template/createFileUsingTemplateRender.ts +12 -0
- package/src/template/deleteFileUsingTemplateRender.ts +15 -0
- package/src/template/importCarsonTemplate.ts +13 -0
- package/src/template/insertUsingTemplateRender.ts +33 -0
- package/src/template/internals/merge.ts +44 -0
- package/src/template/internals/prettify.ts +24 -0
- package/src/template/internals/unmerge.ts +48 -0
- package/src/template/internals.ts +3 -0
- package/src/template/loadTemplateRenderSnapshots.ts +18 -0
- package/src/template/mergeFileUsingTemplateRender.ts +39 -0
- package/src/template/overwriteFileUsingTemplateRender.ts +12 -0
- package/src/template/parseTemplateId.ts +9 -0
- package/src/template/readCarsonTemplate.ts +46 -0
- package/src/template/renderTemplate.ts +30 -0
- package/src/template/resolveTemplateModule.ts +9 -0
- package/src/template/saveTemplateRenderSnapshots.ts +34 -0
- package/src/template/uninsertUsingTemplateRender.ts +36 -0
- package/src/template/unmergeFileUsingTemplateRender.ts +42 -0
- package/src/template.ts +20 -0
- package/src/workspace/Project.ts +246 -0
- package/src/workspace/ProjectConfig.ts +9 -0
- package/src/workspace/ProjectCreateOptions.ts +9 -0
- package/src/workspace/ProjectError.ts +15 -0
- package/src/workspace/ProjectOptions.ts +17 -0
- package/src/workspace/ProjectUpdateOptions.ts +3 -0
- package/src/workspace/Workspace.ts +553 -0
- package/src/workspace/WorkspaceConfig.ts +9 -0
- package/src/workspace/WorkspaceCreateOptions.ts +5 -0
- package/src/workspace/WorkspaceCreateProjectOptions.ts +6 -0
- package/src/workspace/WorkspaceDependencies.ts +196 -0
- package/src/workspace/WorkspaceError.ts +18 -0
- package/src/workspace/WorkspaceOptions.ts +29 -0
- package/src/workspace/WorkspaceOptionsProjectOptions.ts +9 -0
- package/src/workspace/WorkspacePackageJson.ts +3 -0
- package/src/workspace/WorkspaceProjectGlobs.ts +1 -0
- package/src/workspace/WorkspaceProjects.ts +3 -0
- package/src/workspace/WorkspaceRepository.ts +4 -0
- package/src/workspace/WorkspaceUpdateOptions.ts +3 -0
- package/src/workspace/internals/compareSemver.ts +35 -0
- package/src/workspace/internals/getPackageJsonWorkspaces.ts +11 -0
- package/src/workspace/internals/getRepositoryBranches.ts +25 -0
- package/src/workspace/internals/getRepositoryUrl.ts +23 -0
- package/src/workspace/internals.ts +4 -0
- package/src/workspace/saveProjectConfig.ts +23 -0
- package/src/workspace/saveWorkspaceConfig.ts +30 -0
- package/src/workspace.ts +10 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {type CommandArguments, Header, icons, colors, useProgram} from '@jakubmazanec/cli';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import {Box, Text} from 'ink';
|
|
4
|
+
import {useEffect, useState} from 'react';
|
|
5
|
+
|
|
6
|
+
import {runUpdateWorkspace} from './runUpdateWorkspace.js';
|
|
7
|
+
import {type updateWorkspaceCommand} from './updateWorkspaceCommand.js';
|
|
8
|
+
import {type Workspace} from '../../workspace.js';
|
|
9
|
+
|
|
10
|
+
export type UpdateWorkspaceProps = {
|
|
11
|
+
args: CommandArguments<typeof updateWorkspaceCommand>;
|
|
12
|
+
workspace: Workspace | Workspace<false>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function UpdateWorkspace({workspace, args}: UpdateWorkspaceProps) {
|
|
16
|
+
let [isFinished, setIsFinished] = useState(false);
|
|
17
|
+
let [jobs, setJobs] = useState<string[]>([]);
|
|
18
|
+
let {exit} = useProgram();
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
let subscription = runUpdateWorkspace({workspace, args}).subscribe({
|
|
22
|
+
next(value) {
|
|
23
|
+
setJobs((previousJobs) => [...previousJobs, value]);
|
|
24
|
+
},
|
|
25
|
+
error(error) {
|
|
26
|
+
exit(error);
|
|
27
|
+
},
|
|
28
|
+
complete() {
|
|
29
|
+
setIsFinished(true);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
subscription.unsubscribe();
|
|
35
|
+
};
|
|
36
|
+
}, [args, exit, workspace]);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Box flexDirection="column">
|
|
40
|
+
<Text>{`Updating workspace at ${chalk[colors.info](workspace.path)}.`}</Text>
|
|
41
|
+
|
|
42
|
+
<Box marginTop={1} flexDirection="column">
|
|
43
|
+
<Header showSpinner={!isFinished} icon={icons.success} marginBottom={1}>
|
|
44
|
+
<Text>Updating workspace...</Text>
|
|
45
|
+
</Header>
|
|
46
|
+
|
|
47
|
+
{jobs.map((job) => (
|
|
48
|
+
<Text key={job}>{`${icons.info} ${job}`}</Text>
|
|
49
|
+
))}
|
|
50
|
+
</Box>
|
|
51
|
+
|
|
52
|
+
{isFinished ? (
|
|
53
|
+
<Header marginTop={1} icon={icons.success}>
|
|
54
|
+
<Text>Done.</Text>
|
|
55
|
+
</Header>
|
|
56
|
+
) : null}
|
|
57
|
+
</Box>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {type CommandArguments} from '@jakubmazanec/cli';
|
|
2
|
+
import Observable from 'zen-observable';
|
|
3
|
+
|
|
4
|
+
import {type updateWorkspaceCommand} from './updateWorkspaceCommand.js';
|
|
5
|
+
import {type Workspace} from '../../workspace.js';
|
|
6
|
+
|
|
7
|
+
export type UpdateWorkspaceAndProjectsOptions = {
|
|
8
|
+
workspace: Workspace | Workspace<false>;
|
|
9
|
+
args: CommandArguments<typeof updateWorkspaceCommand>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type UpdateWorkspaceAndProjectsStatus = string;
|
|
13
|
+
|
|
14
|
+
export function runUpdateWorkspace({workspace, args}: UpdateWorkspaceAndProjectsOptions) {
|
|
15
|
+
return new Observable<UpdateWorkspaceAndProjectsStatus>((observer) => {
|
|
16
|
+
(async () => {
|
|
17
|
+
// update workspace
|
|
18
|
+
observer.next('Updating workspace');
|
|
19
|
+
|
|
20
|
+
await workspace.update({args});
|
|
21
|
+
|
|
22
|
+
// update projects
|
|
23
|
+
for (let project of workspace.projects) {
|
|
24
|
+
observer.next(`Updating project ${project.name ?? '?'}`);
|
|
25
|
+
|
|
26
|
+
await project.update({args});
|
|
27
|
+
}
|
|
28
|
+
})()
|
|
29
|
+
.then(() => {
|
|
30
|
+
observer.complete();
|
|
31
|
+
})
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
observer.error(error);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {Command} from '@jakubmazanec/cli';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {UpdateWorkspace} from './UpdateWorkspace.js';
|
|
5
|
+
import {Workspace} from '../../workspace.js';
|
|
6
|
+
|
|
7
|
+
export const updateWorkspaceCommand = new Command(
|
|
8
|
+
'update workspace',
|
|
9
|
+
async (args, program) => {
|
|
10
|
+
let resolvedPath = path.resolve(process.cwd(), args.options.path ?? '');
|
|
11
|
+
let workspace = await Workspace.findAndRead(resolvedPath);
|
|
12
|
+
|
|
13
|
+
if (!workspace) {
|
|
14
|
+
throw new Error(`No workspace found at "${resolvedPath}"!`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await program.renderElement(<UpdateWorkspace workspace={workspace} args={args} />);
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
description: 'Updates files in a workspace.',
|
|
21
|
+
options: {
|
|
22
|
+
path: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
);
|
package/src/commands.ts
ADDED
package/src/constants.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import url from 'node:url';
|
|
3
|
+
|
|
4
|
+
let directory = path.dirname(url.fileURLToPath(import.meta.url));
|
|
5
|
+
|
|
6
|
+
export const PACKAGE_PATH = path.resolve(directory, '..');
|
|
7
|
+
|
|
8
|
+
// import path from 'node:path';
|
|
9
|
+
// import url from 'node:url';
|
|
10
|
+
|
|
11
|
+
// let directory = path.dirname(url.fileURLToPath(import.meta.url));
|
|
12
|
+
|
|
13
|
+
export const CARSON_CONFIG_DIRECTORY = '.carson';
|
|
14
|
+
export const PROJECT_CONFIG_FILENAME = 'project.json';
|
|
15
|
+
export const WORKSPACE_CONFIG_FILENAME = 'workspace.json';
|
|
16
|
+
export const SNAPSHOTS_FILENAME = '.snapshots';
|
|
17
|
+
|
|
18
|
+
export const TEMPLATES_PATH = 'templates';
|
|
19
|
+
|
|
20
|
+
// config files in carson template package
|
|
21
|
+
export const TEMPLATE_CONFIG_FILENAME = 'config.json';
|
package/src/main.ts
ADDED
package/src/modules.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'prettier-plugin-packagejson';
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {Program, getProgramDetail} from '@jakubmazanec/cli';
|
|
2
|
+
import {readPackageJson} from '@jakubmazanec/zod-utils';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import {createWorkspaceCommand, updateWorkspaceCommand, createProjectCommand} from './commands.js';
|
|
6
|
+
import {PACKAGE_PATH} from './constants.js';
|
|
7
|
+
|
|
8
|
+
let programDetail = getProgramDetail(
|
|
9
|
+
await readPackageJson(path.join(PACKAGE_PATH, 'package.json'), {throwOnZodError: true}),
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
let program = new Program({
|
|
13
|
+
...programDetail,
|
|
14
|
+
name: 'Carson',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
program.addCommand(createWorkspaceCommand);
|
|
18
|
+
program.addCommand(createProjectCommand);
|
|
19
|
+
program.addCommand(updateWorkspaceCommand);
|
|
20
|
+
|
|
21
|
+
await program.run(process.argv.slice(2));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {type Template} from '@jakubmazanec/template';
|
|
2
|
+
|
|
3
|
+
import {type CarsonTemplateConfig} from './CarsonTemplateConfig.js';
|
|
4
|
+
import {type templateAttributesSchema} from './TemplateAttributes.js';
|
|
5
|
+
import {type templateDataSchema} from './TemplateData.js';
|
|
6
|
+
|
|
7
|
+
export type CarsonTemplate = {
|
|
8
|
+
name: string;
|
|
9
|
+
config: CarsonTemplateConfig;
|
|
10
|
+
files: Array<Template<typeof templateAttributesSchema, typeof templateDataSchema>>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {z} from 'zod';
|
|
2
|
+
|
|
3
|
+
export const carsonTemplateConfigSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
disallowMultiProjectWorkspace: z.boolean().optional(),
|
|
6
|
+
disallowSingleProjectWorkspace: z.boolean().optional(),
|
|
7
|
+
|
|
8
|
+
// TODO: add extends property to allow reuisng template files from another carson template
|
|
9
|
+
})
|
|
10
|
+
.strict();
|
|
11
|
+
|
|
12
|
+
export type CarsonTemplateConfig = z.infer<typeof carsonTemplateConfigSchema>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {z} from 'zod';
|
|
2
|
+
|
|
3
|
+
export const templateAttributesSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
// TODO: add strategy 'none' so when you using template A that extends template B, you can overwrite template files to no-op
|
|
6
|
+
strategy: z.union([
|
|
7
|
+
z.literal('create'),
|
|
8
|
+
z.literal('overwrite'),
|
|
9
|
+
z.literal('merge'),
|
|
10
|
+
z.literal('check'),
|
|
11
|
+
z.tuple([z.literal('insert'), z.string()]),
|
|
12
|
+
]),
|
|
13
|
+
})
|
|
14
|
+
.strict();
|
|
15
|
+
|
|
16
|
+
export type TemplateAttributes = z.infer<typeof templateAttributesSchema>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {z} from 'zod';
|
|
2
|
+
|
|
3
|
+
import {carsonTemplateConfigSchema} from './CarsonTemplateConfig.js';
|
|
4
|
+
import {Project} from '../workspace/Project.js';
|
|
5
|
+
import {Workspace} from '../workspace/Workspace.js';
|
|
6
|
+
|
|
7
|
+
// TODO: what about template data for workspace and template data for project, so we can get rid of the `.optional()`?
|
|
8
|
+
export const templateDataSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
workspace: z.instanceof(Workspace).optional(),
|
|
11
|
+
project: z.instanceof(Project).optional(),
|
|
12
|
+
args: z.record(z.unknown()).optional(),
|
|
13
|
+
templateConfig: carsonTemplateConfigSchema.optional(),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
|
|
17
|
+
export type TemplateData = z.infer<typeof templateDataSchema>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import {type TemplateRender as BaseTemplateRender} from '@jakubmazanec/template';
|
|
2
|
+
|
|
3
|
+
import {type templateAttributesSchema} from './TemplateAttributes.js';
|
|
4
|
+
import {type templateDataSchema} from './TemplateData.js';
|
|
5
|
+
|
|
6
|
+
export type TemplateRender = BaseTemplateRender<
|
|
7
|
+
typeof templateAttributesSchema,
|
|
8
|
+
typeof templateDataSchema
|
|
9
|
+
>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {templateAttributesSchema as baseTemplateAttributesSchema} from '@jakubmazanec/template';
|
|
2
|
+
import {z} from 'zod';
|
|
3
|
+
|
|
4
|
+
import {templateAttributesSchema} from './TemplateAttributes.js';
|
|
5
|
+
|
|
6
|
+
export const templateRenderSnapshotSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
attributes: baseTemplateAttributesSchema.pick({to: true}).merge(templateAttributesSchema),
|
|
9
|
+
content: z.string(),
|
|
10
|
+
})
|
|
11
|
+
.strict();
|
|
12
|
+
|
|
13
|
+
export type TemplateRenderSnapshot = z.infer<typeof templateRenderSnapshotSchema>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import {type z} from 'zod';
|
|
2
|
+
|
|
3
|
+
import {templateRenderSnapshotSchema} from './TemplateRenderSnapshot.js';
|
|
4
|
+
|
|
5
|
+
export const templateRenderSnapshotsSchema = templateRenderSnapshotSchema.array();
|
|
6
|
+
|
|
7
|
+
export type TemplateRenderSnapshots = z.infer<typeof templateRenderSnapshotsSchema>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import prettier from 'prettier';
|
|
4
|
+
|
|
5
|
+
import {createFileUsingTemplateRender} from './createFileUsingTemplateRender.js';
|
|
6
|
+
import {deleteFileUsingTemplateRender} from './deleteFileUsingTemplateRender.js';
|
|
7
|
+
import {insertUsingTemplateRender} from './insertUsingTemplateRender.js';
|
|
8
|
+
import {loadTemplateRenderSnapshots} from './loadTemplateRenderSnapshots.js';
|
|
9
|
+
import {mergeFileUsingTemplateRender} from './mergeFileUsingTemplateRender.js';
|
|
10
|
+
import {overwriteFileUsingTemplateRender} from './overwriteFileUsingTemplateRender.js';
|
|
11
|
+
import {saveTemplateRenderSnapshots} from './saveTemplateRenderSnapshots.js';
|
|
12
|
+
import {type TemplateRenders} from './TemplateRenders.js';
|
|
13
|
+
import {uninsertUsingTemplateRender} from './uninsertUsingTemplateRender.js';
|
|
14
|
+
import {unmergeFileUsingTemplateRender} from './unmergeFileUsingTemplateRender.js';
|
|
15
|
+
import {CARSON_CONFIG_DIRECTORY, SNAPSHOTS_FILENAME} from '../constants.js';
|
|
16
|
+
|
|
17
|
+
export type ApplyTemplateRendersOptions = {
|
|
18
|
+
templateRenders: TemplateRenders;
|
|
19
|
+
path: string;
|
|
20
|
+
ignoreCreateStrategies: boolean;
|
|
21
|
+
ignoreCheckStrategies: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export async function applyTemplateRenders({
|
|
25
|
+
templateRenders,
|
|
26
|
+
path: targetPath,
|
|
27
|
+
ignoreCheckStrategies,
|
|
28
|
+
ignoreCreateStrategies,
|
|
29
|
+
}: ApplyTemplateRendersOptions) {
|
|
30
|
+
// we need to clear Prettier cache, because we are changing file system
|
|
31
|
+
prettier.clearConfigCache();
|
|
32
|
+
|
|
33
|
+
let templateRenderSnapshotsPath = path.join(
|
|
34
|
+
targetPath,
|
|
35
|
+
CARSON_CONFIG_DIRECTORY,
|
|
36
|
+
SNAPSHOTS_FILENAME,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (await fs.pathExists(templateRenderSnapshotsPath)) {
|
|
40
|
+
let templateRenderSnapshots = await loadTemplateRenderSnapshots(templateRenderSnapshotsPath);
|
|
41
|
+
|
|
42
|
+
for (let templateRenderSnapshot of templateRenderSnapshots) {
|
|
43
|
+
if (templateRenderSnapshot.attributes.strategy === 'overwrite') {
|
|
44
|
+
await deleteFileUsingTemplateRender(templateRenderSnapshot, targetPath);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (templateRenderSnapshot.attributes.strategy === 'merge') {
|
|
48
|
+
await unmergeFileUsingTemplateRender(templateRenderSnapshot, targetPath);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (templateRenderSnapshot.attributes.strategy[0] === 'insert') {
|
|
52
|
+
await uninsertUsingTemplateRender(templateRenderSnapshot, targetPath);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!ignoreCreateStrategies) {
|
|
58
|
+
for (let templateRender of templateRenders) {
|
|
59
|
+
if (templateRender.attributes.strategy === 'create') {
|
|
60
|
+
await createFileUsingTemplateRender(templateRender, targetPath);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (let templateRender of templateRenders) {
|
|
66
|
+
if (templateRender.attributes.strategy === 'overwrite') {
|
|
67
|
+
await overwriteFileUsingTemplateRender(templateRender, targetPath);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (templateRender.attributes.strategy === 'merge') {
|
|
71
|
+
await mergeFileUsingTemplateRender(templateRender, targetPath);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (templateRender.attributes.strategy[0] === 'insert') {
|
|
75
|
+
await insertUsingTemplateRender(templateRender, targetPath);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!ignoreCheckStrategies && templateRender.attributes.strategy === 'check') {
|
|
79
|
+
let to = path.join(targetPath, templateRender.attributes.to);
|
|
80
|
+
let doesToExist = await fs.pathExists(to);
|
|
81
|
+
|
|
82
|
+
if (!doesToExist) {
|
|
83
|
+
throw new Error(`File "${to}" doesn't exist!`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await saveTemplateRenderSnapshots(templateRenders, templateRenderSnapshotsPath);
|
|
89
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {prettify} from './internals.js';
|
|
5
|
+
import {type TemplateRender} from './TemplateRender.js';
|
|
6
|
+
|
|
7
|
+
export async function createFileUsingTemplateRender(render: TemplateRender, basePath: string) {
|
|
8
|
+
let to = path.join(basePath, render.attributes.to);
|
|
9
|
+
|
|
10
|
+
await fs.ensureDir(path.dirname(to));
|
|
11
|
+
await fs.writeFile(to, await prettify(render.content, to), {encoding: 'utf8'});
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {type TemplateRenderSnapshot} from './TemplateRenderSnapshot.js';
|
|
5
|
+
|
|
6
|
+
export async function deleteFileUsingTemplateRender(
|
|
7
|
+
render: TemplateRenderSnapshot,
|
|
8
|
+
basePath: string,
|
|
9
|
+
) {
|
|
10
|
+
let to = path.join(basePath, render.attributes.to);
|
|
11
|
+
|
|
12
|
+
if (await fs.pathExists(to)) {
|
|
13
|
+
await fs.rm(to);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {parseTemplateId} from './parseTemplateId.js';
|
|
2
|
+
|
|
3
|
+
type Module = {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
default: unknown;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export async function importCarsonTemplate(templateId: string) {
|
|
9
|
+
let [moduleId] = parseTemplateId(templateId);
|
|
10
|
+
let {default: _, ...moduleWithoutDefault} = (await import(moduleId)) as Module;
|
|
11
|
+
|
|
12
|
+
return moduleWithoutDefault;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import {prettify} from './internals.js';
|
|
6
|
+
import {type TemplateRender} from './TemplateRender.js';
|
|
7
|
+
|
|
8
|
+
export async function insertUsingTemplateRender(render: TemplateRender, basePath: string) {
|
|
9
|
+
let to = path.join(basePath, render.attributes.to);
|
|
10
|
+
let extension = path.extname(to);
|
|
11
|
+
|
|
12
|
+
switch (extension) {
|
|
13
|
+
case '.md': {
|
|
14
|
+
let targetFile = await fs.readFile(to, {encoding: 'utf8'});
|
|
15
|
+
let newContent = `<!-- ${render.attributes.strategy[1]} -->${render.content}<!-- ${render.attributes.strategy[1]} -->`;
|
|
16
|
+
let oldContentRegexp = new RegExp(
|
|
17
|
+
`<!--\\s*${_.escapeRegExp(
|
|
18
|
+
render.attributes.strategy[1],
|
|
19
|
+
)}\\s-->[\\s\\S]*<!--\\s*${_.escapeRegExp(render.attributes.strategy[1])}\\s-->`,
|
|
20
|
+
'u',
|
|
21
|
+
);
|
|
22
|
+
let newFile = targetFile.replace(oldContentRegexp, newContent);
|
|
23
|
+
|
|
24
|
+
await fs.writeFile(to, await prettify(newFile, to), {encoding: 'utf8'});
|
|
25
|
+
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
default: {
|
|
30
|
+
throw new Error(`File extension "${extension}" is not supported!`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges two JSON-like variables. Only simple objects, not arrays, are merged recursively.
|
|
3
|
+
*/
|
|
4
|
+
export function merge(a: unknown, b: unknown) {
|
|
5
|
+
if (b === undefined || b == null) {
|
|
6
|
+
return a;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof b !== 'object' || Array.isArray(b)) {
|
|
10
|
+
return a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (a === undefined || a == null) {
|
|
14
|
+
return a;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof a !== 'object' || Array.isArray(a)) {
|
|
18
|
+
return a;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const newA: Record<string, unknown> = {...a};
|
|
22
|
+
|
|
23
|
+
for (let [key, value] of Object.entries(b)) {
|
|
24
|
+
if (
|
|
25
|
+
(a as Record<string, unknown>)[key] &&
|
|
26
|
+
typeof (a as Record<string, unknown>)[key] === 'object' &&
|
|
27
|
+
!Array.isArray((a as Record<string, unknown>)[key]) &&
|
|
28
|
+
(b as Record<string, unknown>)[key] &&
|
|
29
|
+
typeof (b as Record<string, unknown>)[key] === 'object' &&
|
|
30
|
+
!Array.isArray((b as Record<string, unknown>)[key])
|
|
31
|
+
) {
|
|
32
|
+
const result = merge(
|
|
33
|
+
(a as Record<string, unknown>)[key],
|
|
34
|
+
(b as Record<string, unknown>)[key],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
newA[key] = result;
|
|
38
|
+
} else {
|
|
39
|
+
newA[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return newA;
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import prettier from 'prettier';
|
|
2
|
+
import packageJsonPrettierPlugin from 'prettier-plugin-packagejson';
|
|
3
|
+
|
|
4
|
+
const NO_INFERRED_PARSER = /parser.*inferred/i;
|
|
5
|
+
|
|
6
|
+
export async function prettify(content: string, targetPath: string) {
|
|
7
|
+
let prettifiedContent = content;
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
let prettierOptions = await prettier.resolveConfig(targetPath, {editorconfig: true});
|
|
11
|
+
|
|
12
|
+
prettifiedContent = prettier.format(content, {
|
|
13
|
+
...prettierOptions,
|
|
14
|
+
filepath: targetPath,
|
|
15
|
+
plugins: [packageJsonPrettierPlugin],
|
|
16
|
+
});
|
|
17
|
+
} catch (error: unknown) {
|
|
18
|
+
if (!NO_INFERRED_PARSER.test((error as Error).message)) {
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return prettifiedContent;
|
|
24
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reverts {@linkcode merge}.
|
|
3
|
+
*/
|
|
4
|
+
export function unmerge(a: unknown, b: unknown) {
|
|
5
|
+
if (b === undefined || b == null) {
|
|
6
|
+
return a;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (typeof b !== 'object' || Array.isArray(b)) {
|
|
10
|
+
return a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (a === undefined || a == null) {
|
|
14
|
+
return a;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof a !== 'object' || Array.isArray(a)) {
|
|
18
|
+
return a;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const newA: Record<string, unknown> = {};
|
|
22
|
+
|
|
23
|
+
for (let [key] of Object.entries(a)) {
|
|
24
|
+
if (!Object.hasOwn(b, key)) {
|
|
25
|
+
newA[key] = (a as Record<string, unknown>)[key];
|
|
26
|
+
|
|
27
|
+
continue;
|
|
28
|
+
} else if (
|
|
29
|
+
(a as Record<string, unknown>)[key] &&
|
|
30
|
+
typeof (a as Record<string, unknown>)[key] === 'object' &&
|
|
31
|
+
!Array.isArray((a as Record<string, unknown>)[key]) &&
|
|
32
|
+
(b as Record<string, unknown>)[key] &&
|
|
33
|
+
typeof (b as Record<string, unknown>)[key] === 'object' &&
|
|
34
|
+
!Array.isArray((b as Record<string, unknown>)[key])
|
|
35
|
+
) {
|
|
36
|
+
const result = unmerge(
|
|
37
|
+
(a as Record<string, unknown>)[key],
|
|
38
|
+
(b as Record<string, unknown>)[key],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (Object.keys(result as Record<string, unknown>).length > 0) {
|
|
42
|
+
newA[key] = result;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return newA;
|
|
48
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {inflateSync, strFromU8} from 'fflate';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
|
|
4
|
+
import {templateRenderSnapshotsSchema} from './TemplateRenderSnapshots.js';
|
|
5
|
+
|
|
6
|
+
export async function loadTemplateRenderSnapshots(templateRenderSnapshotsPath: string) {
|
|
7
|
+
let compressedSnapshots = await fs.readFile(templateRenderSnapshotsPath);
|
|
8
|
+
let decompressedSnapshots = inflateSync(new Uint8Array(compressedSnapshots));
|
|
9
|
+
let parsingResult = templateRenderSnapshotsSchema.safeParse(
|
|
10
|
+
JSON.parse(strFromU8(decompressedSnapshots)),
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
if (!parsingResult.success) {
|
|
14
|
+
throw parsingResult.error;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return parsingResult.data;
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {type Json} from '@jakubmazanec/zod-utils';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import json from 'json5';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import yaml from 'yaml';
|
|
6
|
+
|
|
7
|
+
import {merge, prettify} from './internals.js';
|
|
8
|
+
import {type TemplateRender} from './TemplateRender.js';
|
|
9
|
+
|
|
10
|
+
export async function mergeFileUsingTemplateRender(render: TemplateRender, basePath: string) {
|
|
11
|
+
let to = path.join(basePath, render.attributes.to);
|
|
12
|
+
let extension = path.extname(to);
|
|
13
|
+
|
|
14
|
+
switch (extension) {
|
|
15
|
+
case '.json': {
|
|
16
|
+
let targetFile = (await fs.readJson(to)) as Json;
|
|
17
|
+
let fileToMerge = json.parse<Json>(render.content);
|
|
18
|
+
let newFile = JSON.stringify(merge(targetFile, fileToMerge));
|
|
19
|
+
|
|
20
|
+
await fs.writeFile(to, await prettify(newFile, to), {encoding: 'utf8'});
|
|
21
|
+
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
case '.yaml': {
|
|
26
|
+
let targetFile = yaml.parse(await fs.readFile(to, {encoding: 'utf8'})) as unknown;
|
|
27
|
+
let fileToMerge = yaml.parse(render.content) as unknown;
|
|
28
|
+
let newFile = yaml.stringify(merge(targetFile, fileToMerge));
|
|
29
|
+
|
|
30
|
+
await fs.writeFile(to, await prettify(newFile, to), {encoding: 'utf8'});
|
|
31
|
+
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
default: {
|
|
36
|
+
throw new Error(`File extension "${extension}" is not supported!`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {prettify} from './internals.js';
|
|
5
|
+
import {type TemplateRender} from './TemplateRender.js';
|
|
6
|
+
|
|
7
|
+
export async function overwriteFileUsingTemplateRender(render: TemplateRender, basePath: string) {
|
|
8
|
+
let to = path.join(basePath, render.attributes.to);
|
|
9
|
+
|
|
10
|
+
await fs.ensureDir(path.dirname(to));
|
|
11
|
+
await fs.writeFile(to, await prettify(render.content, to), {encoding: 'utf8'});
|
|
12
|
+
}
|