Browse Source

should work prototype of pro-router init; to be tested later; fix exporting helpers

master
Marek Piasecki 2 years ago
parent
commit
b65fa7bcc9
  1. 16
      bin/pro-router.imba
  2. 2
      src/helpers.imba

16
bin/pro-router.imba

@ -11,7 +11,7 @@ def run(steps)
C "[ {result.status ? "OK" : "FAILED"} ] {result.message}" C "[ {result.status ? "OK" : "FAILED"} ] {result.message}"
def addProRouterViewsPlugin() def addProRouterViewsPlugin()
const configFile = file "./vite.config.js" const configFile = file "vite.config.js"
const configContent = try nfs.readFileSync(configFile, 'utf-8') const configContent = try nfs.readFileSync(configFile, 'utf-8')
return { return {
desc: "Adding proRouterViews() plugin to vite.config.js", desc: "Adding proRouterViews() plugin to vite.config.js",
@ -28,26 +28,26 @@ def addProRouterViewsPlugin()
} }
def generateRouterFile() def generateRouterFile()
const routerFile = file './src/router.imba' const destinationFile = file 'src/router.imba'
const routerContent = try nfs.readFileSync(routerFile, 'utf-8') const destinationContent = try nfs.readFileSync(destinationFile, 'utf-8')
return { return {
desc: "Generating src/router.imba file" desc: "Generating src/router.imba file"
run: do run: do
if routerContent if destinationContent
if /R\.init/.test(routerContent) if /R\.init/.test(destinationContent)
return status: true, message: "router seems to be ALREADY on place" return status: true, message: "router seems to be ALREADY on place"
else else
return status: false, message: "file already exist" return status: false, message: "file already exist"
else else
try try
nfs.cp source: './node_modules/pro-router-imba2/src/router.imba', destination: './src/' 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" return status: true, message: "generated successfuly"
catch catch
return status: false, message: 'unable to copy router.imba template' return status: false, message: 'unable to copy router.imba template'
} }
C nfs
if process.argv.slice(2) == "init" if process.argv.slice(2) == "init"
run([addProRouterViewsPlugin(), generateRouterFile()]) run([addProRouterViewsPlugin(), generateRouterFile()])
else else

2
src/helpers.imba

@ -6,7 +6,7 @@ import reject from 'lodash.reject'
import toPairs from 'lodash.topairs' import toPairs from 'lodash.topairs'
import flatten from 'lodash.flatten' import flatten from 'lodash.flatten'
export helpers = { export const helpers = {
compact: compact compact: compact
fromPairs: fromPairs fromPairs: fromPairs
chunk: chunk chunk: chunk

Loading…
Cancel
Save