From 3aae9699087523bafc46a229ea4d09d489991402 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:22:10 +0900 Subject: [PATCH 1/9] Use package.json as project boundary --- packages/cli/src/project/WorkspaceLoader.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/project/WorkspaceLoader.ts b/packages/cli/src/project/WorkspaceLoader.ts index 5cfd87b2..57b27c3e 100644 --- a/packages/cli/src/project/WorkspaceLoader.ts +++ b/packages/cli/src/project/WorkspaceLoader.ts @@ -71,7 +71,8 @@ export class WorkspaceLoader { } readonly filePattern: string; - readonly manifestName = "uimix.json"; + readonly uimixProjectFile = "uimix.json"; + readonly projectBoundary = "package.json"; // TODO: other project boundaries jsons = new Map(); // project path -> project json get json(): ProjectJSON { @@ -97,7 +98,7 @@ export class WorkspaceLoader { async load(): Promise { const filePaths = await this.fileAccess.glob( - `{${this.filePattern},**/${this.manifestName}}` + `{${this.filePattern},**/${this.projectBoundary}}` ); filePaths.sort(); @@ -106,14 +107,14 @@ export class WorkspaceLoader { ]); for (const manifestPaths of filePaths.filter((filePath) => - filePath.endsWith(this.manifestName) + filePath.endsWith(this.projectBoundary) )) { const parentPath = path.dirname(manifestPaths); filePathsForProject.set(parentPath, []); } for (const filePath of filePaths) { - if (filePath.endsWith(this.manifestName)) { + if (filePath.endsWith(this.projectBoundary)) { continue; } @@ -134,7 +135,7 @@ export class WorkspaceLoader { manifest = ProjectManifestJSON.parse( JSON.parse( await this.fileAccess.readText( - path.join(projectPath, this.manifestName) + path.join(projectPath, this.uimixProjectFile) ) ) ); @@ -188,7 +189,7 @@ export class WorkspaceLoader { } await this.fileAccess.writeText( - path.join(projectPath, this.manifestName), + path.join(projectPath, this.uimixProjectFile), formatJSON(JSON.stringify(manifest)) ); From 866fa25d84dde030e774d948a50bac146c261585 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:24:52 +0900 Subject: [PATCH 2/9] Fix test --- packages/cli/src/project/WorkspaceLoader.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/cli/src/project/WorkspaceLoader.test.ts b/packages/cli/src/project/WorkspaceLoader.test.ts index d9004fcd..abb006c8 100644 --- a/packages/cli/src/project/WorkspaceLoader.test.ts +++ b/packages/cli/src/project/WorkspaceLoader.test.ts @@ -56,6 +56,12 @@ describe(WorkspaceLoader.name, () => { loader.jsons.set(deepInnerProjectPath, deepInnerProject.toJSON()); await loader.save(); + fs.writeFileSync(tmpObj.name + "/demo-project/inner/package.json", "{}"); + fs.writeFileSync( + tmpObj.name + "/demo-project/inner/inner/package.json", + "{}" + ); + expect( loader.projectPathForFile(tmpObj.name + "/demo-project/src/page1.uimix") ).toEqual(tmpObj.name + "/demo-project"); @@ -113,6 +119,9 @@ describe(WorkspaceLoader.name, () => { path.resolve(loader.rootPath, "inner"), innerProject.toJSON() ); + await loader.save(); + + fs.writeFileSync(tmpObj.name + "/demo-project/inner/package.json", "{}"); let watchCount = 0; loader.watch(() => { From 91b98ad508c8545388535ea2dcbbe739417f8141 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:25:39 +0900 Subject: [PATCH 3/9] Add dummy package.json --- packages/sandbox/src/nested/package.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/sandbox/src/nested/package.json diff --git a/packages/sandbox/src/nested/package.json b/packages/sandbox/src/nested/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/packages/sandbox/src/nested/package.json @@ -0,0 +1 @@ +{} From ded37ef5deb1d1179fbec852ec756e84320331d1 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:28:56 +0900 Subject: [PATCH 4/9] README --- packages/sandbox/src/nested/README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 packages/sandbox/src/nested/README.md diff --git a/packages/sandbox/src/nested/README.md b/packages/sandbox/src/nested/README.md new file mode 100644 index 00000000..c26c4111 --- /dev/null +++ b/packages/sandbox/src/nested/README.md @@ -0,0 +1,5 @@ +## Nested project example + +UIMix identifies any directory containing a package.json file as a project. + +It allows for the nesting of projects within one another, while ensuring that files from the nested project are not included in the parent project. This feature is useful when setting up a monorepo. From 17cfdacbf4595bb4ee023cc52fe189d96f8027f4 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:34:51 +0900 Subject: [PATCH 5/9] Fix --- packages/editor/src/state/{ => demoFile}/demo.uimix | 0 packages/editor/src/state/demoFile/package.json | 1 + packages/editor/src/state/uimix.json | 1 - 3 files changed, 1 insertion(+), 1 deletion(-) rename packages/editor/src/state/{ => demoFile}/demo.uimix (100%) create mode 100644 packages/editor/src/state/demoFile/package.json delete mode 100644 packages/editor/src/state/uimix.json diff --git a/packages/editor/src/state/demo.uimix b/packages/editor/src/state/demoFile/demo.uimix similarity index 100% rename from packages/editor/src/state/demo.uimix rename to packages/editor/src/state/demoFile/demo.uimix diff --git a/packages/editor/src/state/demoFile/package.json b/packages/editor/src/state/demoFile/package.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/packages/editor/src/state/demoFile/package.json @@ -0,0 +1 @@ +{} diff --git a/packages/editor/src/state/uimix.json b/packages/editor/src/state/uimix.json deleted file mode 100644 index 83680f2b..00000000 --- a/packages/editor/src/state/uimix.json +++ /dev/null @@ -1 +0,0 @@ -{ "componentURLs": [] } From a67a5e93889e89358f0a4e80f352703b9a5b03d2 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:38:44 +0900 Subject: [PATCH 6/9] Fix --- packages/editor/src/state/ProjectState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/state/ProjectState.ts b/packages/editor/src/state/ProjectState.ts index 322c7202..d29c9275 100644 --- a/packages/editor/src/state/ProjectState.ts +++ b/packages/editor/src/state/ProjectState.ts @@ -17,7 +17,7 @@ import { getIncrementalUniqueName } from "@uimix/foundation/src/utils/Name"; import { PageState } from "./PageState"; import { ScrollState } from "./ScrollState"; // eslint-disable-next-line import/no-unresolved -import demoFile from "./demo.uimix?raw"; +import demoFile from "./demoFile/demo.uimix?raw"; import { filesToProjectJSON } from "../../../cli/src/project/WorkspaceLoader"; export class ProjectState { From a448315e472bf30fe5a7090e017305e5c1e9a443 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:38:53 +0900 Subject: [PATCH 7/9] Watch project boundary as well --- packages/cli/src/project/WorkspaceLoader.ts | 23 ++++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/project/WorkspaceLoader.ts b/packages/cli/src/project/WorkspaceLoader.ts index 57b27c3e..74ec7c58 100644 --- a/packages/cli/src/project/WorkspaceLoader.ts +++ b/packages/cli/src/project/WorkspaceLoader.ts @@ -217,18 +217,21 @@ export class WorkspaceLoader { watch(onChange: (projectJSON: ProjectJSON) => void): () => void { console.log("start watching..."); - return this.fileAccess.watch(this.filePattern, async () => { - try { - if (this.isSaving) { - return; - } - if (await this.load()) { - onChange(this.json); + return this.fileAccess.watch( + `{${this.filePattern},**/${this.projectBoundary}}`, + async () => { + try { + if (this.isSaving) { + return; + } + if (await this.load()) { + onChange(this.json); + } + } catch (e) { + console.error(e); } - } catch (e) { - console.error(e); } - }); + ); } } From 6eb4b149db43779f66ad1acbd756687b3a50343d Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:50:44 +0900 Subject: [PATCH 8/9] Load empty files --- packages/cli/src/project/WorkspaceLoader.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/project/WorkspaceLoader.ts b/packages/cli/src/project/WorkspaceLoader.ts index 74ec7c58..2d80d8ce 100644 --- a/packages/cli/src/project/WorkspaceLoader.ts +++ b/packages/cli/src/project/WorkspaceLoader.ts @@ -146,9 +146,14 @@ export class WorkspaceLoader { const pages = new Map(); for (const pagePath of pagePaths) { - const pageJSON = PageJSON.parse( - JSON.parse(await this.fileAccess.readText(pagePath)) - ); + const pageText = await this.fileAccess.readText(pagePath); + + const pageJSON = + pageText.trim() === "" + ? { nodes: {}, styles: {} } + : PageJSON.parse( + JSON.parse(await this.fileAccess.readText(pagePath)) + ); pages.set( path.relative(projectPath, pagePath).replace(/\.uimix$/, ""), From cd989a823252e51cdfc5b977abfa56be79b75799 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 13 Apr 2023 10:55:24 +0900 Subject: [PATCH 9/9] Do not save project files of non affected project --- packages/cli/src/project/WorkspaceLoader.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/project/WorkspaceLoader.ts b/packages/cli/src/project/WorkspaceLoader.ts index 2d80d8ce..29a5cb18 100644 --- a/packages/cli/src/project/WorkspaceLoader.ts +++ b/packages/cli/src/project/WorkspaceLoader.ts @@ -189,14 +189,8 @@ export class WorkspaceLoader { for (const [projectPath, json] of this.jsons) { const { manifest, pages } = projectJSONToFiles(json); - if (pages.size === 0) { - continue; - } - await this.fileAccess.writeText( - path.join(projectPath, this.uimixProjectFile), - formatJSON(JSON.stringify(manifest)) - ); + let projectSaved = false; for (const [pageName, pageJSON] of pages) { const pagePath = path.join(projectPath, pageName + ".uimix"); @@ -208,6 +202,14 @@ export class WorkspaceLoader { formatJSON(JSON.stringify(pageJSON)) ); pagePathsToDelete.delete(pagePath); + projectSaved = true; + } + + if (projectSaved) { + await this.fileAccess.writeText( + path.join(projectPath, this.uimixProjectFile), + formatJSON(JSON.stringify(manifest)) + ); } }