function iter$__(a){ let v; return a ? ((v=a.toIterable) ? v.call(a) : a) : a; }; var np = require('path'); var nfs = require('fs'); function file(path){ return console.log(np.join(__dirname, path)); }; function read(file){ try { return nfs.readFileSync(file,'utf-8'); } catch (e) { }; }; function run(steps){ var $1; $1 = []; for (let $2 = 0, $3 = iter$__(steps), $4 = $3.length; $2 < $4; $2++) { let step = $3[$2]; console.log(step.desc); let result = step.run(); $1.push(console.log(("[ " + (result.status ? "OK" : "FAILED") + " ] " + (result.message)))); }; return $1; }; function addProRouterViewsPlugin(){ const configFile = file("vite.config.js"); const configContent = read(configFile); return { desc: "Adding proRouterViews() plugin to vite.config.js", run: function() { if (configContent) { if (/proRouterViews\(\)/.test(configContent)) { return {status: true,message: "plugin already there"}; } else { // import pro-router-imba2/views-plugin nfs.writeFileSync(configFile,configContent.replace("imba()","proRouterViews(), imba()")); return {status: true,message: "config updated"}; }; } else { return {status: false,message: "vite.config.js not found in the project"}; }; } }; }; function generateRouterFile(){ const destinationFile = file('src/router.imba'); const destinationContent = read(destinationFile); return { desc: "Generating src/router.imba file", run: function() { if (destinationContent) { if (/R\.init/.test(destinationContent)) { return {status: true,message: "router SEEMS to be already on place"}; } else { return {status: false,message: "file already exist"}; }; } else { try { const routerContent = read(file('node_modules/pro-router-imba2/src/router.imba')); nfs.writeFileSync(destinationFile,routerContent.replace("./",'pro-router-imba2')); return {status: true,message: "generated successfuly"}; } catch ($5) { return {status: false,message: 'unable to copy router.imba template'}; }; }; } }; }; function initializeViewsFile(){ const path = 'src/views.json'; const viewsFile = file(path); return { desc: "Initializing views list file - src/views.json", run: function() { if (nfs.existsSync(path)) { return {status: true,message: ["file already exists"]}; } else { nfs.writeFileSync(viewsFile,"[]"); return {status: true,message: ["initialized successfuly"]}; }; } }; }; function importRouter(){ const indexFile = file('src/index.js'); const indexContent = read(indexFile); return { desc: "Adding import definition to src/index.js", run: function() { if (indexContent) { if (/import '\.\/router\.imba'/.test(indexContent)) { return {status: true,message: "import definition already there"}; } else { try { nfs.writeFileSync(indexFile,"import './router.imba'\n" + indexContent); return {status: true,message: "definition added successfuly"}; } catch ($6) { return {status: false,message: "failed during writing to file"}; }; }; } else { return {status: false,message: 'no such file or directory'}; }; } }; }; if (process.argv.slice(2) == "init") { run([addProRouterViewsPlugin(),generateRouterFile(),initializeViewsFile(),importRouter()]); } else { console.log("For initial configuration of pro router use command: pro-router init"); };