@next-bricks/vb-experiment 0.1.8 → 0.1.9

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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunks/644.a129f8b3.js","mappings":"kJAyCIA,E,kVACEC,EAA8B,gCAsQnC,SAAAC,IAAA,OAAAA,GAAAC,EAAAA,EAAAA,IAtNM,UAAAC,GAGqC,IAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,GAHF,cACxCC,EAAa,WACbC,GACyBR,EACnBS,EAAM,IAAIC,KACVC,EAAUF,EAAIG,OAAO,WACrBC,EAAMF,EAAQC,OAAO,OAErBE,EAA6B,CACjCC,SAAU,GACVC,SAAU,IAAIC,KAEVC,GAAkBC,EAAAA,EAAAA,IAAcX,EAAWY,OAAQ,GAAIN,GAEvDO,EAA0C,CAC9CC,GAAIf,EAAcgB,MAClBC,KAAMjB,EAAciB,KACpBC,SAAUlB,EAAcmB,WAAWD,SACnCE,WAAYpB,EAAcmB,WAAWC,WACrCC,MAAOrB,EAAcmB,WAAWE,MAChCC,YAAatB,EAAcmB,WAAWG,YACtCC,QAASvB,EAAcmB,WAAWI,QAClCC,cAAeC,KAAKC,MAAM1B,EAAcmB,WAAWK,eAAiB,MACpEG,SAAUF,KAAKC,MAAM1B,EAAcmB,WAAWS,MAAQ,QACtDC,gBAAgB,GAElBvB,EAAIwB,KACF,SACAC,EAAS,kBAADC,OAAmBP,KAAKQ,UAAUnB,EAAK,KAAM,GAAE,OAGzD,IAAMoB,EAAuB,QAAnBxC,EAAIO,EAAWiC,YAAI,IAAAxC,EAAAA,EAAI,CAAC,EAI5ByC,EAAsC,QAAvBxC,EAAGuC,EAAKC,uBAAe,IAAAxC,EAAAA,EAAI,GAC1CyC,EAA0B,QAAjBxC,EAAGsC,EAAKE,iBAAS,IAAAxC,EAAAA,EAAI,GAC9ByC,EAAkB,QAAbxC,EAAGqC,EAAKG,aAAK,IAAAxC,E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C,QAAQK,GACxC,OAAQR,GACN,IAAK,WACCI,MAAMC,QAAQJ,IAAUA,EAAMV,OAAS,GACzCe,EAAcL,GAEhB,MACF,IAAK,KACH,MACF,IAAK,iBACL,IAAK,iBACCG,MAAMC,QAAQJ,IAA2B,IAAjBA,EAAMV,eACzBiB,EAASR,GAElB,MACF,QACgB,OAAVC,IAA4B,IAAVA,UACbO,EAASR,GAI1B,EAtWAS,EAAAA,EAAAA,gBAAe7I,EAA6B,CAC1C2B,KAAM3B,EACN8I,QAAS,CACPC,oBAAoBvF,GACO,YAArBA,EAAKwF,OAAO3B,MACd7D,EAAKyF,YAAYC,EAAAA,yBAA2B1F,EAAKC,MAErD,EACA0F,WAAW3F,GACT,OAAQA,EAAKC,KAAK9B,MAChB,IAAK,KACH5B,EAAgBqJ,IAAI,gCACpB,MACF,IAAK,IACHrJ,EAAgBqJ,IAAI,2BACpB,MACF,IAAK,SACHrJ,EAAgBqJ,IAAI,gCACpB,MACF,IAAK,QACHrJ,EAAgBqJ,IACd,kEAIR,KA+UJC,eAAeC,OACb,wCACAC,EAAAA,EAAAA,sBA3TK,SAAkCC,GAAA,OAAAvJ,EAAAsH,MAAC,KAADC,UAAA,I","sources":["webpack:///./src/data-providers/export-as-source-files.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport type { Storyboard, MicroApp, StoryboardMeta } from \"@next-core/types\";\nimport { createProviderClass } from \"@next-core/utils/general\";\nimport JSZip from \"jszip\";\nimport { saveAs } from \"file-saver\";\nimport { format } from \"prettier/standalone.js\";\nimport parserBabel from \"prettier/parser-babel.js\";\nimport * as t from \"@babel/types\";\nimport { transform, registerPlugin } from \"@babel/standalone\";\nimport {\n ExtractState,\n extractRoutes,\n extractTemplates,\n} from \"./utils/extract.js\";\nimport {\n SourceFileOrFolder,\n buildFileStructure,\n} from \"./utils/buildFileStructure.js\";\nimport { generate } from \"./utils/generators/generate.js\";\nimport jsxConstantsJs from \"./raws/jsx/constants.js.txt\";\nimport jsxIndexJs from \"./raws/jsx/index.js.txt\";\nimport jsxJsxRuntimeJs from \"./raws/jsx/jsx-runtime.js.txt\";\nimport jsxPackageJson from \"./raws/jsx/package.json.txt\";\nimport jsxLoadStyleTextJs from \"./raws/jsx/loadStyleText.js.txt\";\nimport jsxLoadFunctionJs from \"./raws/jsx/loadFunction.js.txt\";\nimport scriptsBabelJs from \"./raws/scripts/babel.js.txt\";\nimport scriptsBuildJs from \"./raws/scripts/build.js.txt\";\nimport scriptsStartJs from \"./raws/scripts/start.js.txt\";\nimport scriptsTranspileJs from \"./raws/scripts/transpile.js.txt\";\nimport srcResourcesIndexJs from \"./raws/src/resources/index.js.txt\";\nimport srcIndexJs from \"./raws/src/index.js.txt\";\nimport editorConfig from \"./raws/.editorconfig.txt\";\nimport gitIgnore from \"./raws/.gitignore.txt\";\nimport babelConfigJs from \"./raws/babel.config.js.txt\";\nimport declarationsDTs from \"./raws/declarations.d.ts.txt\";\nimport devConfigMjs from \"./raws/dev.config.mjs.txt\";\nimport packageJson from \"./raws/package.json.txt\";\nimport jsconfigJson from \"./raws/jsconfig.json.txt\";\nimport readmeMd from \"./raws/README.md.txt\";\nimport { JS_RESERVED_WORDS } from \"./utils/constants.js\";\n\nlet fnGlobalImports: Set<string>;\nconst transformStoryboardFunction = \"transform-storyboard-function\";\nregisterPlugin(transformStoryboardFunction, {\n name: transformStoryboardFunction,\n visitor: {\n FunctionDeclaration(path) {\n if (path.parent.type === \"Program\") {\n path.replaceWith(t.exportDefaultDeclaration(path.node));\n }\n },\n Identifier(path) {\n switch (path.node.name) {\n case \"FN\":\n fnGlobalImports.add('import FN from \"./index.js\";');\n break;\n case \"_\":\n fnGlobalImports.add('import _ from \"lodash\";');\n break;\n case \"moment\":\n fnGlobalImports.add('import moment from \"moment\";');\n break;\n case \"PIPES\":\n fnGlobalImports.add(\n 'import { pipes as PIPES } from \"@easyops-cn/brick-next-pipes\";'\n );\n break;\n }\n },\n },\n});\n\nexport interface StoryboardAssemblyResult {\n storyboard: Storyboard;\n\n projectDetail: {\n appId: string;\n name: string;\n appSetting: Pick<\n MicroApp,\n \"homepage\" | \"theme\" | \"locales\" | \"noAuthGuard\"\n > & {\n layoutType?: string;\n defaultConfig?: string;\n icon?: string;\n };\n brickNextVersion?: number;\n };\n}\n\nexport async function exportAsSourceFiles({\n projectDetail,\n storyboard,\n}: StoryboardAssemblyResult): Promise<void> {\n const zip = new JSZip();\n const project = zip.folder(\"project\")!;\n const src = project.folder(\"src\")!;\n\n const extractState: ExtractState = {\n extracts: [],\n namePool: new Map(),\n };\n const extractedRoutes = extractRoutes(storyboard.routes, [], extractState);\n\n const app: MicroApp & { layoutType?: string } = {\n id: projectDetail.appId,\n name: projectDetail.name,\n homepage: projectDetail.appSetting.homepage,\n layoutType: projectDetail.appSetting.layoutType,\n theme: projectDetail.appSetting.theme,\n noAuthGuard: projectDetail.appSetting.noAuthGuard,\n locales: projectDetail.appSetting.locales,\n defaultConfig: JSON.parse(projectDetail.appSetting.defaultConfig || \"{}\"),\n menuIcon: JSON.parse(projectDetail.appSetting.icon || \"null\"),\n standaloneMode: true,\n };\n src.file(\n \"app.js\",\n formatJs(`export default ${JSON.stringify(app, null, 2)};`)\n );\n\n const meta = (storyboard.meta ?? {}) as StoryboardMeta & {\n workflows?: unknown;\n userGroups?: unknown;\n };\n const customTemplates = meta.customTemplates ?? [];\n const functions = meta.functions ?? [];\n const menus = meta.menus ?? [];\n const contracts = meta.contracts ?? [];\n const i18n = meta.i18n ?? {};\n delete meta.customTemplates;\n delete meta.functions;\n delete meta.menus;\n delete meta.contracts;\n delete meta.i18n;\n delete meta.workflows;\n delete meta.mocks;\n delete meta.userGroups;\n\n const extractedTemplates = extractTemplates(\n customTemplates,\n [\"components\"],\n extractState\n );\n extractState.extracts.push({\n name: \"index\",\n path: [\"components\"],\n node: extractedTemplates,\n nodeType: \"others\",\n });\n\n const fileStructure = buildFileStructure(extractState.extracts);\n\n src.file(\"index.js\", srcIndexJs);\n\n src.file(\n \"routes.jsx\",\n formatJs(generate(extractedRoutes, \"routes\", [\"routes.jsx\"]))\n );\n\n const resources = src.folder(\"resources\")!;\n\n // Functions\n const fnDir = resources.folder(\"functions\")!;\n const fnNames: string[] = [];\n const fnImports: string[] = [];\n for (const fn of functions) {\n if (fn.name === \"index\") {\n throw new Error('Unexpected function name: \"index\"');\n }\n\n // Prepend with `export default` for functions\n fnGlobalImports = new Set();\n let { code } = transform(fn.source, {\n filename: `expr.${fn.typescript ? \"ts\" : \"js\"}`,\n plugins: [\n ...(fn.typescript ? [\"syntax-typescript\"] : []),\n transformStoryboardFunction,\n ],\n });\n if (fnGlobalImports.size > 0) {\n code = `${[...fnGlobalImports].join(\"\\n\")}\\n\\n${code}`;\n }\n\n fnDir.file(`${fn.name}.${fn.typescript ? \"ts\" : \"js\"}`, code);\n fnImports.push(`import ${fn.name} from \"./${fn.name}.js\";`);\n fnNames.push(fn.name);\n }\n fnDir.file(\n \"index.js\",\n formatJs(\n `${fnImports.join(\"\\n\")}\\n\\nexport default { ${fnNames.join(\",\")} };`\n )\n );\n\n // Menus\n const menusDir = resources.folder(\"menus\")!;\n const menuNames: string[] = [];\n const menuImports: string[] = [];\n for (const menu of menus) {\n cleanMenu(menu);\n if (menu.menuId === \"index\") {\n throw new Error('Unexpected menu id: \"index\"');\n }\n const filename = `${menu.menuId}.js`;\n menusDir.file(\n filename,\n formatJs(generate(menu, \"menu\", [\"resources\", \"menus\", filename]))\n );\n let name = menu.menuId.replace(/^\\d+|[^\\w]+/g, \"_\");\n if (JS_RESERVED_WORDS.has(name)) {\n name = `${name}__2`;\n }\n menuImports.push(`import ${name} from \"./${filename}\";`);\n menuNames.push(name);\n }\n menusDir.file(\n \"index.js\",\n formatJs(\n `${menuImports.join(\"\\n\")}\\n\\nexport default [${menuNames.join(\",\")}]`\n )\n );\n\n // Contracts\n const contractsDir = resources.folder(\"contracts\")!;\n const contractNames: string[] = [];\n const contractImports: string[] = [];\n for (const contract of contracts) {\n if (contract.name === \"index\") {\n throw new Error('Unexpected contract name: \"index\"');\n }\n contractsDir.file(\n `${contract.name}.js`,\n formatJs(`export default ${JSON.stringify(contract)};`)\n );\n const name = contract.name.replace(/^\\d+|[^\\w]+/g, \"_\");\n contractImports.push(`import ${name} from \"./${contract.name}.js\";`);\n contractNames.push(name);\n }\n contractsDir.file(\n \"index.js\",\n formatJs(\n `${contractImports.join(\"\\n\")}\\n\\nexport default [${contractNames.join(\n \",\"\n )}]`\n )\n );\n\n resources\n .folder(\"i18n\")!\n .file(\"index.js\", formatJs(`export default ${JSON.stringify(i18n)};`));\n resources.file(\n \"meta.js\",\n formatJs(`export default ${JSON.stringify(meta, null, 2)};`)\n );\n resources.file(\"index.js\", srcResourcesIndexJs);\n\n generateByFileStructure(fileStructure, src, []);\n\n const appRelativeDir = JSON.stringify(\n `../mock-micro-apps/${projectDetail.appId}`\n );\n\n const scripts = project.folder(\"scripts\")!;\n scripts.file(\n \"build.js\",\n scriptsBuildJs.replaceAll(\"__APP_RELATIVE_DIR__\", appRelativeDir)\n );\n scripts.file(\"babel.js\", scriptsBabelJs);\n scripts.file(\"start.js\", scriptsStartJs);\n scripts.file(\"transpile.js\", scriptsTranspileJs);\n\n const appDir = project\n .folder(\"mock-micro-apps\")!\n .folder(projectDetail.appId)!;\n appDir.file(\".gitignore\", \"*\\n!.gitignore\");\n\n const jsxDir = project.folder(\"jsx\")!;\n jsxDir.file(\"constants.js\", jsxConstantsJs);\n jsxDir.file(\"index.js\", jsxIndexJs);\n jsxDir.file(\"jsx-runtime.js\", jsxJsxRuntimeJs);\n jsxDir.file(\"package.json\", jsxPackageJson);\n jsxDir.file(\"loadStyleText.js\", jsxLoadStyleTextJs);\n jsxDir.file(\"loadFunction.js\", jsxLoadFunctionJs);\n\n project.file(\".editorconfig\", editorConfig);\n project.file(\".gitignore\", gitIgnore);\n project.file(\"babel.config.js\", babelConfigJs);\n project.file(\"declarations.d.ts\", declarationsDTs);\n project.file(\"dev.config.mjs\", devConfigMjs);\n project.file(\"jsconfig.json\", jsconfigJson);\n project.file(\n \"package.json\",\n packageJson.replaceAll(\"__PROJECT_ID__\", projectDetail.appId)\n );\n project.file(\n \"README.md\",\n readmeMd\n .replaceAll(\"__PROJECT_NAME__\", projectDetail.name)\n .replaceAll(\"__PROJECT_HOMEPAGE__\", projectDetail.appSetting.homepage)\n );\n\n const blob = await zip.generateAsync({ type: \"blob\" });\n saveAs(blob, \"project.zip\");\n}\n\ninterface FormatJsOptions {\n typescript?: boolean;\n semi?: boolean;\n printWidth?: number;\n}\n\nfunction formatJs(\n source: string,\n { typescript, semi = true, printWidth }: FormatJsOptions = {}\n): string {\n return format(source, {\n parser: typescript ? \"babel-ts\" : \"babel\",\n plugins: [parserBabel],\n semi,\n printWidth,\n });\n}\n\nfunction generateByFileStructure(\n items: SourceFileOrFolder[],\n folder: JSZip,\n path: string[]\n) {\n for (const item of items) {\n const childPath = [...path, item.name];\n if (item.type === \"folder\") {\n const childFolder = folder.folder(item.name)!;\n generateByFileStructure(item.items, childFolder, childPath);\n } else {\n folder.file(\n `${item.name}.js${\n item.nodeType === \"routes\" ||\n item.nodeType === \"bricks\" ||\n item.nodeType === \"template\"\n ? \"x\"\n : \"\"\n }`,\n formatJs(generate(item.node, item.nodeType, childPath))\n );\n }\n }\n}\n\nfunction cleanMenu(menu: Record<string, any>) {\n for (const [key, value] of Object.entries(menu)) {\n switch (key) {\n case \"items\":\n if (Array.isArray(value)) {\n for (const item of value) {\n cleanMenuItem(item);\n }\n }\n break;\n case \"type\":\n if (value === \"main\") {\n delete menu[key];\n }\n break;\n case \"if\":\n break;\n case \"i18n\":\n if (Object.keys(value).length === 0) {\n delete menu[key];\n }\n break;\n default:\n if (value === null || value === false) {\n delete menu[key];\n }\n }\n }\n}\n\nfunction cleanMenuItem(menuItem: Record<string, any>) {\n for (const [key, value] of Object.entries(menuItem)) {\n switch (key) {\n case \"children\":\n if (Array.isArray(value) && value.length > 0) {\n cleanMenuItem(value);\n }\n break;\n case \"if\":\n break;\n case \"activeExcludes\":\n case \"activeIncludes\":\n if (Array.isArray(value) && value.length === 0) {\n delete menuItem[key];\n }\n break;\n default:\n if (value === null || value === false) {\n delete menuItem[key];\n }\n }\n }\n}\n\ncustomElements.define(\n \"vb-experiment.export-as-source-files\",\n createProviderClass(exportAsSourceFiles)\n);\n"],"names":["fnGlobalImports","transformStoryboardFunction","_exportAsSourceFiles","_asyncToGenerator","_ref","_storyboard$meta","_meta$customTemplates","_meta$functions","_meta$menus","_meta$contracts","_meta$i18n","projectDetail","storyboard","zip","JSZip","project","folder","src","extractState","extracts","namePool","Map","extractedRoutes","extractRoutes","routes","app","id","appId","name","homepage","appSetting","layoutType","theme","noAuthGuard","locales","defaultConfig","JSON","parse","menuIcon","icon","standaloneMode","file","formatJs","concat","stringify","meta","customTemplates","functions","menus","contracts","i18n","workflows","mocks","userGroups","extractedTemplates","extractTemplates","push","path","node","nodeType","fileStructure","buildFileStructure","srcIndexJs","generate","resources","fnDir","fnNames","fnImports","fn","Error","Set","code","transform","source","filename","typescript","plugins","size","join","menusDir","menuNames","menuImports","menu","cleanMenu","menuId","replace","JS_RESERVED_WORDS","has","contractsDir","contractNames","contractImports","contract","srcResourcesIndexJs","generateByFileStructure","appRelativeDir","scripts","scriptsBuildJs","replaceAll","scriptsBabelJs","scriptsStartJs","scriptsTranspileJs","jsxDir","jsxConstantsJs","jsxIndexJs","jsxJsxRuntimeJs","jsxPackageJson","jsxLoadStyleTextJs","jsxLoadFunctionJs","editorConfig","gitIgnore","babelConfigJs","declarationsDTs","devConfigMjs","jsconfigJson","packageJson","readmeMd","blob","generateAsync","type","saveAs","apply","arguments","semi","printWidth","length","undefined","format","parser","parserBabel","items","item","childPath","childFolder","key","value","Object","entries","Array","isArray","cleanMenuItem","keys","menuItem","registerPlugin","visitor","FunctionDeclaration","parent","replaceWith","t","Identifier","add","customElements","define","createProviderClass","_x"],"sourceRoot":""}
@@ -1,2 +0,0 @@
1
- "use strict";(self.webpackChunk_next_bricks_vb_experiment=self.webpackChunk_next_bricks_vb_experiment||[]).push([[732],{6264:(e,n,t)=>{t.r(n),t.d(n,{exportAsSourceFiles:()=>G});var a,r=t(4795),o=t(2019),i=t(1297),s=t.n(i),c=t(6782),l=t(9691),p=t(8483),f=t.n(p),d=t(1483),u=t(7243),m=t(9333),j=t(5738),x=t(2121),g=t(7444),v=t(9082),y=t(4431),h=t(9456),b=t(6689),_=t(9522),k=t(8678),A=t(7768),S=t(9503),w=t(7211),E=t(5125),I=t(9602),O=t(7287),P=t(2524),T=t(2344),J=t(3626),N=t(8223),R=t(7040),C=t(4450),D=t(3870),F=t(4778),M="transform-storyboard-function";function G(e){return U.apply(this,arguments)}function U(){return(U=(0,r.Z)((function*(e){var n,t,r,o,i,l,{projectDetail:p,storyboard:f}=e,d=new(s()),G=d.folder("project"),U=G.folder("src"),B={extracts:[],namePool:new Map},H=(0,m.I$)(f.routes,[],B),K={id:p.appId,name:p.name,homepage:p.appSetting.homepage,layoutType:p.appSetting.layoutType,theme:p.appSetting.theme,noAuthGuard:p.appSetting.noAuthGuard,locales:p.appSetting.locales,defaultConfig:JSON.parse(p.appSetting.defaultConfig||"{}"),menuIcon:JSON.parse(p.appSetting.icon||"null"),standaloneMode:!0};U.file("app.js",W("export default ".concat(JSON.stringify(K,null,2),";")));var V=null!==(n=f.meta)&&void 0!==n?n:{},Z=null!==(t=V.customTemplates)&&void 0!==t?t:[],$=null!==(r=V.functions)&&void 0!==r?r:[],q=null!==(o=V.menus)&&void 0!==o?o:[],Q=null!==(i=V.contracts)&&void 0!==i?i:[],X=null!==(l=V.i18n)&&void 0!==l?l:{};delete V.customTemplates,delete V.functions,delete V.menus,delete V.contracts,delete V.i18n,delete V.workflows,delete V.mocks,delete V.userGroups;var Y=(0,m.LK)(Z,["components"],B);B.extracts.push({name:"index",path:["components"],node:Y,nodeType:"others"});var ee=(0,j.B)(B.extracts);U.file("index.js",I),U.file("routes.jsx",W((0,x.R)(H,"routes",["routes.jsx"])));var ne=U.folder("resources"),te=ne.folder("functions"),ae=[],re=[];for(var oe of $){if("index"===oe.name)throw new Error('Unexpected function name: "index"');a=new Set;var{code:ie}=(0,u.transform)(oe.source,{filename:"expr.".concat(oe.typescript?"ts":"js"),plugins:[...oe.typescript?["syntax-typescript"]:[],M]});a.size>0&&(ie="".concat([...a].join("\n"),"\n\n").concat(ie)),te.file("".concat(oe.name,".").concat(oe.typescript?"ts":"js"),ie),re.push("import ".concat(oe.name,' from "./').concat(oe.name,'.js";')),ae.push(oe.name)}te.file("index.js",W("".concat(re.join("\n"),"\n\nexport default { ").concat(ae.join(",")," };")));var se=ne.folder("menus"),ce=[],le=[];for(var pe of q){if(L(pe),"index"===pe.menuId)throw new Error('Unexpected menu id: "index"');var fe="".concat(pe.menuId,".js");se.file(fe,W((0,x.R)(pe,"menu",["resources","menus",fe])));var de=pe.menuId.replace(/^\d+|[^\w]+/g,"_");F.h8.has(de)&&(de="".concat(de,"__2")),le.push("import ".concat(de,' from "./').concat(fe,'";')),ce.push(de)}se.file("index.js",W("".concat(le.join("\n"),"\n\nexport default [").concat(ce.join(","),"]")));var ue=ne.folder("contracts"),me=[],je=[];for(var xe of Q){if("index"===xe.name)throw new Error('Unexpected contract name: "index"');ue.file("".concat(xe.name,".js"),W("export default ".concat(JSON.stringify(xe),";")));var ge=xe.name.replace(/^\d+|[^\w]+/g,"_");je.push("import ".concat(ge,' from "./').concat(xe.name,'.js";')),me.push(ge)}ue.file("index.js",W("".concat(je.join("\n"),"\n\nexport default [").concat(me.join(","),"]"))),ne.folder("i18n").file("index.js",W("export default ".concat(JSON.stringify(X),";"))),ne.file("meta.js",W("export default ".concat(JSON.stringify(V,null,2),";"))),ne.file("index.js",E),z(ee,U,[]);var ve=JSON.stringify("../mock-micro-apps/".concat(p.appId)),ye=G.folder("scripts");ye.file("build.js",A.replaceAll("__APP_RELATIVE_DIR__",ve)),ye.file("babel.js",k),ye.file("start.js",S),ye.file("transpile.js",w),G.folder("mock-micro-apps").folder(p.appId).file(".gitignore","*\n!.gitignore");var he=G.folder("jsx");he.file("constants.js",g),he.file("index.js",v),he.file("jsx-runtime.js",y),he.file("package.json",h),he.file("loadStyleText.js",b),he.file("loadFunction.js",_),G.file(".editorconfig",O),G.file(".gitignore",P),G.file("babel.config.js",T),G.file("declarations.d.ts",J),G.file("dev.config.mjs",N),G.file("jsconfig.json",C),G.file("package.json",R.replaceAll("__PROJECT_ID__",p.appId)),G.file("README.md",D.replaceAll("__PROJECT_NAME__",p.name).replaceAll("__PROJECT_HOMEPAGE__",p.appSetting.homepage));var be=yield d.generateAsync({type:"blob"});(0,c.saveAs)(be,"project.zip")}))).apply(this,arguments)}function W(e){var{typescript:n,semi:t=!0,printWidth:a}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,l.format)(e,{parser:n?"babel-ts":"babel",plugins:[f()],semi:t,printWidth:a})}function z(e,n,t){for(var a of e){var r=[...t,a.name];if("folder"===a.type){var o=n.folder(a.name);z(a.items,o,r)}else n.file("".concat(a.name,".js").concat("routes"===a.nodeType||"bricks"===a.nodeType||"template"===a.nodeType?"x":""),W((0,x.R)(a.node,a.nodeType,r)))}}function L(e){for(var[n,t]of Object.entries(e))switch(n){case"items":if(Array.isArray(t))for(var a of t)B(a);break;case"type":"main"===t&&delete e[n];break;case"if":break;case"i18n":0===Object.keys(t).length&&delete e[n];break;default:null!==t&&!1!==t||delete e[n]}}function B(e){for(var[n,t]of Object.entries(e))switch(n){case"children":Array.isArray(t)&&t.length>0&&B(t);break;case"if":break;case"activeExcludes":case"activeIncludes":Array.isArray(t)&&0===t.length&&delete e[n];break;default:null!==t&&!1!==t||delete e[n]}}(0,u.registerPlugin)(M,{name:M,visitor:{FunctionDeclaration(e){"Program"===e.parent.type&&e.replaceWith(d.exportDefaultDeclaration(e.node))},Identifier(e){switch(e.node.name){case"FN":a.add('import FN from "./index.js";');break;case"_":a.add('import _ from "lodash";');break;case"moment":a.add('import moment from "moment";');break;case"PIPES":a.add('import { pipes as PIPES } from "@easyops-cn/brick-next-pipes";')}}}}),customElements.define("vb-experiment.export-as-source-files",(0,o.createProviderClass)(G))}}]);
2
- //# sourceMappingURL=export-as-source-files.8198c27a.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chunks/export-as-source-files.8198c27a.js","mappings":"qLAyCIA,E,kVACEC,EAA8B,gCAgD7B,SAAeC,EAAmBC,GAAA,OAAAC,EAAAC,MAAC,KAADC,UAAA,CAsNxC,SAAAF,IAAA,OAAAA,GAAAG,EAAAA,EAAAA,IAtNM,UAAAC,GAGqC,IAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,GAHF,cACxCC,EAAa,WACbC,GACyBR,EACnBS,EAAM,IAAIC,KACVC,EAAUF,EAAIG,OAAO,WACrBC,EAAMF,EAAQC,OAAO,OAErBE,EAA6B,CACjCC,SAAU,GACVC,SAAU,IAAIC,KAEVC,GAAkBC,EAAAA,EAAAA,IAAcX,EAAWY,OAAQ,GAAIN,GAEvDO,EAA0C,CAC9CC,GAAIf,EAAcgB,MAClBC,KAAMjB,EAAciB,KACpBC,SAAUlB,EAAcmB,WAAWD,SACnCE,WAAYpB,EAAcmB,WAAWC,WACrCC,MAAOrB,EAAcmB,WAAWE,MAChCC,YAAatB,EAAcmB,WAAWG,YACtCC,QAASvB,EAAcmB,WAAWI,QAClCC,cAAeC,KAAKC,MAAM1B,EAAcmB,WAAWK,eAAiB,MACpEG,SAAUF,KAAKC,MAAM1B,EAAcmB,WAAWS,MAAQ,QACtDC,gBAAgB,GAElBvB,EAAIwB,KACF,SACAC,EAAS,kBAADC,OAAmBP,KAAKQ,UAAUnB,EAAK,KAAM,GAAE,OAGzD,IAAMoB,EAAuB,QAAnBxC,EAAIO,EAAWiC,YAAI,IAAAxC,EAAAA,EAAI,CAAC,EAI5ByC,EAAsC,QAAvBxC,EAAGuC,EAAKC,uBAAe,IAAAxC,EAAAA,EAAI,GAC1CyC,EAA0B,QAAjBxC,EAAGsC,EAAKE,iBAAS,IAAAx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,EAAKiD,GAItB,CAEA,SAASM,EAAcE,GACrB,IAAK,IAAOR,EAAKC,KAAUC,OAAOC,QAAQK,GACxC,OAAQR,GACN,IAAK,WACCI,MAAMC,QAAQJ,IAAUA,EAAMV,OAAS,GACzCe,EAAcL,GAEhB,MACF,IAAK,KACH,MACF,IAAK,iBACL,IAAK,iBACCG,MAAMC,QAAQJ,IAA2B,IAAjBA,EAAMV,eACzBiB,EAASR,GAElB,MACF,QACgB,OAAVC,IAA4B,IAAVA,UACbO,EAASR,GAI1B,EAtWAS,EAAAA,EAAAA,gBAAe/I,EAA6B,CAC1C+B,KAAM/B,EACNgJ,QAAS,CACPC,oBAAoBrF,GACO,YAArBA,EAAKsF,OAAOzB,MACd7D,EAAKuF,YAAYC,EAAAA,yBAA2BxF,EAAKC,MAErD,EACAwF,WAAWzF,GACT,OAAQA,EAAKC,KAAK9B,MAChB,IAAK,KACHhC,EAAgBuJ,IAAI,gCACpB,MACF,IAAK,IACHvJ,EAAgBuJ,IAAI,2BACpB,MACF,IAAK,SACHvJ,EAAgBuJ,IAAI,gCACpB,MACF,IAAK,QACHvJ,EAAgBuJ,IACd,kEAIR,KA+UJC,eAAeC,OACb,wCACAC,EAAAA,EAAAA,qBAAoBxJ,G","sources":["webpack:///./src/data-providers/export-as-source-files.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport type { Storyboard, MicroApp, StoryboardMeta } from \"@next-core/types\";\nimport { createProviderClass } from \"@next-core/utils/general\";\nimport JSZip from \"jszip\";\nimport { saveAs } from \"file-saver\";\nimport { format } from \"prettier/standalone.js\";\nimport parserBabel from \"prettier/parser-babel.js\";\nimport * as t from \"@babel/types\";\nimport { transform, registerPlugin } from \"@babel/standalone\";\nimport {\n ExtractState,\n extractRoutes,\n extractTemplates,\n} from \"./utils/extract.js\";\nimport {\n SourceFileOrFolder,\n buildFileStructure,\n} from \"./utils/buildFileStructure.js\";\nimport { generate } from \"./utils/generators/generate.js\";\nimport jsxConstantsJs from \"./raws/jsx/constants.js.txt\";\nimport jsxIndexJs from \"./raws/jsx/index.js.txt\";\nimport jsxJsxRuntimeJs from \"./raws/jsx/jsx-runtime.js.txt\";\nimport jsxPackageJson from \"./raws/jsx/package.json.txt\";\nimport jsxLoadStyleTextJs from \"./raws/jsx/loadStyleText.js.txt\";\nimport jsxLoadFunctionJs from \"./raws/jsx/loadFunction.js.txt\";\nimport scriptsBabelJs from \"./raws/scripts/babel.js.txt\";\nimport scriptsBuildJs from \"./raws/scripts/build.js.txt\";\nimport scriptsStartJs from \"./raws/scripts/start.js.txt\";\nimport scriptsTranspileJs from \"./raws/scripts/transpile.js.txt\";\nimport srcResourcesIndexJs from \"./raws/src/resources/index.js.txt\";\nimport srcIndexJs from \"./raws/src/index.js.txt\";\nimport editorConfig from \"./raws/.editorconfig.txt\";\nimport gitIgnore from \"./raws/.gitignore.txt\";\nimport babelConfigJs from \"./raws/babel.config.js.txt\";\nimport declarationsDTs from \"./raws/declarations.d.ts.txt\";\nimport devConfigMjs from \"./raws/dev.config.mjs.txt\";\nimport packageJson from \"./raws/package.json.txt\";\nimport jsconfigJson from \"./raws/jsconfig.json.txt\";\nimport readmeMd from \"./raws/README.md.txt\";\nimport { JS_RESERVED_WORDS } from \"./utils/constants.js\";\n\nlet fnGlobalImports: Set<string>;\nconst transformStoryboardFunction = \"transform-storyboard-function\";\nregisterPlugin(transformStoryboardFunction, {\n name: transformStoryboardFunction,\n visitor: {\n FunctionDeclaration(path) {\n if (path.parent.type === \"Program\") {\n path.replaceWith(t.exportDefaultDeclaration(path.node));\n }\n },\n Identifier(path) {\n switch (path.node.name) {\n case \"FN\":\n fnGlobalImports.add('import FN from \"./index.js\";');\n break;\n case \"_\":\n fnGlobalImports.add('import _ from \"lodash\";');\n break;\n case \"moment\":\n fnGlobalImports.add('import moment from \"moment\";');\n break;\n case \"PIPES\":\n fnGlobalImports.add(\n 'import { pipes as PIPES } from \"@easyops-cn/brick-next-pipes\";'\n );\n break;\n }\n },\n },\n});\n\nexport interface StoryboardAssemblyResult {\n storyboard: Storyboard;\n\n projectDetail: {\n appId: string;\n name: string;\n appSetting: Pick<\n MicroApp,\n \"homepage\" | \"theme\" | \"locales\" | \"noAuthGuard\"\n > & {\n layoutType?: string;\n defaultConfig?: string;\n icon?: string;\n };\n brickNextVersion?: number;\n };\n}\n\nexport async function exportAsSourceFiles({\n projectDetail,\n storyboard,\n}: StoryboardAssemblyResult): Promise<void> {\n const zip = new JSZip();\n const project = zip.folder(\"project\")!;\n const src = project.folder(\"src\")!;\n\n const extractState: ExtractState = {\n extracts: [],\n namePool: new Map(),\n };\n const extractedRoutes = extractRoutes(storyboard.routes, [], extractState);\n\n const app: MicroApp & { layoutType?: string } = {\n id: projectDetail.appId,\n name: projectDetail.name,\n homepage: projectDetail.appSetting.homepage,\n layoutType: projectDetail.appSetting.layoutType,\n theme: projectDetail.appSetting.theme,\n noAuthGuard: projectDetail.appSetting.noAuthGuard,\n locales: projectDetail.appSetting.locales,\n defaultConfig: JSON.parse(projectDetail.appSetting.defaultConfig || \"{}\"),\n menuIcon: JSON.parse(projectDetail.appSetting.icon || \"null\"),\n standaloneMode: true,\n };\n src.file(\n \"app.js\",\n formatJs(`export default ${JSON.stringify(app, null, 2)};`)\n );\n\n const meta = (storyboard.meta ?? {}) as StoryboardMeta & {\n workflows?: unknown;\n userGroups?: unknown;\n };\n const customTemplates = meta.customTemplates ?? [];\n const functions = meta.functions ?? [];\n const menus = meta.menus ?? [];\n const contracts = meta.contracts ?? [];\n const i18n = meta.i18n ?? {};\n delete meta.customTemplates;\n delete meta.functions;\n delete meta.menus;\n delete meta.contracts;\n delete meta.i18n;\n delete meta.workflows;\n delete meta.mocks;\n delete meta.userGroups;\n\n const extractedTemplates = extractTemplates(\n customTemplates,\n [\"components\"],\n extractState\n );\n extractState.extracts.push({\n name: \"index\",\n path: [\"components\"],\n node: extractedTemplates,\n nodeType: \"others\",\n });\n\n const fileStructure = buildFileStructure(extractState.extracts);\n\n src.file(\"index.js\", srcIndexJs);\n\n src.file(\n \"routes.jsx\",\n formatJs(generate(extractedRoutes, \"routes\", [\"routes.jsx\"]))\n );\n\n const resources = src.folder(\"resources\")!;\n\n // Functions\n const fnDir = resources.folder(\"functions\")!;\n const fnNames: string[] = [];\n const fnImports: string[] = [];\n for (const fn of functions) {\n if (fn.name === \"index\") {\n throw new Error('Unexpected function name: \"index\"');\n }\n\n // Prepend with `export default` for functions\n fnGlobalImports = new Set();\n let { code } = transform(fn.source, {\n filename: `expr.${fn.typescript ? \"ts\" : \"js\"}`,\n plugins: [\n ...(fn.typescript ? [\"syntax-typescript\"] : []),\n transformStoryboardFunction,\n ],\n });\n if (fnGlobalImports.size > 0) {\n code = `${[...fnGlobalImports].join(\"\\n\")}\\n\\n${code}`;\n }\n\n fnDir.file(`${fn.name}.${fn.typescript ? \"ts\" : \"js\"}`, code);\n fnImports.push(`import ${fn.name} from \"./${fn.name}.js\";`);\n fnNames.push(fn.name);\n }\n fnDir.file(\n \"index.js\",\n formatJs(\n `${fnImports.join(\"\\n\")}\\n\\nexport default { ${fnNames.join(\",\")} };`\n )\n );\n\n // Menus\n const menusDir = resources.folder(\"menus\")!;\n const menuNames: string[] = [];\n const menuImports: string[] = [];\n for (const menu of menus) {\n cleanMenu(menu);\n if (menu.menuId === \"index\") {\n throw new Error('Unexpected menu id: \"index\"');\n }\n const filename = `${menu.menuId}.js`;\n menusDir.file(\n filename,\n formatJs(generate(menu, \"menu\", [\"resources\", \"menus\", filename]))\n );\n let name = menu.menuId.replace(/^\\d+|[^\\w]+/g, \"_\");\n if (JS_RESERVED_WORDS.has(name)) {\n name = `${name}__2`;\n }\n menuImports.push(`import ${name} from \"./${filename}\";`);\n menuNames.push(name);\n }\n menusDir.file(\n \"index.js\",\n formatJs(\n `${menuImports.join(\"\\n\")}\\n\\nexport default [${menuNames.join(\",\")}]`\n )\n );\n\n // Contracts\n const contractsDir = resources.folder(\"contracts\")!;\n const contractNames: string[] = [];\n const contractImports: string[] = [];\n for (const contract of contracts) {\n if (contract.name === \"index\") {\n throw new Error('Unexpected contract name: \"index\"');\n }\n contractsDir.file(\n `${contract.name}.js`,\n formatJs(`export default ${JSON.stringify(contract)};`)\n );\n const name = contract.name.replace(/^\\d+|[^\\w]+/g, \"_\");\n contractImports.push(`import ${name} from \"./${contract.name}.js\";`);\n contractNames.push(name);\n }\n contractsDir.file(\n \"index.js\",\n formatJs(\n `${contractImports.join(\"\\n\")}\\n\\nexport default [${contractNames.join(\n \",\"\n )}]`\n )\n );\n\n resources\n .folder(\"i18n\")!\n .file(\"index.js\", formatJs(`export default ${JSON.stringify(i18n)};`));\n resources.file(\n \"meta.js\",\n formatJs(`export default ${JSON.stringify(meta, null, 2)};`)\n );\n resources.file(\"index.js\", srcResourcesIndexJs);\n\n generateByFileStructure(fileStructure, src, []);\n\n const appRelativeDir = JSON.stringify(\n `../mock-micro-apps/${projectDetail.appId}`\n );\n\n const scripts = project.folder(\"scripts\")!;\n scripts.file(\n \"build.js\",\n scriptsBuildJs.replaceAll(\"__APP_RELATIVE_DIR__\", appRelativeDir)\n );\n scripts.file(\"babel.js\", scriptsBabelJs);\n scripts.file(\"start.js\", scriptsStartJs);\n scripts.file(\"transpile.js\", scriptsTranspileJs);\n\n const appDir = project\n .folder(\"mock-micro-apps\")!\n .folder(projectDetail.appId)!;\n appDir.file(\".gitignore\", \"*\\n!.gitignore\");\n\n const jsxDir = project.folder(\"jsx\")!;\n jsxDir.file(\"constants.js\", jsxConstantsJs);\n jsxDir.file(\"index.js\", jsxIndexJs);\n jsxDir.file(\"jsx-runtime.js\", jsxJsxRuntimeJs);\n jsxDir.file(\"package.json\", jsxPackageJson);\n jsxDir.file(\"loadStyleText.js\", jsxLoadStyleTextJs);\n jsxDir.file(\"loadFunction.js\", jsxLoadFunctionJs);\n\n project.file(\".editorconfig\", editorConfig);\n project.file(\".gitignore\", gitIgnore);\n project.file(\"babel.config.js\", babelConfigJs);\n project.file(\"declarations.d.ts\", declarationsDTs);\n project.file(\"dev.config.mjs\", devConfigMjs);\n project.file(\"jsconfig.json\", jsconfigJson);\n project.file(\n \"package.json\",\n packageJson.replaceAll(\"__PROJECT_ID__\", projectDetail.appId)\n );\n project.file(\n \"README.md\",\n readmeMd\n .replaceAll(\"__PROJECT_NAME__\", projectDetail.name)\n .replaceAll(\"__PROJECT_HOMEPAGE__\", projectDetail.appSetting.homepage)\n );\n\n const blob = await zip.generateAsync({ type: \"blob\" });\n saveAs(blob, \"project.zip\");\n}\n\ninterface FormatJsOptions {\n typescript?: boolean;\n semi?: boolean;\n printWidth?: number;\n}\n\nfunction formatJs(\n source: string,\n { typescript, semi = true, printWidth }: FormatJsOptions = {}\n): string {\n return format(source, {\n parser: typescript ? \"babel-ts\" : \"babel\",\n plugins: [parserBabel],\n semi,\n printWidth,\n });\n}\n\nfunction generateByFileStructure(\n items: SourceFileOrFolder[],\n folder: JSZip,\n path: string[]\n) {\n for (const item of items) {\n const childPath = [...path, item.name];\n if (item.type === \"folder\") {\n const childFolder = folder.folder(item.name)!;\n generateByFileStructure(item.items, childFolder, childPath);\n } else {\n folder.file(\n `${item.name}.js${\n item.nodeType === \"routes\" ||\n item.nodeType === \"bricks\" ||\n item.nodeType === \"template\"\n ? \"x\"\n : \"\"\n }`,\n formatJs(generate(item.node, item.nodeType, childPath))\n );\n }\n }\n}\n\nfunction cleanMenu(menu: Record<string, any>) {\n for (const [key, value] of Object.entries(menu)) {\n switch (key) {\n case \"items\":\n if (Array.isArray(value)) {\n for (const item of value) {\n cleanMenuItem(item);\n }\n }\n break;\n case \"type\":\n if (value === \"main\") {\n delete menu[key];\n }\n break;\n case \"if\":\n break;\n case \"i18n\":\n if (Object.keys(value).length === 0) {\n delete menu[key];\n }\n break;\n default:\n if (value === null || value === false) {\n delete menu[key];\n }\n }\n }\n}\n\nfunction cleanMenuItem(menuItem: Record<string, any>) {\n for (const [key, value] of Object.entries(menuItem)) {\n switch (key) {\n case \"children\":\n if (Array.isArray(value) && value.length > 0) {\n cleanMenuItem(value);\n }\n break;\n case \"if\":\n break;\n case \"activeExcludes\":\n case \"activeIncludes\":\n if (Array.isArray(value) && value.length === 0) {\n delete menuItem[key];\n }\n break;\n default:\n if (value === null || value === false) {\n delete menuItem[key];\n }\n }\n }\n}\n\ncustomElements.define(\n \"vb-experiment.export-as-source-files\",\n createProviderClass(exportAsSourceFiles)\n);\n"],"names":["fnGlobalImports","transformStoryboardFunction","exportAsSourceFiles","_x","_exportAsSourceFiles","apply","arguments","_asyncToGenerator","_ref","_storyboard$meta","_meta$customTemplates","_meta$functions","_meta$menus","_meta$contracts","_meta$i18n","projectDetail","storyboard","zip","JSZip","project","folder","src","extractState","extracts","namePool","Map","extractedRoutes","extractRoutes","routes","app","id","appId","name","homepage","appSetting","layoutType","theme","noAuthGuard","locales","defaultConfig","JSON","parse","menuIcon","icon","standaloneMode","file","formatJs","concat","stringify","meta","customTemplates","functions","menus","contracts","i18n","workflows","mocks","userGroups","extractedTemplates","extractTemplates","push","path","node","nodeType","fileStructure","buildFileStructure","srcIndexJs","generate","resources","fnDir","fnNames","fnImports","fn","Error","Set","code","transform","source","filename","typescript","plugins","size","join","menusDir","menuNames","menuImports","menu","cleanMenu","menuId","replace","JS_RESERVED_WORDS","has","contractsDir","contractNames","contractImports","contract","srcResourcesIndexJs","generateByFileStructure","appRelativeDir","scripts","scriptsBuildJs","replaceAll","scriptsBabelJs","scriptsStartJs","scriptsTranspileJs","jsxDir","jsxConstantsJs","jsxIndexJs","jsxJsxRuntimeJs","jsxPackageJson","jsxLoadStyleTextJs","jsxLoadFunctionJs","editorConfig","gitIgnore","babelConfigJs","declarationsDTs","devConfigMjs","jsconfigJson","packageJson","readmeMd","blob","generateAsync","type","saveAs","semi","printWidth","length","undefined","format","parser","parserBabel","items","item","childPath","childFolder","key","value","Object","entries","Array","isArray","cleanMenuItem","keys","menuItem","registerPlugin","visitor","FunctionDeclaration","parent","replaceWith","t","Identifier","add","customElements","define","createProviderClass"],"sourceRoot":""}