UNPKG

@wix/cli

Version:

CLI tool for building Wix sites and applications

917 lines (871 loc) 32.2 kB
import { createRequire as _createRequire } from 'node:module'; const require = _createRequire(import.meta.url); import { getSourceFolder } from "./chunk-DZ3U3XXP.js"; import { CliError, CliErrorCode } from "./chunk-CO5A7CZG.js"; import { init_esm_shims } from "./chunk-EXLZF52D.js"; // ../cli-site/src/site-fs-manager.ts init_esm_shims(); import { relative } from "node:path"; // ../../node_modules/@wix/anyide-cli-file-structure/dist/index.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/wixSiteFSManager.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/index.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/code.js init_esm_shims(); import path from "path"; // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/utils/veloUtils.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/utils/constants.js init_esm_shims(); var PAGE_CODE_TEMPLATE = `// API Reference: https://www.wix.com/velo/reference/api-overview/introduction // \u201CHello, World!\u201D Example: https://learn-code.wix.com/en/article/hello-world $w.onReady(function () { // Write your JavaScript here // To select an element by ID use: $w('#elementID') // Click 'Preview' to run your code }); `; // ../../node_modules/@wix/anyide-cli-file-structure/node_modules/@wix/velo-github-layout-definitions/build/index.js init_esm_shims(); import { join } from "node:path"; function getSourceFolder2(projectFolder) { return join(projectFolder, "src"); } function getPagesFolder(projectFolder = "") { return join(getSourceFolder2(projectFolder), "pages"); } function getPublicFolder(projectFolder = "") { return join(getSourceFolder2(projectFolder), "public"); } function getBackendFolder(projectFolder = "") { return join(getSourceFolder2(projectFolder), "backend"); } function getStylesFolder(projectFolder = "") { return join(getSourceFolder2(projectFolder), "styles"); } // ../../node_modules/@wix/anyide-cli-file-structure/dist/types.js init_esm_shims(); var foldersType = { backend: "backend", public: "public", styles: "styles" }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/utils/veloUtils.js var createDefaultPageCodeFile = async (siteFileSystem, filePath) => siteFileSystem.writeFile(filePath, PAGE_CODE_TEMPLATE); var getPageCodeFilePath = (pageId) => `${getPagesFolder()}/${pageId}.js`; var convertToGithubLayout = (state, path6, folderType) => { switch (folderType) { case foldersType.backend: return transformPath(path6, state.fileStructure.getBackendFolderPath(), getBackendFolder()); case foldersType.public: return transformPath(path6, state.fileStructure.getPublicFolderPath(), getPublicFolder()); case foldersType.styles: return transformPath(path6, state.fileStructure.getStylesFolderPath(), getStylesFolder()); } }; var transformPath = (path6, basePath, folderPrefix) => { const relativePath = path6.replace(`${basePath}/`, ""); return `${folderPrefix}/${relativePath}`; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/code.js var readAllFilesInDir = async (state, dir, folderType) => { const entries = await state.fileSystem.readFolder(dir); const filePromises = entries.map(async (entry) => { const entryPath = path.join(dir, entry.name); if (entry.isFile()) { return { path: convertToGithubLayout(state, entryPath, folderType), content: await state.fileSystem.readFile(entryPath) }; } return readAllFilesInDir(state, entryPath, folderType); }); return (await Promise.all(filePromises)).flat(); }; var readBackendFiles = async (state) => readAllFilesInDir(state, state.fileStructure.getBackendFolderPath(), foldersType.backend); var readPublicFiles = async (state) => readAllFilesInDir(state, state.fileStructure.getPublicFolderPath(), foldersType.public); var readStylesFiles = async (state) => readAllFilesInDir(state, state.fileStructure.getStylesFolderPath(), foldersType.styles); var readPageCodeFiles = async (state) => { const codeFiles = []; const pages = state.pages.getAll(); for (const { pageId, pagePath } of pages) { const page = state.fileStructure.getPageFilesPaths(pagePath); const content = await state.fileSystem.readFile(page.code); codeFiles.push({ path: getPageCodeFilePath(pageId), content }); } return codeFiles; }; var getSiteCode = async (state) => { const allFiles = await Promise.all([ readBackendFiles(state), readPublicFiles(state), readStylesFiles(state), readPageCodeFiles(state) ]); return { files: allFiles.flat(), layout: "GITHUB", ignoreForbiddenPaths: true }; }; var onlinePathRegex = /^(public\/pages|public|backend|styles)\/?((.+)\.js|.*)$/; var splitOnlinePath = (onlinePath) => { const [, folderPath, relativeFilePath, pageId] = onlinePathRegex.exec(onlinePath) ?? []; return { folderPath, relativeFilePath, pageId }; }; var buildCodeFilePath = (folderPath, relativeFilePath) => { if (!relativeFilePath) { return folderPath; } return path.join(folderPath, relativeFilePath); }; var buildPageCodeFilePath = ({ pages, fileStructure }, pageId) => { if (!pageId) { throw new Error("Invalid page code file path"); } const pageFolderPath = pages.getFolderPath(pageId); if (!pageFolderPath) { throw new Error("Page does not exist"); } return fileStructure.getPageFilesPaths(pageFolderPath).code; }; var convertOnlineLayoutToRelativePath = (state, onlinePath) => { const { fileStructure } = state; const { folderPath, relativeFilePath, pageId } = splitOnlinePath(onlinePath); switch (folderPath) { case "public": return buildCodeFilePath(fileStructure.getPublicFolderPath(), relativeFilePath); case "backend": return buildCodeFilePath(fileStructure.getBackendFolderPath(), relativeFilePath); case "styles": return buildCodeFilePath(fileStructure.getStylesFolderPath(), relativeFilePath); case "public/pages": return buildPageCodeFilePath(state, pageId); default: throw new Error("Unknown online path"); } }; var convertOnlineLayout = (state, basePath, onlinePath) => path.join(basePath, convertOnlineLayoutToRelativePath(state, onlinePath)); // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/index.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/document.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/utils/wmlUtils.js init_esm_shims(); var pageIdRegex = /<(?:Master)?Page\s[^>]*?(?<=\s)id="(.+?)".*?>/; var getPageId = async (siteFileSystem, { structure }) => { const structureXmlContent = await siteFileSystem.readFile(structure); const [match, pageId] = structureXmlContent.match(pageIdRegex) ?? []; if (!match) { throw new Error("pageId not found in wml"); } return pageId; }; var mapWmlFiles = async (documentStructure, callbackFn) => { const [structure, data, style] = await Promise.all([ callbackFn(documentStructure.structure, "structure"), callbackFn(documentStructure.data, "data"), callbackFn(documentStructure.style, "style") ]); return { structure, data, style }; }; var writeWmlFiles = async (siteFileSystem, documentStructure, wml) => { const filesContent = convertWmlExportToFiles(wml); await mapWmlFiles(documentStructure, (filePath, fileName) => siteFileSystem.writeFile(filePath, filesContent[fileName])); }; var removeWmlFiles = async (siteFileSystem, documentStructure) => { await mapWmlFiles(documentStructure, (filePath) => siteFileSystem.removeFile(filePath)); }; var writeWml = async (siteFileSystem, documentStructure, pageData) => { if (pageData === null) { return removeWmlFiles(siteFileSystem, documentStructure); } return writeWmlFiles(siteFileSystem, documentStructure, pageData.data); }; var readWml = async (siteFileSystem, documentStructure) => { const filesContent = await mapWmlFiles(documentStructure, async (filePath) => await siteFileSystem.readFile(filePath)); return convertFilesToWmlExport(filesContent); }; var indentedStringify = (data) => JSON.stringify(data, void 0, 2); var convertWmlExportToFiles = (wmlExport) => { const dataWithoutVersion = JSON.parse(wmlExport.data.content); const dataWithVersion = indentedStringify({ ...dataWithoutVersion, version: wmlExport.version }); return { structure: wmlExport.structure.content, style: wmlExport.style.content, data: dataWithVersion }; }; var convertFilesToWmlExport = (filesContent) => { const { version, ...dataWithoutVersion } = JSON.parse(filesContent.data); return { structure: { type: "xml", content: filesContent.structure }, data: { type: "json", content: indentedStringify(dataWithoutVersion) }, style: { type: "css", content: filesContent.style }, version }; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/document.js var getDocumentPages = async (state) => { const documentPages = {}; const pages = state.pages.getAll(); for (const { pageId, pagePath } of pages) { const page = state.fileStructure.getPageFilesPaths(pagePath); const data = await readWml(state.fileSystem, page.document); documentPages[pageId] = { data }; } return documentPages; }; var getSiteDocument = async (state) => { const documentPages = await getDocumentPages(state); const { masterPage, ...otherPages } = documentPages; if (!masterPage) { throw new Error("Missing master page"); } return { pages: { masterPage, ...otherPages } }; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/externalUpdates.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/page/utils.js init_esm_shims(); import path2 from "path"; var generatePageFolderPathByInfo = (state, pageInfo) => { const pagePath = state.fileStructure.getPagesPathsForType(pageInfo.type); return path2.join(...pagePath.map((entry) => entry.type === "Folder" ? entry.name : pageInfo[entry.variableName])); }; var escapeRegexSpecialChars = (str) => str.replace(/[.*+?^=!:${}()|[\]/\\]/g, "\\$&"); var isPathFormatMatching = (fullPath, basePath) => new RegExp(`^${escapeRegexSpecialChars(basePath)}(?: \\((\\d*)\\))?$`).test(fullPath); var generateNewPagePath = (state, pageInfo, existingPageFolderPath) => { let pageFolderPath = generatePageFolderPathByInfo(state, pageInfo); if (existingPageFolderPath && isPathFormatMatching(existingPageFolderPath, pageFolderPath)) { return existingPageFolderPath; } while (state.pages.getPageId(pageFolderPath)) { pageFolderPath = incrementPathSuffix(pageFolderPath); } return pageFolderPath; }; var createPageFiles = async (state, folderPath, pageData) => { const pageStructure = state.fileStructure.getPageFilesPaths(folderPath); await Promise.all([ writeWml(state.fileSystem, pageStructure.document, pageData), createDefaultPageCodeFile(state.fileSystem, pageStructure.code) ]); }; var createPage = async (state, pageId, pageData) => { const newPageFolder = generateNewPagePath(state, pageData.info); await state.fileSystem.createFolder(newPageFolder); await createPageFiles(state, newPageFolder, pageData); state.pages.addPage(pageId, newPageFolder); }; var removePage = async (state, pageId) => { const folderPath = state.pages.getFolderPath(pageId); if (!folderPath) return; await state.fileSystem.removeFolder(folderPath); state.pages.removePageById(pageId); }; var updatePage = async (state, pageId, existingPageFolderPath, pageData) => { const expectedFolderPath = generateNewPagePath(state, pageData.info, existingPageFolderPath); if (existingPageFolderPath !== expectedFolderPath) { await removePage(state, pageId); await createPage(state, pageId, pageData); return; } const pageStructure = state.fileStructure.getPageFilesPaths(existingPageFolderPath); await writeWml(state.fileSystem, pageStructure.document, pageData); }; var incrementPathSuffix = (path6) => { const [, origPath, suffix = 1] = path6.match(/^(.*?)(?: \((\d+)\))?$/) ?? []; return `${origPath} (${Number(suffix) + 1})`; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/externalUpdates.js var applyPageUpdate = async (state, pageId, pageData) => { if (pageData === null) { return removePage(state, pageId); } const existingPageFolder = state.pages.getFolderPath(pageId); if (existingPageFolder) { return updatePage(state, pageId, existingPageFolder, pageData); } return createPage(state, pageId, pageData); }; var applyDocumentExternalUpdates = async (state, { pages }) => { for (const [pageId, pageData] of Object.entries(pages)) { await applyPageUpdate(state, pageId, pageData); } }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/state.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/siteFileStructure.js init_esm_shims(); // ../../node_modules/@wix/anyide-template-layout/dist/index.js init_esm_shims(); // ../../node_modules/@wix/anyide-template-layout/dist/code.js init_esm_shims(); // ../../node_modules/@wix/anyide-template-layout/dist/configs/index.js init_esm_shims(); // ../../node_modules/@wix/anyide-template-layout/dist/configs/blocksConfig.js init_esm_shims(); var blocksConfig = { backend: "backend", public: "public", styles: "styles", pages: { structure: { code: "index.js", document: { structure: "structure.xml", data: "data.json", style: "style.wcss" } }, folders: { Page: [ { name: "pages", type: "Folder" }, { variableName: "title", type: "DynamicFolder" } ], Dashboard: [ { name: "dashboards", type: "Folder" }, { variableName: "dashboardName", type: "DynamicFolder" } ], Widget: [ { name: "widgets", type: "Folder" }, { variableName: "widgetName", type: "DynamicFolder" } ], Panel: [ { name: "widgets", type: "Folder" }, { variableName: "widgetName", type: "DynamicFolder" }, { name: "panels", type: "Folder" }, { variableName: "panelName", type: "DynamicFolder" } ] } } }; // ../../node_modules/@wix/anyide-template-layout/dist/configs/editorConfig.js init_esm_shims(); var editorConfig = { backend: "backend", public: "public", styles: "styles", pages: { structure: { code: "index.js", document: { structure: "structure.xml", data: "data.json", style: "style.wcss" } }, folders: { Page: [ { name: "pages", type: "Folder" }, { variableName: "title", type: "DynamicFolder" } ] } } }; // ../../node_modules/@wix/anyide-template-layout/dist/configs/index.js var configs = { Editor: editorConfig, Blocks: blocksConfig }; var getConfig = (structureType) => { const config = configs[structureType]; if (!config) { throw new Error("Unknown file structure type: " + structureType); } return config; }; // ../../node_modules/@wix/anyide-template-layout/dist/code.js var getBackendPath = (structureType) => getConfig(structureType).backend; var getPublicPath = (structureType) => getConfig(structureType).public; var getStylesPath = (structureType) => getConfig(structureType).styles; // ../../node_modules/@wix/anyide-template-layout/dist/page.js init_esm_shims(); import path3 from "path"; var getPagesPaths = (structureType) => getConfig(structureType).pages.folders; var getPageFilesPaths = (structureType, folderPath) => { const { pages } = getConfig(structureType); const { structure } = pages; return { code: path3.join(folderPath, structure.code), document: { structure: path3.join(folderPath, structure.document.structure), style: path3.join(folderPath, structure.document.style), data: path3.join(folderPath, structure.document.data) } }; }; var getPageFilesNames = (structureType, pageStructureType) => { const { pages } = getConfig(structureType); const { structure } = pages; if (pageStructureType === "document") { return /* @__PURE__ */ new Set([ structure[pageStructureType].structure, structure[pageStructureType].data, structure[pageStructureType].style ]); } return /* @__PURE__ */ new Set([structure[pageStructureType]]); }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/siteFileStructure.js var SiteFileStructure = class { fileStructureType; folderStructure; constructor(fileStructureType) { this.fileStructureType = fileStructureType; this.folderStructure = [ { path: this.generateFolderPath(getBackendPath), type: foldersType.backend }, { path: this.generateFolderPath(getPublicPath), type: foldersType.public }, { path: this.generateFolderPath(getStylesPath), type: foldersType.styles } ]; } generateFolderPath(getPathFunction) { return `${getPathFunction(this.fileStructureType)}/`; } getBackendFolderPath() { return getBackendPath(this.fileStructureType); } getPublicFolderPath() { return getPublicPath(this.fileStructureType); } getStylesFolderPath() { return getStylesPath(this.fileStructureType); } getPagesPaths() { return getPagesPaths(this.fileStructureType); } getPagesPathsForType(type) { const paths = this.getPagesPaths(); const pathForType = paths[type]; if (!pathForType) { throw new Error(`page type "${type}" is invalid for structureType "${this.fileStructureType}"`); } return pathForType; } getPageFilesPaths(pageFolderPath) { return getPageFilesPaths(this.fileStructureType, pageFolderPath); } matchPagePath(filePath) { const pageFilesPath = this.getPagesPaths(); const sortedPageFilesPath = Object.entries(pageFilesPath).sort((a, b) => b[1].length - a[1].length); for (const [type, pagePath] of sortedPageFilesPath) { const typeRegex = new RegExp(`^(${pagePath.map((entry) => entry.type === "Folder" ? entry.name : ".+?").join("/")})/(.+)`); const path6 = typeRegex.exec(filePath); if (path6) { return { type, pagePath: path6[1], fileName: path6[2] }; } } return null; } createCodeStructureInfo(folderType) { return { type: "code", isPageFile: false, folderType }; } getCodeStructureInfoByFolderPath(filePath) { for (const folder of this.folderStructure) { if (filePath.startsWith(folder.path)) { return this.createCodeStructureInfo(folder.type); } } } getStructureInfoByFilePath(filePath) { const folderStructure = this.getCodeStructureInfoByFolderPath(filePath); if (folderStructure) { return folderStructure; } const pageMatch = this.matchPagePath(filePath); if (pageMatch) { const { pagePath, fileName } = pageMatch; const codeFiles = getPageFilesNames(this.fileStructureType, "code"); if (codeFiles.has(fileName)) { return { type: "code", isPageFile: true, pagePath }; } const documentFiles = getPageFilesNames(this.fileStructureType, "document"); if (documentFiles.has(fileName)) { return { type: "document", isPageFile: true, pagePath }; } } return null; } }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/siteFileSystem.js init_esm_shims(); import fs from "fs/promises"; import path4 from "path"; var SiteFileSystem = class { rootFolderPath; constructor(rootFolderPath) { this.rootFolderPath = rootFolderPath; } getFullPath(relativePath) { return path4.join(this.rootFolderPath, relativePath); } async readFile(filePath) { return fs.readFile(this.getFullPath(filePath), "utf-8"); } async writeFile(filePath, content) { return fs.writeFile(this.getFullPath(filePath), content); } async removeFile(filePath) { return fs.rm(this.getFullPath(filePath)); } async readFolder(folderPath) { return fs.readdir(this.getFullPath(folderPath), { withFileTypes: true }); } async createFolder(folderPath) { await fs.mkdir(this.getFullPath(folderPath), { recursive: true }); } async removeFolder(folderPath) { return fs.rm(this.getFullPath(folderPath), { recursive: true }); } }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/stateBuilder.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/sitePagesState.js init_esm_shims(); var CaseInsensitiveMap = class { map = /* @__PURE__ */ new Map(); normalizeKey(key) { return key.toLowerCase(); } get(key) { return this.map.get(this.normalizeKey(key)); } set(key, value) { this.map.set(this.normalizeKey(key), value); } delete(key) { this.map.delete(this.normalizeKey(key)); } entries() { return this.map.entries(); } }; var SitePagesState = class { pageIdToFolderPath = /* @__PURE__ */ new Map(); folderPathToPageId = new CaseInsensitiveMap(); validatePageIdExists(pageId) { if (this.pageIdToFolderPath.has(pageId)) { throw new Error(`Duplicated pageId found in structure.xml files: ${pageId}`); } } getAll() { const allPages = []; for (const [pageId, pagePath] of this.pageIdToFolderPath.entries()) { allPages.push({ pageId, pagePath }); } return allPages; } addPage(pageId, folderPath) { this.validatePageIdExists(pageId); this.pageIdToFolderPath.set(pageId, folderPath); this.folderPathToPageId.set(folderPath, pageId); } removePageById(pageId) { const folderPath = this.pageIdToFolderPath.get(pageId); if (folderPath === void 0) { return; } this.pageIdToFolderPath.delete(pageId); this.folderPathToPageId.delete(folderPath); } removePageByPath(path6) { const pageId = this.folderPathToPageId.get(path6); if (pageId === void 0) { return; } this.pageIdToFolderPath.delete(pageId); this.folderPathToPageId.delete(path6); } getFolderPath(pageId) { return this.pageIdToFolderPath.get(pageId); } getPageId(folderPath) { return this.folderPathToPageId.get(folderPath); } }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/stateBuilder.js import path5 from "path"; var getFoldersInPath = async (siteFileSystem, dirPath) => { const entries = await siteFileSystem.readFolder(dirPath); return entries.filter((entry) => entry.isDirectory()).map(({ name }) => name); }; var getMatchingPaths = (folderName, paths) => paths.filter(([first]) => first?.type === "DynamicFolder" || first.name === folderName); var isNonEmptyFolder = async (siteFileSystem, folderPath) => { const entries = await siteFileSystem.readFolder(folderPath); return entries.length > 0; }; var filterAsync = async (arr, predicate) => { const results = await Promise.all(arr.map(predicate)); return arr.filter((_, index) => results[index]); }; var getPages = async (siteFileSystem, paths, rootPath = "") => { if (paths.length === 0) return []; const result = []; const rootFolders = await getFoldersInPath(siteFileSystem, rootPath); for (const folderName of rootFolders) { const matchingPaths = getMatchingPaths(folderName, paths); if (matchingPaths.length > 0) { const finalPaths = await filterAsync(matchingPaths.filter((p) => p.length === 1).map(() => path5.join(rootPath, folderName)), (folderPath) => isNonEmptyFolder(siteFileSystem, folderPath)); const nonFinalPaths = matchingPaths.filter((p) => p.length > 1).map(([, ...rest]) => rest); const nestedPages = await getPages(siteFileSystem, nonFinalPaths, path5.join(rootPath, folderName)); result.push(...finalPaths, ...nestedPages); } } return result; }; var getAllPageFolders = async (siteFileStructure, siteFileSystem) => { const paths = siteFileStructure.getPagesPaths(); return await getPages(siteFileSystem, Object.values(paths)); }; var buildPagesState = async (siteFileStructure, siteFileSystem) => { const state = new SitePagesState(); const pagesFolders = await getAllPageFolders(siteFileStructure, siteFileSystem); await Promise.all(pagesFolders.map(async (folderPath) => { const filePaths = siteFileStructure.getPageFilesPaths(folderPath); const pageId = await getPageId(siteFileSystem, filePaths.document); state.addPage(pageId, folderPath); })); return state; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/state/state.js var buildState = async (rootFolderPath, fileStructureType) => { const fileSystem = new SiteFileSystem(rootFolderPath); const fileStructure = new SiteFileStructure(fileStructureType); const pages = await buildPagesState(fileStructure, fileSystem); return { fileSystem, fileStructure, pages }; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/applyFsUpdates.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/code/fsUpdates.js init_esm_shims(); var initVeloCodeUpdate = () => { return { layout: "GITHUB", ignoreForbiddenPaths: true }; }; var applyDeleteCode = (codeUpdate, path6) => { if (!codeUpdate) { codeUpdate = initVeloCodeUpdate(); } codeUpdate.pathsToDelete ??= []; codeUpdate.pathsToDelete.push(path6); return codeUpdate; }; var applyUpdateCode = (codeUpdate, veloFile) => { if (!codeUpdate) { codeUpdate = initVeloCodeUpdate(); } codeUpdate.filesToUpdate ??= []; codeUpdate.filesToUpdate.push(veloFile); return codeUpdate; }; var accumulateFsUpdateToVeloCodeUpdate = async (state, veloCodeUpdate, structureInfo, { path: path6, action }) => { let result = veloCodeUpdate; const pathInGithubLayout = convertToGithubLayout(state, path6, structureInfo.folderType); if (action === "DELETE") { result = applyDeleteCode(result, pathInGithubLayout); } else if (action === "UPDATE") { result = applyUpdateCode(result, { path: pathInGithubLayout, content: await state.fileSystem.readFile(path6) }); } return result; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/page/fsUpdates.js init_esm_shims(); // ../../node_modules/@wix/anyide-cli-file-structure/dist/document/fsUpdates.js init_esm_shims(); var applyDocumentUpdate = (documentUpdate, pageId, value) => { documentUpdate ??= { pages: {} }; documentUpdate.pages[pageId] = value; return documentUpdate; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/page/fsUpdates.js var applyDeletePage = (siteFsUpdate, pageId) => { siteFsUpdate.document = applyDocumentUpdate(siteFsUpdate.document, pageId, null); const veloPath = getPageCodeFilePath(pageId); siteFsUpdate.code = applyDeleteCode(siteFsUpdate.code, veloPath); return siteFsUpdate; }; var applyCodeUpdateInPage = async (state, siteFsUpdate, pageId, path6) => { siteFsUpdate.code = applyUpdateCode(siteFsUpdate.code, { path: getPageCodeFilePath(pageId), content: await state.fileSystem.readFile(path6) }); return siteFsUpdate; }; var accumulatePageFsUpdateToWixSiteFSUpdate = async (state, siteFsUpdate, structureInfo, { action, path: path6 }) => { const result = siteFsUpdate; const pageId = state.pages.getPageId(structureInfo.pagePath); if (action === "DELETE") { if (!pageId) { return result; } const { document, code } = applyDeletePage(result, pageId); result.document = document; result.code = code; state.pages.removePageById(pageId); } else if (action === "UPDATE") { const page = state.fileStructure.getPageFilesPaths(structureInfo.pagePath); if (structureInfo.type === "document") { const wml = await readWml(state.fileSystem, page.document); const pageIdInDocument = await getPageId(state.fileSystem, page.document); const folderPathForPageIdInDocument = state.pages.getFolderPath(pageIdInDocument); if (folderPathForPageIdInDocument && folderPathForPageIdInDocument !== structureInfo.pagePath) { throw new Error(`Duplicated pageId found in structure.xml files: ${pageIdInDocument}`); } if (pageId !== pageIdInDocument) { if (pageId) { const { document, code } = applyDeletePage(result, pageId); result.document = document; result.code = code; await applyCodeUpdateInPage(state, result, pageIdInDocument, page.code); state.pages.removePageById(pageId); } state.pages.addPage(pageIdInDocument, structureInfo.pagePath); } result.document = applyDocumentUpdate(result.document, pageIdInDocument, { data: wml }); } else if (structureInfo.type === "code") { if (!pageId) { return result; } await applyCodeUpdateInPage(state, result, pageId, path6); } } return result; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/applyFsUpdates.js var applyFsUpdates = async (state, updates) => { const result = {}; for (const { path: path6, action } of updates) { const structureInfo = state.fileStructure.getStructureInfoByFilePath(path6); if (structureInfo === null) continue; if (structureInfo.isPageFile) { const { document, code } = await accumulatePageFsUpdateToWixSiteFSUpdate(state, result, structureInfo, { path: path6, action }); result.code = code; result.document = document; } else if (structureInfo.type === "code") { result.code = await accumulateFsUpdateToVeloCodeUpdate(state, result.code, structureInfo, { path: path6, action }); } } return result; }; // ../../node_modules/@wix/anyide-cli-file-structure/dist/wixSiteFSManager.js var WixSiteFSManager = class _WixSiteFSManager { state; constructor(state) { this.state = state; } static async create(rootFolderPath, fileStructureType) { const state = await buildState(rootFolderPath, fileStructureType); return new _WixSiteFSManager(state); } getCode = async () => getSiteCode(this.state); getDocument = async () => getSiteDocument(this.state); applyFsUpdates = async (updates) => applyFsUpdates(this.state, updates); applyExternalUpdates = async ({ code, document }) => { if (code) { throw new Error("external code updates are not supported"); } if (document) { await applyDocumentExternalUpdates(this.state, document); } }; createConvertOnlineLayoutApi = (basePath) => (onlinePath) => convertOnlineLayout(this.state, basePath, onlinePath); }; // ../cli-site/src/site-fs-manager.ts async function createSiteFsManager(projectFolder) { const srcFolder = getSourceFolder(projectFolder); const fsManager = await WixSiteFSManager.create(srcFolder, "Editor").catch( (error) => { throw new CliError({ code: CliErrorCode.FailedToInitializeSiteFsManager(), cause: error }); } ); return { convertToOnlineLayout: fsManager.createConvertOnlineLayoutApi( relative(projectFolder, srcFolder) ), async getCode() { try { return await fsManager.getCode(); } catch (error) { throw new CliError({ code: CliErrorCode.FailedToGetSiteFsManagerCode(), cause: error }); } }, async getDocument() { try { return await fsManager.getDocument(); } catch (error) { throw new CliError({ code: CliErrorCode.FailedToGetSiteFsManagerDocument(), cause: error }); } }, async applyFsUpdates(updates) { try { return await fsManager.applyFsUpdates(updates); } catch (error) { throw new CliError({ code: CliErrorCode.FailedToApplySiteFsManagerFsUpdates(), cause: error }); } }, async applyExternalUpdates(update) { try { await fsManager.applyExternalUpdates(update); } catch (error) { throw new CliError({ code: CliErrorCode.FailedToApplySiteFsManagerExternalUpdates(), cause: error }); } } }; } export { createSiteFsManager }; //# sourceMappingURL=chunk-J3YCPEZS.js.map