Browse Source

tweak everything to work again using self package

master
Marek Piasecki 2 years ago
parent
commit
e00fde3412
  1. 10
      bin/pro-router.js
  2. 11
      index.html
  3. 9
      package.json
  4. 2
      site/index.html
  5. 2310
      site/package-lock.json
  6. 2
      site/package.json
  7. 13
      site/src/router.imba
  8. 1
      site/vite.config.js
  9. 5
      src/router.imba
  10. 8
      src/vite-plugin.js

10
bin/pro-router.js

@ -4,7 +4,7 @@ var np = require('path');
var nfs = require('fs');
function file(path){
np.join(require.main.filename, path);
return np.resolve(process.cwd(), path);
};
function read(file){
try {
@ -26,7 +26,6 @@ function run(steps){
};
function addProRouterViewsPlugin(){
const configFile = file("vite.config.js");
const configContent = read(configFile);
return {
@ -40,8 +39,7 @@ function addProRouterViewsPlugin(){
return {status: true,message: "plugin already there"};
} else {
// import pro-router-imba2/views-plugin
nfs.writeFileSync(configFile,configContent.replace("imba()","proRouterViews(), imba()"));
nfs.writeFileSync(configFile,"import proRouterViews from 'pro-router-imba2/vite-plugin'\n" + configContent.replace("imba()","proRouterViews(), imba()"));
return {status: true,message: "config updated"};
};
} else {
@ -72,9 +70,8 @@ function generateRouterFile(){
} else {
try {
const routerContent = read(file('node_modules/pro-router-imba2/src/router.imba'));
nfs.writeFileSync(destinationFile,routerContent.replace("./",'pro-router-imba2'));
nfs.writeFileSync(destinationFile,routerContent);
return {status: true,message: "generated successfuly"};
} catch ($5) {
@ -139,7 +136,6 @@ function importRouter(){
};
if (process.argv.slice(2) == "init") {
run([addProRouterViewsPlugin(),generateRouterFile(),initializeViewsFile(),importRouter()]);
} else {

11
index.html

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Imba Module</title>
</head>
<body>
<script type="module" src="/src/index.js"></script>
</body>
</html>

9
package.json

@ -6,12 +6,11 @@
"bin",
"src"
],
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"main": "./src/router_tag.imba",
"exports": {
"helpers": "./src/helpers.imba",
"router_tags": "./src/router_tag.imba",
"vite-plugin": "./src/vite-plugin.js"
".": "./src/router_tag.imba",
"./helpers": "./src/helpers.imba",
"./vite-plugin": "./src/vite-plugin.js"
},
"bin": {
"pro-router": "./bin/pro-router"

2
site/index.html

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Imba Vite Template</title>
<title>Pro Router Imba2 integration</title>
</head>
<body>
<script type="module" src="/src/index.js"></script>

2310
site/package-lock.json

File diff suppressed because it is too large

2
site/package.json

@ -14,6 +14,6 @@
"vite-plugin-imba": "^0.10.1"
},
"dependencies": {
"pro-router-imba2": "^1.0.1"
"pro-router-imba2": "^1.0.3"
}
}

13
site/src/router.imba

@ -0,0 +1,13 @@
import "pro-router/standalone" # standalone operates on "/#/" hash style url; for regular "/" url use: "pro-router/router"
import "pro-router-imba2"
import { helpers } from "pro-router-imba2/helpers"
import views from "./views.json"
R.init helpers: helpers, views: views, root: 'home', render: imba.commit
tag view-home
<self><h1> 'Imba2 on Pro Router is working...'
tag view-not_found
<self><h1> "Page not found :("

1
site/vite.config.js

@ -1,3 +1,4 @@
import proRouterViews from 'pro-router-imba2/vite-plugin'
import { imba } from 'vite-plugin-imba';
import { defineConfig } from 'vite';

5
src/router.imba

@ -1,7 +1,8 @@
import "pro-router/standalone" # standalone operates on "/#/" hash style url; for regular "/" url use: "pro-router/router"
import "./router_tag.imba"
import "pro-router-imba2"
import { helpers } from "pro-router-imba2/helpers"
import views from "./views.json"
import { helpers } from "./helpers.imba"
R.init helpers: helpers, views: views, root: 'home', render: imba.commit

8
src/vite-plugin.js

@ -1,7 +1,7 @@
import np from 'path'
import nfs from 'fs'
let np = require('path')
let nfs = require('fs')
function file() { return np.join(__dirname, '../src/views.json') }
function file() { return np.resolve(process.cwd(), 'src/views.json') }
let viewsList = []
let viewPaths = {} // view: [path]
@ -9,7 +9,7 @@ let pathViews = {} // path: [view]
function duplicate(obj){ return JSON.parse(JSON.stringify(obj)) }
function without(el, arr) { return arr.filter(function(e){ if(e != el) { return e } }) }
export function proRouterViews() {
module.exports = function proRouterViews() {
return {
name: 'pro-router-views',
transformIndexHtml(html) {

Loading…
Cancel
Save