diff --git a/bin/pro-router b/bin/pro-router index 6519eeb..10571b1 100644 --- a/bin/pro-router +++ b/bin/pro-router @@ -1,4 +1,2 @@ #!/usr/bin/env node -var path = require('path') -var fs = require('fs'); -require(path.join(path.dirname(fs.realpathSync(__filename)), '../dist/index3')); \ No newline at end of file +require('./pro-router.js'); \ No newline at end of file diff --git a/bin/pro-router.imba b/bin/pro-router.imba deleted file mode 100644 index c050fa3..0000000 --- a/bin/pro-router.imba +++ /dev/null @@ -1,87 +0,0 @@ -import np from 'path' -import nfs from 'fs' - -C = console.log -def file(path) do np.join (__dirname, path) -def read(file) do try nfs.readFileSync(file, 'utf-8') - -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 = read configFile - 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 = read destinationFile - 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 = 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 - return status: false, message: 'unable to copy router.imba template' - } -def initializeViewsFile() - const path = 'src/views.json' - const viewsFile = file path - - return { - desc: "Initializing views list file - src/views.json" - run: do - if nfs.existsSync(path) - return status: true, message: ["file already exists"] - else - nfs.writeFileSync viewsFile, "[]" - return status: true, message: ["initialized successfuly"] - } - -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" - run([addProRouterViewsPlugin(), generateRouterFile(), initializeViewsFile(), importRouter()]) -else - C("For initial configuration of pro router use command: pro-router init") \ No newline at end of file diff --git a/bin/pro-router.js b/bin/pro-router.js new file mode 100644 index 0000000..c3e7775 --- /dev/null +++ b/bin/pro-router.js @@ -0,0 +1,147 @@ +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"); +}; diff --git a/package.json b/package.json index c257318..7707f6c 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { "name": "pro-router-imba2", "version": "1.0.1", - "type": "module", + "type": "commonjs", "files": [ - "dist" + "bin", + "src" ], "main": "./dist/index.umd.cjs", "module": "./dist/index.js", "exports": { - ".": { - "import": "./dist/index.js", - "require": "./dist/index.umd.cjs" - } + "helpers": "./src/helpers.imba", + "router_tags": "./src/router_tag.imba", + "vite-plugin": "./src/vite-plugin.js" }, "bin": { "pro-router": "./bin/pro-router" diff --git a/readme.md b/readme.md index 3722650..66a06f1 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,3 @@ -# Module Template +# pro-router-imba2 -See https://github.com/imba/imba.io/pull/255 for most up-to-date usage guide. +Integration of pro-router and Imba2. More information here http://imba-router.maniak.pro. \ No newline at end of file diff --git a/site/package-lock.json b/site/package-lock.json index c67e246..4d92ce7 100644 --- a/site/package-lock.json +++ b/site/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "site", "version": "0.0.0", + "dependencies": { + "pro-router-imba2": "^1.0.1" + }, "devDependencies": { "imba": "^2.0.0-alpha.226", "vite": "^3.2.5", @@ -2143,6 +2146,41 @@ "dev": true, "peer": true }, + "node_modules/lodash.chunk": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", + "integrity": "sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w==" + }, + "node_modules/lodash.compact": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash.compact/-/lodash.compact-3.0.1.tgz", + "integrity": "sha512-2ozeiPi+5eBXW1CLtzjk8XQFhQOEMwwfxblqeq6EGyTxZJ1bPATqilY0e6g2SLQpP4KuMeuioBhEnWz5Pr7ICQ==" + }, + "node_modules/lodash.flatten": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==" + }, + "node_modules/lodash.frompairs": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz", + "integrity": "sha512-dvqe2I+cO5MzXCMhUnfYFa9MD+/760yx2aTAN1lqEcEkf896TxgrX373igVdqSJj6tQd0jnSLE1UMuKufqqxFw==" + }, + "node_modules/lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "node_modules/lodash.reject": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.reject/-/lodash.reject-4.6.0.tgz", + "integrity": "sha512-qkTuvgEzYdyhiJBx42YPzPo71R1aEr0z79kAv7Ixg8wPFEjgRgJdUsGMG3Hf3OYSF/kHI79XhNlt+5Ar6OzwxQ==" + }, + "node_modules/lodash.topairs": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.topairs/-/lodash.topairs-4.3.0.tgz", + "integrity": "sha512-qrRMbykBSEGdOgQLJJqVSdPWMD7Q+GJJ5jMRfQYb+LTLsw3tYVIabnCzRqTJb2WTo17PG5gNzXuFaZgYH/9SAQ==" + }, "node_modules/loupe": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", @@ -2504,6 +2542,29 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/pro-router": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/pro-router/-/pro-router-4.3.2.tgz", + "integrity": "sha512-S1qvuUwg5dLegfMIt3tFxW2jMhMFgZP0YqoHLdOlggrQYIhbzgpzUsoKqQ6kQ6vRD3kiS+H6NaQt/Ve0fpm4yQ==" + }, + "node_modules/pro-router-imba2": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pro-router-imba2/-/pro-router-imba2-1.0.1.tgz", + "integrity": "sha512-UtgCyHYk8SAupzi/tiKd4UDUV/Mud9kgQ3l/8oW3VBhy97L5Jf2xTCcUHgfXDBJinwurJHKahpXgp72Q90vo4A==", + "dependencies": { + "lodash.chunk": "^4.2.0", + "lodash.compact": "^3.0.1", + "lodash.flatten": "^4.4.0", + "lodash.frompairs": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.reject": "^4.6.0", + "lodash.topairs": "^4.3.0", + "pro-router": "^4.3.2" + }, + "bin": { + "pro-router": "bin/pro-router" + } + }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -4628,6 +4689,41 @@ "dev": true, "peer": true }, + "lodash.chunk": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lodash.chunk/-/lodash.chunk-4.2.0.tgz", + "integrity": "sha512-ZzydJKfUHJwHa+hF5X66zLFCBrWn5GeF28OHEr4WVWtNDXlQ/IjWKPBiikqKo2ne0+v6JgCgJ0GzJp8k8bHC7w==" + }, + "lodash.compact": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/lodash.compact/-/lodash.compact-3.0.1.tgz", + "integrity": "sha512-2ozeiPi+5eBXW1CLtzjk8XQFhQOEMwwfxblqeq6EGyTxZJ1bPATqilY0e6g2SLQpP4KuMeuioBhEnWz5Pr7ICQ==" + }, + "lodash.flatten": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==" + }, + "lodash.frompairs": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/lodash.frompairs/-/lodash.frompairs-4.0.1.tgz", + "integrity": "sha512-dvqe2I+cO5MzXCMhUnfYFa9MD+/760yx2aTAN1lqEcEkf896TxgrX373igVdqSJj6tQd0jnSLE1UMuKufqqxFw==" + }, + "lodash.includes": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", + "integrity": "sha512-W3Bx6mdkRTGtlJISOvVD/lbqjTlPPUDTMnlXZFnVwi9NKJ6tiAk6LVdlhZMm17VZisqhKcgzpO5Wz91PCt5b0w==" + }, + "lodash.reject": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/lodash.reject/-/lodash.reject-4.6.0.tgz", + "integrity": "sha512-qkTuvgEzYdyhiJBx42YPzPo71R1aEr0z79kAv7Ixg8wPFEjgRgJdUsGMG3Hf3OYSF/kHI79XhNlt+5Ar6OzwxQ==" + }, + "lodash.topairs": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.topairs/-/lodash.topairs-4.3.0.tgz", + "integrity": "sha512-qrRMbykBSEGdOgQLJJqVSdPWMD7Q+GJJ5jMRfQYb+LTLsw3tYVIabnCzRqTJb2WTo17PG5gNzXuFaZgYH/9SAQ==" + }, "loupe": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.6.tgz", @@ -4895,6 +4991,26 @@ } } }, + "pro-router": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/pro-router/-/pro-router-4.3.2.tgz", + "integrity": "sha512-S1qvuUwg5dLegfMIt3tFxW2jMhMFgZP0YqoHLdOlggrQYIhbzgpzUsoKqQ6kQ6vRD3kiS+H6NaQt/Ve0fpm4yQ==" + }, + "pro-router-imba2": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pro-router-imba2/-/pro-router-imba2-1.0.1.tgz", + "integrity": "sha512-UtgCyHYk8SAupzi/tiKd4UDUV/Mud9kgQ3l/8oW3VBhy97L5Jf2xTCcUHgfXDBJinwurJHKahpXgp72Q90vo4A==", + "requires": { + "lodash.chunk": "^4.2.0", + "lodash.compact": "^3.0.1", + "lodash.flatten": "^4.4.0", + "lodash.frompairs": "^4.0.1", + "lodash.includes": "^4.3.0", + "lodash.reject": "^4.6.0", + "lodash.topairs": "^4.3.0", + "pro-router": "^4.3.2" + } + }, "prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", diff --git a/site/package.json b/site/package.json index 9c3ae44..5dd1368 100644 --- a/site/package.json +++ b/site/package.json @@ -12,5 +12,8 @@ "imba": "^2.0.0-alpha.226", "vite": "^3.2.5", "vite-plugin-imba": "^0.10.1" + }, + "dependencies": { + "pro-router-imba2": "^1.0.1" } } diff --git a/site/vite.config.js b/site/vite.config.js index 06e3bdf..0855a35 100644 --- a/site/vite.config.js +++ b/site/vite.config.js @@ -3,5 +3,5 @@ import { defineConfig } from 'vite'; export default defineConfig({ base: '', - plugins: [imba()], + plugins: [proRouterViews(), imba()], }); diff --git a/vite.config.js b/vite.config.js deleted file mode 100644 index dec371a..0000000 --- a/vite.config.js +++ /dev/null @@ -1,17 +0,0 @@ -import { imba } from 'vite-plugin-imba'; -import { resolve } from 'path' -import { defineConfig } from 'vite'; -import { name } from './package.json' - -export default defineConfig({ - plugins: [imba()], - build: { - lib: { - name: name, - fileName: "index", - entry: [resolve(__dirname, 'src/router_tag.imba'), - resolve(__dirname, 'src/vite-plugin.js'), - resolve(__dirname, 'bin/pro-router.imba')] - } - }, -}); \ No newline at end of file