From 1665611cd54e1a66cbca74d0628cc9a56d997c62 Mon Sep 17 00:00:00 2001 From: Luk Date: Tue, 29 Oct 2024 12:58:09 +0800 Subject: [PATCH] add 'boot_link.js' --- boot_link.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 boot_link.js diff --git a/boot_link.js b/boot_link.js new file mode 100644 index 0000000..e7ebf93 --- /dev/null +++ b/boot_link.js @@ -0,0 +1,46 @@ +// boot_link.js +const fs = require('fs') +const { execSync } = require('child_process') +const path = require('path') + +// Main function to link libraries +const openNpmPath = fs.existsSync(path.resolve('./env_loc.gitomit.sfomit.json')) + ? require(path.resolve('./env_loc.gitomit.sfomit.json')).openNpm + : '' +console.log('openNpm:', openNpmPath) +if (!openNpmPath) { + return +} + +const nodeModulesPath = path.resolve('./node_modules') +console.log('nodeModulesPath:', nodeModulesPath) + +// Get the list of libraries +const libs = fs + .readdirSync(nodeModulesPath) + .filter( + libName => + libName.startsWith('wo_') || + libName.startsWith('wo-') || + libName === 'tic-crypto' + ) +console.log('libs:', libs) + +libs.forEach(libName => { + const libPath = path.join(openNpmPath, libName) + if (fs.existsSync(libPath)) { + console.log(`Copying ${libName}`) + const sourceFiles = fs + .readdirSync(libPath) + .filter( + fileName => fileName.endsWith('.js') || fileName.endsWith('.json') + ) + sourceFiles.forEach(file => { + const sourceFile = path.join(libPath, file) + const tempFile = path.join(nodeModulesPath, libName, file + '.temp') + const destFile = path.join(nodeModulesPath, libName, file) + fs.symlinkSync(sourceFile, tempFile, 'file') + fs.renameSync(tempFile, destFile) + }) + } +})