|
@ -3,6 +3,7 @@ import nfs from 'fs' |
|
|
|
|
|
|
|
|
C = console.log |
|
|
C = console.log |
|
|
def file(path) do np.join (__dirname, path) |
|
|
def file(path) do np.join (__dirname, path) |
|
|
|
|
|
def read(file) do try nfs.readFileSync(file, 'utf-8') |
|
|
|
|
|
|
|
|
def run(steps) |
|
|
def run(steps) |
|
|
for step in steps |
|
|
for step in steps |
|
@ -12,43 +13,62 @@ def run(steps) |
|
|
|
|
|
|
|
|
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 = read configFile |
|
|
return { |
|
|
return { |
|
|
desc: "Adding proRouterViews() plugin to vite.config.js", |
|
|
desc: "Adding proRouterViews() plugin to vite.config.js", |
|
|
run: do |
|
|
run: do |
|
|
if configContent |
|
|
if configContent |
|
|
if /proRouterViews\(\)/.test(configContent) |
|
|
if /proRouterViews\(\)/.test(configContent) |
|
|
return status: true, message: "Plugin already there" |
|
|
return status: true, message: "plugin already there" |
|
|
else |
|
|
else |
|
|
# import pro-router-imba2/views-plugin |
|
|
# import pro-router-imba2/views-plugin |
|
|
nfs.writeFileSync(configFile, configContent.replace("imba()","proRouterViews(), imba()")) |
|
|
nfs.writeFileSync(configFile, configContent.replace("imba()","proRouterViews(), imba()")) |
|
|
return status: true, message: "Config updated" |
|
|
return status: true, message: "config updated" |
|
|
else |
|
|
else |
|
|
return status: false, message: "vite.config.js not found in the project" |
|
|
return status: false, message: "vite.config.js not found in the project" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def generateRouterFile() |
|
|
def generateRouterFile() |
|
|
const destinationFile = file 'src/router.imba' |
|
|
const destinationFile = file 'src/router.imba' |
|
|
const destinationContent = try nfs.readFileSync(destinationFile, 'utf-8') |
|
|
const destinationContent = read destinationFile |
|
|
return { |
|
|
return { |
|
|
desc: "Generating src/router.imba file" |
|
|
desc: "Generating src/router.imba file" |
|
|
run: do |
|
|
run: do |
|
|
if destinationContent |
|
|
if destinationContent |
|
|
if /R\.init/.test(destinationContent) |
|
|
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 |
|
|
const routerContent = nfs.readFileSync(file('node_modules/pro-router-imba2/src/router.imba'), 'utf-8') |
|
|
const routerContent = read file('node_modules/pro-router-imba2/src/router.imba') |
|
|
nfs.writeFileSync(destinationFile, routerContent.replace("./", 'pro-router-imba2')) |
|
|
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' |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def importRouter |
|
|
|
|
|
const indexFile = file 'src/index.js' |
|
|
|
|
|
const indexContent = read indexFile |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
desc: "Adding import definition to src/index.js" |
|
|
|
|
|
run: do |
|
|
|
|
|
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 |
|
|
|
|
|
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" |
|
|
if process.argv.slice(2) == "init" |
|
|
run([addProRouterViewsPlugin(), generateRouterFile()]) |
|
|
run([addProRouterViewsPlugin(), generateRouterFile(), importRouter()]) |
|
|
else |
|
|
else |
|
|
C("For initial configuration of pro router use command: pro-router init") |
|
|
C("For initial configuration of pro router use command: pro-router init") |