2026-10-22 16:18:37 +08:00
const fs = require ( 'node:fs' ) ;
const path = require ( 'node:path' ) ;
const root = path . resolve ( _ _dirname , '..' ) ;
const write = ( file , text ) => { const full = path . join ( root , file ) ; fs . mkdirSync ( path . dirname ( full ) , { recursive : true } ) ; fs . writeFileSync ( full , text ) ; } ;
const edit = ( file , fn ) => write ( file , fn ( fs . readFileSync ( path . join ( root , file ) , 'utf8' ) ) ) ;
for ( const name of [ 'common' , 'aima' ] ) {
write ( ` src/cmvr/ ${ name } /utils/request.js ` , "export { default, download, isRelogin } from '@/cmvr/request'\n" ) ;
2026-11-03 10:55:40 +08:00
write ( ` src/cmvr/ ${ name } /utils/auth.js ` , "export { getAccessToken as getToken, removeToken } from '@/utils/auth'\nexport const setToken = () => { throw new Error('请通过招商车研三维尺寸快检平台登录') }\n" ) ;
2026-10-22 16:18:37 +08:00
write ( ` src/cmvr/ ${ name } /router/index.js ` , "export { default } from '@/router'\n" ) ;
write ( ` src/cmvr/ ${ name } /store/index.js ` , "export { store as default } from '@/store'\n" ) ;
// Do not let source user/session stores compete with FreeScan identity.
write ( ` src/cmvr/ ${ name } /store/modules/user.js ` , ` import { useUserStore as useTargetUserStore } from '@/store/modules/user' \n import { getAccessToken } from '@/utils/auth' \n export default function useUserStore() { const target = useTargetUserStore(); return { get id() { return target.user.id }, get token() { return getAccessToken() }, get roles() { return target.roles }, get permissions() { return Array.from(target.permissions) }, logOut: () => target.loginOut() } } \n ` ) ;
}
// Original common source has a spelling mismatch that prevents robot filtering.
edit ( 'src/cmvr/common/views/resource/device/index.vue' , text => text . replaceAll ( 'robotsLoading.value' , 'robotLoading.value' ) ) ;
const pages = {
'intelligenceTest/testCase' : [ 'aima/views/intelligenceTest/testCase/index.vue' , 'CmvrTestCase' ] ,
'intelligenceTest/taskManage' : [ 'aima/views/intelligenceTest/taskManage/index.vue' , 'CmvrTaskManage' ] ,
'intelligenceTest/runningTask' : [ 'aima/views/intelligenceTest/runningTask/index.vue' , 'CmvrRunningTask' ] ,
'intelligenceTest/car' : [ 'aima/views/intelligenceTest/car/index.vue' , 'CmvrCar' ] ,
'intelligenceTest/mobilePhone' : [ 'aima/views/intelligenceTest/mobilePhone/index.vue' , 'CmvrMobilePhone' ] ,
'resource/robot' : [ 'common/views/resource/robot/index.vue' , 'CmvrRobot' ] ,
'resource/device' : [ 'common/views/resource/device/index.vue' , 'CmvrDevice' ] ,
'resource/map' : [ 'common/views/resource/map/index.vue' , 'CmvrMap' ] ,
'resource/terminal' : [ 'common/views/resource/terminal/index.vue' , 'CmvrTerminal' ] ,
'resource/visionCalibration' : [ 'common/views/resource/visionCalibration/index.vue' , 'CmvrVisionCalibration' ] ,
} ;
for ( const [ page , [ component , name ] ] of Object . entries ( pages ) ) {
write ( ` src/views/cmvr/ ${ page } /index.vue ` , ` <template><div class="cmvr-module"><OriginalPage /></div></template> \n <script setup lang="ts"> \n import OriginalPage from '@/cmvr/ ${ component } ' \n defineOptions({ name: ' ${ name } ' }) \n </script> \n ` ) ;
}
write ( 'src/views/cmvr/flow/index.vue' , ` <template><div class="cmvr-flow"><OriginalFlow /></div></template> \n <script setup lang="ts"> \n import OriginalFlow from '@/cmvr/common/views/flow/index.vue' \n defineOptions({ name: 'CmvrFlow' }) \n </script> \n ` ) ;
edit ( 'src/main.ts' , text => text . replace ( "import App from './App.vue'" , "import App from './App.vue'\nimport { setupCmvr } from '@/cmvr/setup'" ) . replace ( 'setupStore(app)' , 'setupStore(app)\n\n setupCmvr(app)' ) ) ;
edit ( 'build/vite/index.ts' , text => text . replace ( "'vue-router'," , "'vue-router',\n 'pinia'," ) . replace ( "iconDirs: [pathResolve('src/assets/svgs')]" , "iconDirs: [pathResolve('src/assets/svgs'), pathResolve('src/cmvr/common/assets/icons/svg')]" ) ) ;
edit ( 'vite.config.ts' , text => text . replace ( "alias: [" , "alias: [\n { find: '@cmvr/iot-common', replacement: pathResolve('src/cmvr/bridge.js') }," ) . replace ( "extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss', '.css']" , "extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue', '.scss', '.css']" ) . replace ( 'base: env.VITE_BASE_PATH,' , 'base: env.VITE_BASE_PATH,\n define: { __PROJECT_NAME__: JSON.stringify("aima") },' ) . replace ( 'const normalizedFilename = normalizePath(filename)' , ` const normalizedFilename = normalizePath(filename) \n if (normalizedFilename.includes('/src/cmvr/')) { \n const cmvrVars = pathResolve('src/cmvr/common/style/variable.scss') \n if (normalizedFilename.endsWith('/style/variable.scss')) return source \n return \` @use " \$ {getRelativeScssUsePath(filename, cmvrVars)}" as *; \\ n \$ {source} \` \n } ` ) ) ;
// Preserve all source teach and companion routes; expose the same paths used by original actions.
write ( 'src/cmvr/routes.ts' , ` import { Layout } from '@/utils/routerHelper' \n import { createDeviceRoutes } from './common/router/deviceRoutes' \n const originalDeviceRoutes = createDeviceRoutes(Layout).map((route: any) => ({ ...route, meta: { ...route.meta, hidden: true }, children: route.children?.map((child: any) => ({ ...child, meta: { ...child.meta, hidden: true, canTo: true } })) })) \n export const cmvrRoutes = [ \n { path: '/flow', name: 'CmvrFlow', component: () => import('@/views/cmvr/flow/index.vue'), meta: { hidden: true, canTo: true, title: '流程编排' } }, \n ...originalDeviceRoutes, \n ] \n ` ) ;
edit ( 'src/router/modules/remaining.ts' , text => text . replace ( "import { Layout } from '@/utils/routerHelper'" , "import { Layout } from '@/utils/routerHelper'\nimport { cmvrRoutes } from '@/cmvr/routes'" ) . replace ( 'const remainingRouter: AppRouteRecordRaw[] = [' , 'const remainingRouter: AppRouteRecordRaw[] = [\n ...cmvrRoutes,' ) ) ;
// Keep the imported JavaScript business modules out of the host's strict TS project;
// imported TS helpers carry @ts-nocheck while Vite validates the complete dependency graph.
edit ( 'tsconfig.json' , text => text . replace ( '"paths": {' , '"paths": {\n "@cmvr/iot-common": ["src/cmvr/bridge.js"],' ) . replace ( '"exclude": ["dist", "target", "node_modules"]' , '"exclude": ["dist", "target", "node_modules", "src/cmvr/common", "src/cmvr/aima"]' ) ) ;
console . log ( 'CMVR source adapters, original-page wrappers, hidden routes, authentication and build hooks applied.' ) ;