@jakubmazanec/carson 0.1.0-a500263
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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workspace/internals.ts"],"sourcesContent":["export * from './internals/compareSemver.js';\nexport * from './internals/getPackageJsonWorkspaces.js';\nexport * from './internals/getRepositoryBranches.js';\nexport * from './internals/getRepositoryUrl.js';\n"],"names":[],"mappings":"AAAA,cAAc,+BAA+B;AAC7C,cAAc,0CAA0C;AACxD,cAAc,uCAAuC;AACrD,cAAc,kCAAkC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ProjectConfig } from './ProjectConfig.js';
|
|
2
|
+
export type SaveProjectConfigOptions = {
|
|
3
|
+
projectPath: string;
|
|
4
|
+
projectConfig: ProjectConfig;
|
|
5
|
+
};
|
|
6
|
+
export declare function saveProjectConfig({ projectPath, projectConfig }: SaveProjectConfigOptions): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME } from '../constants.js';
|
|
4
|
+
import { prettify } from '../template/internals.js';
|
|
5
|
+
export async function saveProjectConfig({ projectPath , projectConfig }) {
|
|
6
|
+
await fs.ensureDir(path.join(projectPath, CARSON_CONFIG_DIRECTORY));
|
|
7
|
+
let projectConfigPath = path.join(projectPath, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME);
|
|
8
|
+
await fs.writeFile(projectConfigPath, await prettify(JSON.stringify(projectConfig), projectConfigPath), {
|
|
9
|
+
encoding: 'utf8'
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=saveProjectConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workspace/saveProjectConfig.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport path from 'node:path';\n\nimport {type ProjectConfig} from './ProjectConfig.js';\nimport {CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME} from '../constants.js';\nimport {prettify} from '../template/internals.js';\n\nexport type SaveProjectConfigOptions = {\n projectPath: string;\n projectConfig: ProjectConfig;\n};\n\nexport async function saveProjectConfig({projectPath, projectConfig}: SaveProjectConfigOptions) {\n await fs.ensureDir(path.join(projectPath, CARSON_CONFIG_DIRECTORY));\n\n let projectConfigPath = path.join(projectPath, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME);\n\n await fs.writeFile(\n projectConfigPath,\n await prettify(JSON.stringify(projectConfig), projectConfigPath),\n {encoding: 'utf8'},\n );\n}\n"],"names":["fs","path","CARSON_CONFIG_DIRECTORY","PROJECT_CONFIG_FILENAME","prettify","saveProjectConfig","projectPath","projectConfig","ensureDir","join","projectConfigPath","writeFile","JSON","stringify","encoding"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAC1B,OAAOC,UAAU,YAAY;AAG7B,SAAQC,uBAAuB,EAAEC,uBAAuB,QAAO,kBAAkB;AACjF,SAAQC,QAAQ,QAAO,2BAA2B;AAOlD,OAAO,eAAeC,kBAAkB,EAACC,YAAW,EAAEC,cAAa,EAA2B;IAC5F,MAAMP,GAAGQ,UAAUP,KAAKQ,KAAKH,aAAaJ;IAE1C,IAAIQ,oBAAoBT,KAAKQ,KAAKH,aAAaJ,yBAAyBC;IAExE,MAAMH,GAAGW,UACPD,mBACA,MAAMN,SAASQ,KAAKC,UAAUN,gBAAgBG,oBAC9C;QAACI,UAAU;IAAM;AAErB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type WorkspaceConfig } from './WorkspaceConfig.js';
|
|
2
|
+
export type SaveWorkspaceConfigOptions = {
|
|
3
|
+
workspacePath: string;
|
|
4
|
+
workspaceConfig: WorkspaceConfig;
|
|
5
|
+
};
|
|
6
|
+
export declare function saveWorkspaceConfig({ workspacePath, workspaceConfig, }: SaveWorkspaceConfigOptions): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { CARSON_CONFIG_DIRECTORY, WORKSPACE_CONFIG_FILENAME } from '../constants.js';
|
|
4
|
+
import { prettify } from '../template/internals.js';
|
|
5
|
+
export async function saveWorkspaceConfig({ workspacePath , workspaceConfig }) {
|
|
6
|
+
await fs.ensureDir(path.join(workspacePath, CARSON_CONFIG_DIRECTORY));
|
|
7
|
+
let workspaceConfigPath = path.join(workspacePath, CARSON_CONFIG_DIRECTORY, WORKSPACE_CONFIG_FILENAME);
|
|
8
|
+
await fs.writeFile(workspaceConfigPath, await prettify(JSON.stringify(workspaceConfig), workspaceConfigPath), {
|
|
9
|
+
encoding: 'utf8'
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=saveWorkspaceConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workspace/saveWorkspaceConfig.ts"],"sourcesContent":["import fs from 'fs-extra';\nimport path from 'node:path';\n\nimport {type WorkspaceConfig} from './WorkspaceConfig.js';\nimport {CARSON_CONFIG_DIRECTORY, WORKSPACE_CONFIG_FILENAME} from '../constants.js';\nimport {prettify} from '../template/internals.js';\n\nexport type SaveWorkspaceConfigOptions = {\n workspacePath: string;\n workspaceConfig: WorkspaceConfig;\n};\n\nexport async function saveWorkspaceConfig({\n workspacePath,\n workspaceConfig,\n}: SaveWorkspaceConfigOptions) {\n await fs.ensureDir(path.join(workspacePath, CARSON_CONFIG_DIRECTORY));\n\n let workspaceConfigPath = path.join(\n workspacePath,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n\n await fs.writeFile(\n workspaceConfigPath,\n await prettify(JSON.stringify(workspaceConfig), workspaceConfigPath),\n {encoding: 'utf8'},\n );\n}\n"],"names":["fs","path","CARSON_CONFIG_DIRECTORY","WORKSPACE_CONFIG_FILENAME","prettify","saveWorkspaceConfig","workspacePath","workspaceConfig","ensureDir","join","workspaceConfigPath","writeFile","JSON","stringify","encoding"],"mappings":"AAAA,OAAOA,QAAQ,WAAW;AAC1B,OAAOC,UAAU,YAAY;AAG7B,SAAQC,uBAAuB,EAAEC,yBAAyB,QAAO,kBAAkB;AACnF,SAAQC,QAAQ,QAAO,2BAA2B;AAOlD,OAAO,eAAeC,oBAAoB,EACxCC,cAAa,EACbC,gBAAe,EACY;IAC3B,MAAMP,GAAGQ,UAAUP,KAAKQ,KAAKH,eAAeJ;IAE5C,IAAIQ,sBAAsBT,KAAKQ,KAC7BH,eACAJ,yBACAC;IAGF,MAAMH,GAAGW,UACPD,qBACA,MAAMN,SAASQ,KAAKC,UAAUN,kBAAkBG,sBAChD;QAACI,UAAU;IAAM;AAErB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './workspace/Project.js';
|
|
2
|
+
export * from './workspace/ProjectConfig.js';
|
|
3
|
+
export * from './workspace/ProjectError.js';
|
|
4
|
+
export * from './workspace/saveProjectConfig.js';
|
|
5
|
+
export * from './workspace/saveWorkspaceConfig.js';
|
|
6
|
+
export * from './workspace/Workspace.js';
|
|
7
|
+
export * from './workspace/WorkspaceConfig.js';
|
|
8
|
+
export * from './workspace/WorkspaceDependencies.js';
|
|
9
|
+
export * from './workspace/WorkspaceError.js';
|
|
10
|
+
export * from './workspace/WorkspaceRepository.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './workspace/Project.js';
|
|
2
|
+
export * from './workspace/ProjectConfig.js';
|
|
3
|
+
export * from './workspace/ProjectError.js';
|
|
4
|
+
export * from './workspace/saveProjectConfig.js';
|
|
5
|
+
export * from './workspace/saveWorkspaceConfig.js';
|
|
6
|
+
export * from './workspace/Workspace.js';
|
|
7
|
+
export * from './workspace/WorkspaceConfig.js';
|
|
8
|
+
export * from './workspace/WorkspaceDependencies.js';
|
|
9
|
+
export * from './workspace/WorkspaceError.js';
|
|
10
|
+
export * from './workspace/WorkspaceRepository.js';
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=workspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/workspace.ts"],"sourcesContent":["export * from './workspace/Project.js';\nexport * from './workspace/ProjectConfig.js';\nexport * from './workspace/ProjectError.js';\nexport * from './workspace/saveProjectConfig.js';\nexport * from './workspace/saveWorkspaceConfig.js';\nexport * from './workspace/Workspace.js';\nexport * from './workspace/WorkspaceConfig.js';\nexport * from './workspace/WorkspaceDependencies.js';\nexport * from './workspace/WorkspaceError.js';\nexport * from './workspace/WorkspaceRepository.js';\n"],"names":[],"mappings":"AAAA,cAAc,yBAAyB;AACvC,cAAc,+BAA+B;AAC7C,cAAc,8BAA8B;AAC5C,cAAc,mCAAmC;AACjD,cAAc,qCAAqC;AACnD,cAAc,2BAA2B;AACzC,cAAc,iCAAiC;AAC/C,cAAc,uCAAuC;AACrD,cAAc,gCAAgC;AAC9C,cAAc,qCAAqC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jakubmazanec/carson",
|
|
3
|
+
"version": "0.1.0-a500263",
|
|
4
|
+
"description": "Tool for managing workspace and project configuration.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jakubmazanec/js-tools",
|
|
8
|
+
"directory": "packages/carson"
|
|
9
|
+
},
|
|
10
|
+
"license": "AGPL-3.0-only",
|
|
11
|
+
"author": "Jakub Mazanec <jakub@mazanec.dev>",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": "./dist/main.js",
|
|
15
|
+
"bin": {
|
|
16
|
+
"carson": "bin/carson.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"src"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "swc src -d dist && tsc",
|
|
24
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
25
|
+
"develop": "swc src -d dist --watch",
|
|
26
|
+
"document": "typedoc --options typedoc.config.cjs",
|
|
27
|
+
"format": "prettier . --write --ignore-unknown --ignore-path ../../.prettierignore",
|
|
28
|
+
"lint": "eslint .",
|
|
29
|
+
"start": "node --loader ts-node/esm/transpile-only --inspect src/run.ts",
|
|
30
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
|
|
31
|
+
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@jakubmazanec/args": "1.0.1-a500263",
|
|
35
|
+
"@jakubmazanec/cli": "0.1.0-a500263",
|
|
36
|
+
"@jakubmazanec/error": "2.0.1-a500263",
|
|
37
|
+
"@jakubmazanec/fs-utils": "0.1.0-a500263",
|
|
38
|
+
"@jakubmazanec/template": "1.0.1-a500263",
|
|
39
|
+
"@jakubmazanec/ts-utils": "2.1.0-a500263",
|
|
40
|
+
"@jakubmazanec/zod-utils": "1.0.0-a500263",
|
|
41
|
+
"chalk": "^5.2.0",
|
|
42
|
+
"diff": "^5.1.0",
|
|
43
|
+
"fast-glob": "^3.2.11",
|
|
44
|
+
"fflate": "^0.7.4",
|
|
45
|
+
"fs-extra": "^10.0.1",
|
|
46
|
+
"json5": "^2.2.1",
|
|
47
|
+
"lodash": "^4.17.21",
|
|
48
|
+
"micromatch": "^4.0.5",
|
|
49
|
+
"prettier": "^2.8.5",
|
|
50
|
+
"prettier-plugin-packagejson": "^2.4.3",
|
|
51
|
+
"semver": "^7.3.6",
|
|
52
|
+
"simple-git": "^3.15.1",
|
|
53
|
+
"yaml": "^2.1.3",
|
|
54
|
+
"zen-observable": "^0.10.0",
|
|
55
|
+
"zod": "^3.14.4"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@jest/globals": "^29.5.0",
|
|
59
|
+
"@types/diff": "^5.0.2",
|
|
60
|
+
"@types/fs-extra": "^9.0.13",
|
|
61
|
+
"@types/lodash": "^4.14.195",
|
|
62
|
+
"@types/micromatch": "^4.0.2",
|
|
63
|
+
"@types/node": "^16.18.3",
|
|
64
|
+
"@types/react": "^18.0.26",
|
|
65
|
+
"@types/semver": "^7.3.9",
|
|
66
|
+
"@types/zen-observable": "^0.8.3",
|
|
67
|
+
"ink": "^3.2.0",
|
|
68
|
+
"react": "^18.2.0"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@types/react": "17.x || 18.x",
|
|
72
|
+
"ink": "^3.0.0",
|
|
73
|
+
"react": "17.x || 18.x"
|
|
74
|
+
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"@types/react": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"packageManager": "npm@8.19.4",
|
|
81
|
+
"engines": {
|
|
82
|
+
"node": ">=16.20.0"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {Header, icons, colors, type CommandArguments, useProgram} from '@jakubmazanec/cli';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import {Box, Text} from 'ink';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {useEffect, useState} from 'react';
|
|
6
|
+
|
|
7
|
+
import {type createProjectCommand} from './createProjectCommand.js';
|
|
8
|
+
import {CreateProjectInput, type CreateProjectInputResult} from './CreateProjectInput.js';
|
|
9
|
+
import {runCreateProject} from './runCreateProject.js';
|
|
10
|
+
import {type Workspace} from '../../workspace.js';
|
|
11
|
+
import {packageNameToDirectory} from '../internals.js';
|
|
12
|
+
|
|
13
|
+
const ONLY_ONE_STAR_REGEXP = /^(?!(.*?\*){2,}|.*? |\*$).*?\*.*$/;
|
|
14
|
+
|
|
15
|
+
export type CreateProjectProps = {
|
|
16
|
+
args: CommandArguments<typeof createProjectCommand>;
|
|
17
|
+
workspace: Workspace | Workspace<false>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function CreateProject({args, workspace}: CreateProjectProps) {
|
|
21
|
+
let [status, setStatus] = useState<'finished' | 'in-progress' | 'not-started'>('not-started');
|
|
22
|
+
let [subscription, setSubscription] = useState<ZenObservable.Subscription | null>(null);
|
|
23
|
+
let [jobs, setJobs] = useState<string[]>([]);
|
|
24
|
+
let [createProjectInputResult, setCreateProjectInputResult] = useState<CreateProjectInputResult>(
|
|
25
|
+
() => ({
|
|
26
|
+
projectName: {value: args.options.name ?? '', isComplete: !!args.options.name},
|
|
27
|
+
projectPath: {value: '', isComplete: false},
|
|
28
|
+
templateId: {value: args.options.template ?? '', isComplete: !!args.options.template},
|
|
29
|
+
}),
|
|
30
|
+
);
|
|
31
|
+
let {exit} = useProgram();
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (Object.entries(createProjectInputResult).every(([, result]) => result.isComplete)) {
|
|
35
|
+
setStatus('in-progress');
|
|
36
|
+
}
|
|
37
|
+
}, [createProjectInputResult]);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (status === 'in-progress' && !subscription) {
|
|
41
|
+
let newSubscription = runCreateProject({
|
|
42
|
+
projectPath: createProjectInputResult.projectPath.value,
|
|
43
|
+
templateId: createProjectInputResult.templateId.value,
|
|
44
|
+
projectName: createProjectInputResult.projectName.value,
|
|
45
|
+
workspace,
|
|
46
|
+
args,
|
|
47
|
+
}).subscribe({
|
|
48
|
+
next(value) {
|
|
49
|
+
setJobs((previousJobs) => [...previousJobs, value]);
|
|
50
|
+
},
|
|
51
|
+
error(error) {
|
|
52
|
+
exit(error);
|
|
53
|
+
},
|
|
54
|
+
complete() {
|
|
55
|
+
newSubscription.unsubscribe();
|
|
56
|
+
setStatus('finished');
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
setSubscription(newSubscription);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return () => {
|
|
63
|
+
if (subscription) {
|
|
64
|
+
subscription.unsubscribe();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}, [args, createProjectInputResult, exit, status, subscription, workspace]);
|
|
68
|
+
|
|
69
|
+
let possiblePaths: Array<{value: string; label: string}> = [];
|
|
70
|
+
|
|
71
|
+
if (createProjectInputResult.projectName.value) {
|
|
72
|
+
let destinationDirectory = packageNameToDirectory(createProjectInputResult.projectName.value);
|
|
73
|
+
|
|
74
|
+
if (workspace.projectGlobs) {
|
|
75
|
+
possiblePaths = workspace.projectGlobs
|
|
76
|
+
.filter((projectGlob) => ONLY_ONE_STAR_REGEXP.test(projectGlob))
|
|
77
|
+
.map((projectGlob) => projectGlob.replace(/\*/, destinationDirectory))
|
|
78
|
+
.map((projectGlob) => path.join(workspace.path, projectGlob))
|
|
79
|
+
.map((projectPath) => ({
|
|
80
|
+
value: projectPath,
|
|
81
|
+
label: path.relative(workspace.path, projectPath).replace('\\', '/'),
|
|
82
|
+
}));
|
|
83
|
+
} else {
|
|
84
|
+
possiblePaths = [
|
|
85
|
+
{
|
|
86
|
+
value: workspace.path,
|
|
87
|
+
label: workspace.path,
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Box flexDirection="column">
|
|
95
|
+
<Text color={colors.body}>
|
|
96
|
+
{`Creating project in the workspace at ${chalk[colors.info](workspace.path)}.`}
|
|
97
|
+
</Text>
|
|
98
|
+
|
|
99
|
+
<CreateProjectInput
|
|
100
|
+
rows={{
|
|
101
|
+
projectPath: {
|
|
102
|
+
choices: possiblePaths,
|
|
103
|
+
},
|
|
104
|
+
}}
|
|
105
|
+
values={createProjectInputResult}
|
|
106
|
+
marginTop={1}
|
|
107
|
+
onChange={setCreateProjectInputResult}
|
|
108
|
+
onComplete={setCreateProjectInputResult}
|
|
109
|
+
/>
|
|
110
|
+
|
|
111
|
+
{status === 'in-progress' || status === 'finished' ? (
|
|
112
|
+
<Box marginTop={1} flexDirection="column">
|
|
113
|
+
<Header showSpinner={status === 'in-progress'} icon={icons.success} marginBottom={1}>
|
|
114
|
+
<Text>Creating project...</Text>
|
|
115
|
+
</Header>
|
|
116
|
+
|
|
117
|
+
{jobs.map((job) => (
|
|
118
|
+
<Text key={job}>{`${icons.info} ${job}`}</Text>
|
|
119
|
+
))}
|
|
120
|
+
</Box>
|
|
121
|
+
) : null}
|
|
122
|
+
|
|
123
|
+
{status === 'finished' ? (
|
|
124
|
+
<Header marginTop={1} icon={icons.success}>
|
|
125
|
+
<Text>Done.</Text>
|
|
126
|
+
</Header>
|
|
127
|
+
) : null}
|
|
128
|
+
</Box>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {type FormResult, createForm} from '@jakubmazanec/cli';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE_ID_REGEXP = /^.+:.+$/;
|
|
4
|
+
const PROJECT_NAME_ID_REGEXP = /^[\d./@a-z-]+$/;
|
|
5
|
+
|
|
6
|
+
export const CreateProjectInput = createForm({
|
|
7
|
+
rows: {
|
|
8
|
+
templateId: {
|
|
9
|
+
type: 'text',
|
|
10
|
+
label: 'What template do you want to use?',
|
|
11
|
+
validate: (value: string) => {
|
|
12
|
+
if (!TEMPLATE_ID_REGEXP.test(value)) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
'Template ID must consist of a module ID and a template name separated by a colon.',
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
projectName: {
|
|
20
|
+
type: 'text',
|
|
21
|
+
label: 'What is the project name?',
|
|
22
|
+
validate: (value: string) => {
|
|
23
|
+
if (!PROJECT_NAME_ID_REGEXP.test(value)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
'Project name can containg only lowercase letters, numbers, hyphen, @, dot or /.',
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
projectPath: {
|
|
31
|
+
type: 'select',
|
|
32
|
+
label: 'What is the project location?',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type CreateProjectInputResult = FormResult<typeof CreateProjectInput>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {Command} from '@jakubmazanec/cli';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import {CreateProject} from './CreateProject.js';
|
|
5
|
+
import {Workspace} from '../../workspace.js';
|
|
6
|
+
|
|
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);
|
|
12
|
+
|
|
13
|
+
if (!workspace) {
|
|
14
|
+
throw new Error(`No workspace found at "${targetPath}"!`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await program.renderElement(<CreateProject args={args} workspace={workspace} />);
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
description: 'Creates a new project in an existing workspace.',
|
|
21
|
+
options: {
|
|
22
|
+
path: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
},
|
|
25
|
+
template: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
},
|
|
28
|
+
name: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {type CommandArguments} from '@jakubmazanec/cli';
|
|
2
|
+
import {isEmptyDirectory} from '@jakubmazanec/fs-utils';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import Observable from 'zen-observable';
|
|
6
|
+
|
|
7
|
+
import {type createProjectCommand} from './createProjectCommand.js';
|
|
8
|
+
import {type Workspace} from '../../workspace.js';
|
|
9
|
+
|
|
10
|
+
export type CreateProjectOptions = {
|
|
11
|
+
projectPath: string;
|
|
12
|
+
projectName: string;
|
|
13
|
+
templateId: string;
|
|
14
|
+
workspace: Workspace | Workspace<false>;
|
|
15
|
+
args: CommandArguments<typeof createProjectCommand>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type CreateProjectStatus = string;
|
|
19
|
+
|
|
20
|
+
export function runCreateProject({
|
|
21
|
+
projectPath,
|
|
22
|
+
templateId,
|
|
23
|
+
projectName,
|
|
24
|
+
workspace,
|
|
25
|
+
args,
|
|
26
|
+
}: CreateProjectOptions) {
|
|
27
|
+
return new Observable<CreateProjectStatus>((observer) => {
|
|
28
|
+
(async () => {
|
|
29
|
+
observer.next('TODO');
|
|
30
|
+
|
|
31
|
+
let resolvedProjectPath = path.resolve(projectPath);
|
|
32
|
+
|
|
33
|
+
// check if path is ok
|
|
34
|
+
await fs.ensureDir(resolvedProjectPath);
|
|
35
|
+
|
|
36
|
+
let isProjectPathEmpty = await isEmptyDirectory(resolvedProjectPath);
|
|
37
|
+
|
|
38
|
+
if (!isProjectPathEmpty) {
|
|
39
|
+
throw new Error(`Directory "${resolvedProjectPath}" must be empty`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// create new project
|
|
43
|
+
let project = await workspace.createProject({
|
|
44
|
+
projectPath: resolvedProjectPath,
|
|
45
|
+
projectName,
|
|
46
|
+
templateId,
|
|
47
|
+
args,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await project.update({args});
|
|
51
|
+
})()
|
|
52
|
+
.then(() => {
|
|
53
|
+
observer.complete();
|
|
54
|
+
})
|
|
55
|
+
.catch((error) => {
|
|
56
|
+
observer.error(error);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {Header, icons, colors, type CommandArguments, useProgram} from '@jakubmazanec/cli';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import {Box, Text} from 'ink';
|
|
4
|
+
import {useEffect, useState} from 'react';
|
|
5
|
+
|
|
6
|
+
import {type createWorkspaceCommand} from './createWorkspaceCommand.js';
|
|
7
|
+
import {CreateWorkspaceInput, type CreateWorkspaceInputResult} from './CreateWorkspaceInput.js';
|
|
8
|
+
import {runCreateWorkspace} from './runCreateWorkspace.js';
|
|
9
|
+
|
|
10
|
+
export type CreateWorkspaceProps = {
|
|
11
|
+
args: CommandArguments<typeof createWorkspaceCommand>;
|
|
12
|
+
path: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function CreateWorkspace({args, path}: CreateWorkspaceProps) {
|
|
16
|
+
let [status, setStatus] = useState<'finished' | 'in-progress' | 'not-started'>('not-started');
|
|
17
|
+
let [subscription, setSubscription] = useState<ZenObservable.Subscription | null>(null);
|
|
18
|
+
let [jobs, setJobs] = useState<string[]>([]);
|
|
19
|
+
let [createWorkspaceInputResult, setCreateWorkspaceInputResult] =
|
|
20
|
+
useState<CreateWorkspaceInputResult>(() => ({
|
|
21
|
+
templateId: {value: args.options.template ?? '', isComplete: !!args.options.template},
|
|
22
|
+
}));
|
|
23
|
+
let {exit} = useProgram();
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (Object.entries(createWorkspaceInputResult).every(([, result]) => result.isComplete)) {
|
|
27
|
+
setStatus('in-progress');
|
|
28
|
+
}
|
|
29
|
+
}, [createWorkspaceInputResult]);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (status === 'in-progress' && !subscription) {
|
|
33
|
+
let newSubscription = runCreateWorkspace({
|
|
34
|
+
workspacePath: path,
|
|
35
|
+
templateId: createWorkspaceInputResult.templateId.value,
|
|
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
|
+
|
|
50
|
+
setSubscription(newSubscription);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
if (subscription) {
|
|
55
|
+
subscription.unsubscribe();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}, [createWorkspaceInputResult, path, status, subscription, args, exit]);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Box flexDirection="column">
|
|
62
|
+
<Text>{`Creating workspace at ${chalk[colors.highlighted](path)}.`}</Text>
|
|
63
|
+
|
|
64
|
+
<CreateWorkspaceInput
|
|
65
|
+
values={createWorkspaceInputResult}
|
|
66
|
+
marginTop={1}
|
|
67
|
+
onChange={setCreateWorkspaceInputResult}
|
|
68
|
+
onComplete={setCreateWorkspaceInputResult}
|
|
69
|
+
/>
|
|
70
|
+
|
|
71
|
+
{status === 'in-progress' || status === 'finished' ? (
|
|
72
|
+
<Box marginTop={1} flexDirection="column">
|
|
73
|
+
<Header showSpinner={status === 'in-progress'} icon={icons.success} marginBottom={1}>
|
|
74
|
+
<Text>Creating workspace...</Text>
|
|
75
|
+
</Header>
|
|
76
|
+
|
|
77
|
+
{jobs.map((job) => (
|
|
78
|
+
<Text key={job}>{`${icons.info} ${job}`}</Text>
|
|
79
|
+
))}
|
|
80
|
+
</Box>
|
|
81
|
+
) : null}
|
|
82
|
+
|
|
83
|
+
{status === 'finished' ? (
|
|
84
|
+
<Header marginTop={1} icon={icons.success}>
|
|
85
|
+
<Text>Done.</Text>
|
|
86
|
+
</Header>
|
|
87
|
+
) : null}
|
|
88
|
+
</Box>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {type FormResult, createForm} from '@jakubmazanec/cli';
|
|
2
|
+
|
|
3
|
+
const TEMPLATE_ID_REGEXP = /^.+:.+$/;
|
|
4
|
+
|
|
5
|
+
export const CreateWorkspaceInput = createForm({
|
|
6
|
+
rows: {
|
|
7
|
+
templateId: {
|
|
8
|
+
type: 'text',
|
|
9
|
+
label: 'Enter template ID:',
|
|
10
|
+
validate: (value: string) => {
|
|
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
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export type CreateWorkspaceInputResult = FormResult<typeof CreateWorkspaceInput>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {Command} from '@jakubmazanec/cli';
|
|
2
|
+
import {isEmptyDirectory} from '@jakubmazanec/fs-utils';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
import {CreateWorkspace} from './CreateWorkspace.js';
|
|
7
|
+
|
|
8
|
+
export const createWorkspaceCommand = new Command(
|
|
9
|
+
'create workspace',
|
|
10
|
+
async (args, program) => {
|
|
11
|
+
let workspacePath = path.resolve(process.cwd(), args.options.path ?? '');
|
|
12
|
+
|
|
13
|
+
await fs.ensureDir(workspacePath);
|
|
14
|
+
|
|
15
|
+
let isWorkspacePathEmpty = await isEmptyDirectory(workspacePath);
|
|
16
|
+
|
|
17
|
+
if (!isWorkspacePathEmpty) {
|
|
18
|
+
throw new Error(`Directory "${workspacePath}" must be empty`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await program.renderElement(<CreateWorkspace args={args} path={workspacePath} />);
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
description: 'Creates a new workspacee.',
|
|
25
|
+
options: {
|
|
26
|
+
path: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
},
|
|
29
|
+
template: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {type CommandArguments} from '@jakubmazanec/cli';
|
|
2
|
+
import {isEmptyDirectory} from '@jakubmazanec/fs-utils';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import Observable from 'zen-observable';
|
|
6
|
+
|
|
7
|
+
import {type createWorkspaceCommand} from './createWorkspaceCommand.js';
|
|
8
|
+
import {Workspace} from '../../workspace.js';
|
|
9
|
+
|
|
10
|
+
export type CreateWorkspaceOptions = {
|
|
11
|
+
workspacePath: string;
|
|
12
|
+
templateId: string;
|
|
13
|
+
args: CommandArguments<typeof createWorkspaceCommand>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type CreateWorkspaceStatus = string;
|
|
17
|
+
|
|
18
|
+
export function runCreateWorkspace({workspacePath, templateId, args}: CreateWorkspaceOptions) {
|
|
19
|
+
return new Observable<CreateWorkspaceStatus>((observer) => {
|
|
20
|
+
(async () => {
|
|
21
|
+
observer.next('TODO');
|
|
22
|
+
|
|
23
|
+
let resolvedWorkspacePath = path.resolve(workspacePath);
|
|
24
|
+
|
|
25
|
+
await fs.ensureDir(resolvedWorkspacePath);
|
|
26
|
+
|
|
27
|
+
let isWorkspacePathEmpty = await isEmptyDirectory(resolvedWorkspacePath);
|
|
28
|
+
|
|
29
|
+
if (!isWorkspacePathEmpty) {
|
|
30
|
+
throw new Error(`Directory "${resolvedWorkspacePath}" must be empty`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// create new workspace
|
|
34
|
+
let workspace = await Workspace.create({
|
|
35
|
+
args,
|
|
36
|
+
path: resolvedWorkspacePath,
|
|
37
|
+
templateId,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await workspace.update({args});
|
|
41
|
+
})()
|
|
42
|
+
.then(() => {
|
|
43
|
+
observer.complete();
|
|
44
|
+
})
|
|
45
|
+
.catch((error) => {
|
|
46
|
+
observer.error(error);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function packageNameToDirectory(packageName: string): string {
|
|
2
|
+
const packageNameParts = packageName.split('/');
|
|
3
|
+
|
|
4
|
+
if (packageNameParts.length === 1) {
|
|
5
|
+
return packageNameParts[0] as string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (packageNameParts.length > 1 && packageName[0] !== '@') {
|
|
9
|
+
return packageNameParts[0] as string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return packageNameParts[1] as string;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './internals/packageNameToDirectory.js';
|