nativescript-web-adapter 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/core/components/ActionBar.vue +1 -1
- package/dist/nativescript-web-adapter.es.js +11 -11
- package/dist/nativescript-web-adapter.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/tools/cli.cjs +19 -5
- package/tools/create-nuxt-platform.cjs +57 -0
- package/tools/create-web-platform.cjs +5 -5
- package/tools/modules/templates-nuxt.cjs +63 -0
- package/tools/modules/transform-nuxt.cjs +59 -0
package/README.md
CHANGED
|
@@ -11,18 +11,22 @@ This project is a “web adapter” for NativeScript‑Vue‑Vite. It can transf
|
|
|
11
11
|
|
|
12
12
|
## Quick Start
|
|
13
13
|
|
|
14
|
-
Temporarily add the local bin to `PATH` to make the `ns-web` command available:
|
|
15
|
-
|
|
16
14
|
```bash
|
|
17
|
-
|
|
15
|
+
npm install nativescript-web-adapter
|
|
18
16
|
```
|
|
19
17
|
|
|
20
18
|
Compile the web template – install dependencies – start the web project's dev server:
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
vue
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx ns-web vue
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
nuxt
|
|
23
27
|
|
|
24
28
|
```bash
|
|
25
|
-
ns-web
|
|
29
|
+
npx ns-web nuxt
|
|
26
30
|
```
|
|
27
31
|
|
|
28
32
|
iOS
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { defineComponent as r, createElementBlock as s, openBlock as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as r, createElementBlock as s, openBlock as a, renderSlot as c, ref as u } from "vue";
|
|
2
|
+
const p = { class: "ns-actionbar" }, d = /* @__PURE__ */ r({
|
|
3
3
|
name: "ActionBar",
|
|
4
4
|
__name: "ActionBar",
|
|
5
5
|
setup(e) {
|
|
6
|
-
return (t, o) => (
|
|
7
|
-
|
|
6
|
+
return (t, o) => (a(), s("header", p, [
|
|
7
|
+
c(t.$slots, "default", {}, void 0, !0)
|
|
8
8
|
]));
|
|
9
9
|
}
|
|
10
10
|
}), _ = (e, t) => {
|
|
11
11
|
const o = e.__vccOpts || e;
|
|
12
|
-
for (const [n,
|
|
13
|
-
o[n] =
|
|
12
|
+
for (const [n, f] of t)
|
|
13
|
+
o[n] = f;
|
|
14
14
|
return o;
|
|
15
|
-
}, m = /* @__PURE__ */ _(
|
|
15
|
+
}, m = /* @__PURE__ */ _(d, [["__scopeId", "data-v-f3af35bf"]]), v = { class: "ns-page" }, b = /* @__PURE__ */ r({
|
|
16
16
|
name: "Page",
|
|
17
17
|
__name: "Page",
|
|
18
18
|
setup(e) {
|
|
19
|
-
return (t, o) => (
|
|
20
|
-
|
|
19
|
+
return (t, o) => (a(), s("div", v, [
|
|
20
|
+
c(t.$slots, "default", {}, void 0, !0)
|
|
21
21
|
]));
|
|
22
22
|
}
|
|
23
23
|
}), g = /* @__PURE__ */ _(b, [["__scopeId", "data-v-87719fa5"]]), h = { class: "ns-frame" }, $ = /* @__PURE__ */ r({
|
|
24
24
|
name: "Frame",
|
|
25
25
|
__name: "Frame",
|
|
26
26
|
setup(e) {
|
|
27
|
-
return (t, o) => (
|
|
28
|
-
|
|
27
|
+
return (t, o) => (a(), s("div", h, [
|
|
28
|
+
c(t.$slots, "default", {}, void 0, !0)
|
|
29
29
|
]));
|
|
30
30
|
}
|
|
31
31
|
}), O = /* @__PURE__ */ _($, [["__scopeId", "data-v-a66356e7"]]), i = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.NativeScriptWebAdapter={},r.Vue))})(this,function(r,e){"use strict";const l={class:"ns-actionbar"},_=e.defineComponent({name:"ActionBar",__name:"ActionBar",setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("header",l,[e.renderSlot(n.$slots,"default",{},void 0,!0)]))}}),c=(t,n)=>{const o=t.__vccOpts||t;for(const[s,$]of n)o[s]=$;return o},u=c(_,[["__scopeId","data-v-
|
|
1
|
+
(function(r,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(r=typeof globalThis<"u"?globalThis:r||self,e(r.NativeScriptWebAdapter={},r.Vue))})(this,function(r,e){"use strict";const l={class:"ns-actionbar"},_=e.defineComponent({name:"ActionBar",__name:"ActionBar",setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("header",l,[e.renderSlot(n.$slots,"default",{},void 0,!0)]))}}),c=(t,n)=>{const o=t.__vccOpts||t;for(const[s,$]of n)o[s]=$;return o},u=c(_,[["__scopeId","data-v-f3af35bf"]]),f={class:"ns-page"},d=c(e.defineComponent({name:"Page",__name:"Page",setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("div",f,[e.renderSlot(n.$slots,"default",{},void 0,!0)]))}}),[["__scopeId","data-v-87719fa5"]]),p={class:"ns-frame"},a=Object.freeze(Object.defineProperty({__proto__:null,ActionBar:u,Frame:c(e.defineComponent({name:"Frame",__name:"Frame",setup(t){return(n,o)=>(e.openBlock(),e.createElementBlock("div",p,[e.renderSlot(n.$slots,"default",{},void 0,!0)]))}}),[["__scopeId","data-v-a66356e7"]]),Page:d},Symbol.toStringTag,{value:"Module"}));function m(){const t=e.ref("");function n(o){t.value=o}return{title:t,setTitle:n}}function b(){const t=e.ref(!0);function n(){t.value=!0}function o(){t.value=!1}return{isVisible:t,show:n,hide:o}}function g(){const t=e.ref([]);function n(s){t.value.push(s)}function o(){return t.value.pop()}return{stack:t,push:n,pop:o}}const i=Object.freeze(Object.defineProperty({__proto__:null,useActionBar:m,useFrame:g,usePage:b},Symbol.toStringTag,{value:"Module"})),h=Object.freeze(Object.defineProperty({__proto__:null,components:a,composables:i},Symbol.toStringTag,{value:"Module"})),S={install(t){Object.entries(a||{}).forEach(([n,o])=>{t.component(n,o)}),t.config.globalProperties.$ns=i||{}}};r.core=h,r.default=S,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.ns-actionbar[data-v-
|
|
1
|
+
.ns-actionbar[data-v-f3af35bf]{padding:12px}.ns-page[data-v-87719fa5]{top:0;left:0;position:absolute;width:100%;min-height:100%;padding:0}
|
package/package.json
CHANGED
package/tools/cli.cjs
CHANGED
|
@@ -18,11 +18,11 @@ program
|
|
|
18
18
|
|
|
19
19
|
program
|
|
20
20
|
.command('build')
|
|
21
|
-
.description('生成
|
|
21
|
+
.description('生成 Vue 平台并在 platforms/vue 内构建')
|
|
22
22
|
.option('--skip-install', '跳过依赖安装')
|
|
23
23
|
.action(async (opts) => {
|
|
24
24
|
await createWebPlatform();
|
|
25
|
-
const webDir = path.join(process.cwd(), 'platforms', '
|
|
25
|
+
const webDir = path.join(process.cwd(), 'platforms', 'vue');
|
|
26
26
|
if (!opts.skipInstall) {
|
|
27
27
|
execSync('npm install', { stdio: 'inherit', cwd: webDir });
|
|
28
28
|
}
|
|
@@ -30,16 +30,30 @@ program
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
program
|
|
33
|
-
.command('
|
|
34
|
-
.description('生成
|
|
33
|
+
.command('vue')
|
|
34
|
+
.description('生成 Vue 平台并在 platforms/vue 内启动开发服务器')
|
|
35
35
|
.option('--skip-install', '跳过依赖安装')
|
|
36
36
|
.action(async (opts) => {
|
|
37
37
|
await createWebPlatform();
|
|
38
|
-
const webDir = path.join(process.cwd(), 'platforms', '
|
|
38
|
+
const webDir = path.join(process.cwd(), 'platforms', 'vue');
|
|
39
39
|
if (!opts.skipInstall) {
|
|
40
40
|
execSync('npm install', { stdio: 'inherit', cwd: webDir });
|
|
41
41
|
}
|
|
42
42
|
execSync('npm run dev', { stdio: 'inherit', cwd: webDir });
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
program
|
|
46
|
+
.command('nuxt')
|
|
47
|
+
.description('生成 Nuxt 平台并在 platforms/nuxt 内执行构建')
|
|
48
|
+
.option('--skip-install', '跳过依赖安装')
|
|
49
|
+
.action(async (opts) => {
|
|
50
|
+
const { createNuxtPlatform } = require('./create-nuxt-platform.cjs');
|
|
51
|
+
await createNuxtPlatform();
|
|
52
|
+
const nuxtDir = path.join(process.cwd(), 'platforms', 'nuxt');
|
|
53
|
+
if (!opts.skipInstall) {
|
|
54
|
+
execSync('npm install', { stdio: 'inherit', cwd: nuxtDir });
|
|
55
|
+
}
|
|
56
|
+
execSync('npm run build', { stdio: 'inherit', cwd: nuxtDir });
|
|
57
|
+
});
|
|
58
|
+
|
|
45
59
|
program.parse();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const copy = require('./modules/copy.cjs');
|
|
4
|
+
const transformNuxt = require('./modules/transform-nuxt.cjs');
|
|
5
|
+
const templatesNuxt = require('./modules/templates-nuxt.cjs');
|
|
6
|
+
|
|
7
|
+
function createNuxtPlatform(options = {}) {
|
|
8
|
+
const adapterDir = path.resolve(__dirname, '..');
|
|
9
|
+
const projectRoot = options.projectRoot ? path.resolve(options.projectRoot) : process.cwd();
|
|
10
|
+
const platformsDir = path.join(projectRoot, 'platforms');
|
|
11
|
+
const nuxtDir = path.join(platformsDir, 'nuxt');
|
|
12
|
+
const srcDir = path.join(projectRoot, 'src');
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(nuxtDir)) {
|
|
15
|
+
fs.mkdirSync(nuxtDir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const adapterComponentsDir = path.join(adapterDir, 'core', 'components');
|
|
19
|
+
const adapterComposablesDir = path.join(adapterDir, 'core', 'composables');
|
|
20
|
+
const targetComponentsDir = path.join(nuxtDir, 'components', 'websfc');
|
|
21
|
+
const targetComposablesDir = path.join(nuxtDir, 'composables', 'websfc');
|
|
22
|
+
|
|
23
|
+
copy.copyAdapterComponents(adapterComponentsDir, targetComponentsDir);
|
|
24
|
+
copy.copyAdapterComposables(adapterComposablesDir, targetComposablesDir);
|
|
25
|
+
|
|
26
|
+
const srcPagesDir = path.join(srcDir, 'pages');
|
|
27
|
+
const srcComponentsDir = path.join(srcDir, 'components');
|
|
28
|
+
const targetPagesDir = path.join(nuxtDir, 'pages');
|
|
29
|
+
const targetUserComponentsDir = path.join(nuxtDir, 'components');
|
|
30
|
+
|
|
31
|
+
copy.copySourceFiles(srcPagesDir, targetPagesDir, transformNuxt.transformNuxtContent);
|
|
32
|
+
copy.copySourceFiles(srcComponentsDir, targetUserComponentsDir, transformNuxt.transformNuxtContent);
|
|
33
|
+
|
|
34
|
+
const srcGlobals = path.join(srcDir, 'globals.ts');
|
|
35
|
+
const nuxtGlobals = path.join(nuxtDir, 'globals.ts');
|
|
36
|
+
if (fs.existsSync(srcGlobals)) {
|
|
37
|
+
const content = fs.readFileSync(srcGlobals, 'utf8');
|
|
38
|
+
const transformed = transformNuxt.transformNuxtContent(content, srcGlobals);
|
|
39
|
+
fs.writeFileSync(nuxtGlobals, transformed, 'utf8');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const srcCss = path.join(srcDir, 'app.css');
|
|
43
|
+
const assetsDir = path.join(nuxtDir, 'assets');
|
|
44
|
+
if (!fs.existsSync(assetsDir)) fs.mkdirSync(assetsDir, { recursive: true });
|
|
45
|
+
if (fs.existsSync(srcCss)) {
|
|
46
|
+
fs.copyFileSync(srcCss, path.join(assetsDir, 'app.css'));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
templatesNuxt.createNuxtPlatformFiles(nuxtDir);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = { createNuxtPlatform };
|
|
53
|
+
|
|
54
|
+
if (require.main === module) {
|
|
55
|
+
createNuxtPlatform();
|
|
56
|
+
}
|
|
57
|
+
|
|
@@ -14,20 +14,20 @@ function createWebPlatform(options = {}) {
|
|
|
14
14
|
// 当作为 node_modules 使用时,项目根应为当前工作目录
|
|
15
15
|
const projectRoot = options.projectRoot ? path.resolve(options.projectRoot) : process.cwd();
|
|
16
16
|
const platformsDir = path.join(projectRoot, 'platforms');
|
|
17
|
-
const webDir = path.join(platformsDir, '
|
|
17
|
+
const webDir = path.join(platformsDir, 'vue');
|
|
18
18
|
const srcDir = path.join(projectRoot, 'src');
|
|
19
19
|
|
|
20
20
|
console.log('[web-adapter] 项目根目录:', projectRoot);
|
|
21
21
|
console.log('[web-adapter] platforms 目录:', platformsDir);
|
|
22
|
-
console.log('[web-adapter]
|
|
22
|
+
console.log('[web-adapter] vue 目录:', webDir);
|
|
23
23
|
console.log('[web-adapter] src 目录:', srcDir);
|
|
24
24
|
|
|
25
25
|
try {
|
|
26
26
|
if (!fs.existsSync(webDir)) {
|
|
27
27
|
fs.mkdirSync(webDir, { recursive: true });
|
|
28
|
-
console.log('[web-adapter] 已创建
|
|
28
|
+
console.log('[web-adapter] 已创建 vue 目录');
|
|
29
29
|
} else {
|
|
30
|
-
console.log('[web-adapter]
|
|
30
|
+
console.log('[web-adapter] vue 目录已存在');
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// 1) 复制源码(仅脚本层转换,保留模板标签)
|
|
@@ -73,4 +73,4 @@ module.exports = { createWebPlatform };
|
|
|
73
73
|
|
|
74
74
|
if (require.main === module) {
|
|
75
75
|
createWebPlatform();
|
|
76
|
-
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function createNuxtPlatformFiles(nuxtDir) {
|
|
5
|
+
const projectRoot = path.dirname(path.dirname(nuxtDir));
|
|
6
|
+
|
|
7
|
+
const pkg = {
|
|
8
|
+
name: 'ns-nuxt-platform',
|
|
9
|
+
private: true,
|
|
10
|
+
scripts: {
|
|
11
|
+
dev: 'nuxt dev',
|
|
12
|
+
build: 'nuxt build',
|
|
13
|
+
preview: 'nuxt preview'
|
|
14
|
+
},
|
|
15
|
+
dependencies: {
|
|
16
|
+
nuxt: '^3.12.0'
|
|
17
|
+
},
|
|
18
|
+
devDependencies: {
|
|
19
|
+
typescript: '^5.0.0',
|
|
20
|
+
tailwindcss: '^3.4.0',
|
|
21
|
+
postcss: '^8.4.31',
|
|
22
|
+
autoprefixer: '^10.4.16'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
fs.writeFileSync(path.join(nuxtDir, 'package.json'), JSON.stringify(pkg, null, 2));
|
|
26
|
+
|
|
27
|
+
const appVue = `<template>\n <NuxtPage />\n</template>`;
|
|
28
|
+
fs.writeFileSync(path.join(nuxtDir, 'app.vue'), appVue);
|
|
29
|
+
|
|
30
|
+
const nuxtConfig = `import { defineNuxtConfig } from 'nuxt/config'
|
|
31
|
+
export default defineNuxtConfig({
|
|
32
|
+
components: [{ path: '~/components/websfc', global: true }],
|
|
33
|
+
css: ['~/assets/app.css']
|
|
34
|
+
})`;
|
|
35
|
+
fs.writeFileSync(path.join(nuxtDir, 'nuxt.config.ts'), nuxtConfig);
|
|
36
|
+
|
|
37
|
+
const pluginsDir = path.join(nuxtDir, 'plugins');
|
|
38
|
+
if (!fs.existsSync(pluginsDir)) fs.mkdirSync(pluginsDir, { recursive: true });
|
|
39
|
+
const pluginContent = `import { initGlobals } from '~/globals'
|
|
40
|
+
import * as ns from '~/composables/websfc/index.ts'
|
|
41
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
42
|
+
nuxtApp.vueApp.config.globalProperties.$ns = ns
|
|
43
|
+
initGlobals()
|
|
44
|
+
})`;
|
|
45
|
+
fs.writeFileSync(path.join(pluginsDir, 'ns-web.ts'), pluginContent);
|
|
46
|
+
|
|
47
|
+
const rootPostcss = path.join(projectRoot, 'postcss.config.js');
|
|
48
|
+
const rootTailwind = path.join(projectRoot, 'tailwind.config.js');
|
|
49
|
+
if (fs.existsSync(rootPostcss)) {
|
|
50
|
+
fs.copyFileSync(rootPostcss, path.join(nuxtDir, 'postcss.config.js'));
|
|
51
|
+
} else {
|
|
52
|
+
const postcssConfig = `module.exports = {\n plugins: {\n tailwindcss: {},\n autoprefixer: {},\n },\n};`;
|
|
53
|
+
fs.writeFileSync(path.join(nuxtDir, 'postcss.config.js'), postcssConfig);
|
|
54
|
+
}
|
|
55
|
+
if (fs.existsSync(rootTailwind)) {
|
|
56
|
+
fs.copyFileSync(rootTailwind, path.join(nuxtDir, 'tailwind.config.js'));
|
|
57
|
+
} else {
|
|
58
|
+
const tailwindConfig = `/** @type {import('tailwindcss').Config} */\nmodule.exports = {\n content: [\n './app.vue',\n './components/**/*.{vue,js,ts}',\n './pages/**/*.{vue,js,ts}',\n ],\n theme: {\n extend: {},\n },\n plugins: [],\n};`;
|
|
59
|
+
fs.writeFileSync(path.join(nuxtDir, 'tailwind.config.js'), tailwindConfig);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { createNuxtPlatformFiles };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function transformNuxtContent(content, srcPath) {
|
|
2
|
+
if (srcPath && /globals\.ts$/.test(srcPath)) {
|
|
3
|
+
return "export function initGlobals() {}\n";
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
content = content.replace(/from\s+['\"](nativescript-vue)['\"]/g, "from 'vue'");
|
|
7
|
+
content = content.replace(/import\s+.*@nativescript\/core.*;?\n?/g, '');
|
|
8
|
+
content = content.replace(/import\s+.*nativescript-web-adapter.*;?\n?/g, '');
|
|
9
|
+
content = content.replace(/declare\s+var\s+com[:\s\w]*;?\n?/g, '');
|
|
10
|
+
|
|
11
|
+
content = content.replace(/function\s+enterNow\([^\)]*\)\s*\{[\s\S]*?\}\n?/g, "function enterNow() { window.open(\"https://viteconf.amsterdam\", '_blank'); }\n");
|
|
12
|
+
content = content.replace(/function\s+enterNow\([^\)]*\)\s*\{[\s\S]*?\}\s*[\s\S]*?let interval/g, 'function enterNow() { window.open("https://viteconf.amsterdam", "_blank"); }\n\nlet interval');
|
|
13
|
+
|
|
14
|
+
if (srcPath && /\.vue$/i.test(srcPath)) {
|
|
15
|
+
const hasNavigateTo = /\$navigateTo\(\s*[A-Za-z_][A-Za-z0-9_]*\s*\)/.test(content);
|
|
16
|
+
const hasNavigateBack = /\$navigateBack\(\s*\)/.test(content);
|
|
17
|
+
const hasFrameNav = /Frame\.(navigate|goBack)\(/.test(content);
|
|
18
|
+
const hasFrameTopmost = /Frame\.topmost\(\)\.(navigate|goBack)\(/.test(content);
|
|
19
|
+
if (hasNavigateTo || hasNavigateBack || hasFrameNav || hasFrameTopmost) {
|
|
20
|
+
content = content.replace(/(?:this\.|[A-Za-z_$]+\?\.|[A-Za-z_$]+\.)*\$navigateTo\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)/g, "router.push('/$1')");
|
|
21
|
+
content = content.replace(/(?:this\.|[A-Za-z_$]+\?\.|[A-Za-z_$]+\.)*\$navigateBack\(\s*\)/g, 'router.go(-1)');
|
|
22
|
+
content = content.replace(/Frame\.goBack\(\s*\)/g, 'router.go(-1)');
|
|
23
|
+
content = content.replace(/Frame\.navigate\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)/g, "router.push('/$1')");
|
|
24
|
+
content = content.replace(/Frame\.navigate\(\s*['\"]([^'\"]+)['\"]\s*\)/g, (m, p1) => {
|
|
25
|
+
const base = String(p1).split('/')?.pop()?.replace(/\.vue$/i, '') || p1;
|
|
26
|
+
return `router.push('/${base}')`;
|
|
27
|
+
});
|
|
28
|
+
content = content.replace(/Frame\.navigate\(\s*\{[\s\S]*?moduleName\s*:\s*['\"]([^'\"]+)['\"][\s\S]*?\}\s*\)/g, (m, p1) => {
|
|
29
|
+
const base = String(p1).split('/')?.pop()?.replace(/\.vue$/i, '') || p1;
|
|
30
|
+
return `router.push('/${base}')`;
|
|
31
|
+
});
|
|
32
|
+
content = content.replace(/Frame\.topmost\(\)\.goBack\(\s*\)/g, 'router.go(-1)');
|
|
33
|
+
content = content.replace(/Frame\.topmost\(\)\.navigate\(\s*([A-Za-z_][A-Za-z0-9_]*)\s*\)/g, "router.push('/$1')");
|
|
34
|
+
content = content.replace(/Frame\.topmost\(\)\.navigate\(\s*['\"]([^'\"]+)['\"]\s*\)/g, (m, p1) => {
|
|
35
|
+
const base = String(p1).split('/')?.pop()?.replace(/\.vue$/i, '') || p1;
|
|
36
|
+
return `router.push('/${base}')`;
|
|
37
|
+
});
|
|
38
|
+
content = content.replace(/Frame\.topmost\(\)\.navigate\(\s*\{[\s\S]*?moduleName\s*:\s*['\"]([^'\"]+)['\"][\s\S]*?\}\s*\)/g, (m, p1) => {
|
|
39
|
+
const base = String(p1).split('/')?.pop()?.replace(/\.vue$/i, '') || p1;
|
|
40
|
+
return `router.push('/${base}')`;
|
|
41
|
+
});
|
|
42
|
+
if (!/useRouter\s*\(/.test(content)) {
|
|
43
|
+
content = content.replace(/(<script[^>]*>)/i, "$1\nimport { useRouter } from 'vue-router';\nconst router = useRouter();\n");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
content = content.replace(/.*(nativeApp|android\.|UIApplication|NSURL|NSDictionary|com\.tns|intent|startActivity|android\.content).*/g, '');
|
|
49
|
+
content = content.replace(/else\s*\{[\s\S]*?\}/g, '');
|
|
50
|
+
content = content.replace(/\/\s+\/>/g, '\/>');
|
|
51
|
+
content = content.replace(/registerElement\([^)]+\);?\n?/g, '');
|
|
52
|
+
if (content.includes('__ANDROID__') || content.includes('Application.launchEvent')) {
|
|
53
|
+
content = content.replace(/Application\.on[\s\S]*?}\);/g, '');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return content;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = { transformNuxtContent };
|