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.9 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 destinationFile = file 'src/router.imba'
const destinationContent = try nfs.readFileSync(destinationFile, 'utf-8')
return {
desc: "Generating src/router.imba file"
run: do
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 = nfs.readFileSync(file('node_modules/pro-router-imba2/src/router.imba'), 'utf-8')
nfs.writeFileSync(destinationFile, routerContent.replace("./", 'pro-router-imba2'))
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'
}
if process.argv.slice(2) == "init"
run([addProRouterViewsPlugin(), generateRouterFile()])
else
C("For initial configuration of pro router use command: pro-router init")