You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB

import np from 'path'
import nfs from 'fs'
C = console.log
def file(path) do np.join (__dirname, path)
def run(steps)
for step in steps
C step.desc
let result = step.run!
C "[ {result.status ? "OK" : "FAILED"} ] {result.message}"
def addProRouterViewsPlugin()
const configFile = file "./vite.config.js"
const configContent = try nfs.readFileSync(configFile, 'utf-8')
return {
desc: "Adding proRouterViews() plugin to vite.config.js",
run: do
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"
}
def generateRouterFile()
const routerFile = file './src/router.imba'
const routerContent = try nfs.readFileSync(routerFile, 'utf-8')
return {
desc: "Generating src/router.imba file"
run: do
if routerContent
if /R\.init/.test(routerContent)
return status: true, message: "router seems to be ALREADY on place"
else
return status: false, message: "file already exist"
else
try
nfs.cp source: './node_modules/pro-router-imba2/src/router.imba', destination: './src/'
return status: true, message: "generated successfuly"
catch
return status: false, message: 'unable to copy router.imba template'
}
C nfs
if process.argv.slice(2) == "init"
run([addProRouterViewsPlugin(), generateRouterFile()])
else
C("For initial configuration of pro router use command: pro-router init")