u
This commit is contained in:
parent
eb937cdab0
commit
56d203c4f0
16
boot_link.js
16
boot_link.js
@ -2,16 +2,18 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
console.log('\n::*** Overwriting node_modules libraries if available in openShare')
|
||||
|
||||
// Main function to link libraries
|
||||
const openSharePath = fs.existsSync(path.resolve('./env_loc.gitomit.sfomit.json')) ? require(path.resolve('./env_loc.gitomit.sfomit.json')).openShare : ''
|
||||
console.log('openShare:', openSharePath)
|
||||
console.log('::--- openShare =', openSharePath)
|
||||
if (!openSharePath) {
|
||||
console.log('openShare not found, exiting now.')
|
||||
console.log('::--- openShare not found, exiting now.')
|
||||
return
|
||||
}
|
||||
|
||||
const nodeModulesPath = path.resolve('./node_modules')
|
||||
console.log('nodeModulesPath:', nodeModulesPath)
|
||||
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')
|
||||
@ -19,7 +21,7 @@ const libs = fs.readdirSync(nodeModulesPath).filter((libName) => libName.startsW
|
||||
libs.forEach((libName) => {
|
||||
const libPath = path.join(openSharePath, libName)
|
||||
if (fs.existsSync(libPath)) {
|
||||
console.log(`Copying ${libName}`)
|
||||
console.log(`Overwriting ${libName}`)
|
||||
const sourceFiles = fs.readdirSync(libPath).filter((fileName) => fileName.endsWith('.js') || fileName.endsWith('.json'))
|
||||
sourceFiles.forEach((file) => {
|
||||
const sourceFile = path.join(libPath, file)
|
||||
@ -29,9 +31,11 @@ libs.forEach((libName) => {
|
||||
try {
|
||||
// fs.linkSync creates hard links on both Windows and Unix/Linux
|
||||
fs.linkSync(sourceFile, tempFile)
|
||||
// console.log('Linked ', sourceFile)
|
||||
} catch (err) {
|
||||
// Fallback to copy if hard link fails
|
||||
fs.copyFileSync(sourceFile, tempFile)
|
||||
// console.log('Copied', sourceFile)
|
||||
}
|
||||
try {
|
||||
fs.unlinkSync(destFile)
|
||||
@ -44,8 +48,8 @@ libs.forEach((libName) => {
|
||||
/*
|
||||
script in package.json:
|
||||
|
||||
"boot_link.sh": "echo '#<<< Copy local lib to node_modules'; for LIB in $(cd node_modules && ls -d wo_* wo-* tic-crypto 2>&1); do if [ -d ../../npm/$LIB ]; then echo $LIB; ln -f $(realpath ../../npm/$LIB)/*.js ./node_modules/$LIB/; fi; done;"
|
||||
"boot_link.sh": "echo '::*** Copy local lib to node_modules'; for LIB in $(cd node_modules && ls -d wo_* wo-* tic-crypto 2>&1); do if [ -d ../../npm/$LIB ]; then echo $LIB; ln -f $(realpath ../../npm/$LIB)/*.js ./node_modules/$LIB/; fi; done;"
|
||||
|
||||
echo #<<< Copy local lib to node_modules; for LIB in $(cd node_modules && ls -d wo_* wo-* tic-crypto 2>&1); do if [ -d $(jq -r .openShare env_loc.gitomit.sfomit.json)/$LIB ]; then echo copying $LIB; ln -f $(realpath $(jq -r .openShare env_loc.gitomit.sfomit.json))/$LIB/*.js ./node_modules/$LIB/; fi; done;
|
||||
echo ::*** Copy local lib to node_modules; for LIB in $(cd node_modules && ls -d wo_* wo-* tic-crypto 2>&1); do if [ -d $(jq -r .openShare env_loc.gitomit.sfomit.json)/$LIB ]; then echo copying $LIB; ln -f $(realpath $(jq -r .openShare env_loc.gitomit.sfomit.json))/$LIB/*.js ./node_modules/$LIB/; fi; done;
|
||||
|
||||
*/
|
||||
|
25
cache_urls.js
Normal file
25
cache_urls.js
Normal file
@ -0,0 +1,25 @@
|
||||
async function fetch_urls (urls) {
|
||||
let seq = 1
|
||||
for (const url of urls) {
|
||||
const startTime = process.hrtime()
|
||||
try {
|
||||
const res = await fetch(url)
|
||||
const { status } = res
|
||||
const sizeDownload = res.headers.get('content-length') || 0
|
||||
const urlEffective = res.url
|
||||
|
||||
await res.text() // Consume the response body
|
||||
|
||||
const [seconds, nanoseconds] = process.hrtime(startTime)
|
||||
const timeTotal = seconds + nanoseconds / 1e9
|
||||
|
||||
console.log(`${seq++}/${urls.length} | ${status} | ${timeTotal.toFixed(3)} s | ${sizeDownload} bytes | ${urlEffective}`)
|
||||
} catch (e) {
|
||||
console.error(`Error fetching ${url}: ${e.message}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// example: fetch_urls(['https://u.cn.agidin.com/uni_modules/uni-pay/static/wxpay.png', 'https://u.cn.agidin.com/static/js/pages-user-resource.4a81c0a7.js'])
|
||||
|
||||
module.exports = fetch_urls
|
14
env_loc.js
14
env_loc.js
@ -18,12 +18,12 @@ const defaultEnv = {
|
||||
os.type() === 'Darwin' && fs.existsSync('/Applications/Transporter.app/Contents/itms/bin/iTMSTransporter')
|
||||
? '/Applications/Transporter.app/Contents/itms/bin/iTMSTransporter'
|
||||
: '',
|
||||
simsimPath: module.paths.some((modulesPath) => fs.existsSync(path.join(modulesPath, 'simsim_api')))
|
||||
? 'simsim_api'
|
||||
: fs.existsSync('../../../simsim-api')
|
||||
? path.resolve('../../../simsim-api')
|
||||
: fs.existsSync(`${os.homedir()}/simsim-api`)
|
||||
? path.resolve(`${os.homedir()}/simsim-api`)
|
||||
simsimPath: module.paths.some((modulesPath) => fs.existsSync(path.join(modulesPath, 'simsim_key')))
|
||||
? 'simsim_key'
|
||||
: fs.existsSync('../../../simsim_key')
|
||||
? path.resolve('../../../simsim_key')
|
||||
: fs.existsSync(`${os.homedir()}/simsim_key`)
|
||||
? path.resolve(`${os.homedir()}/simsim_key`)
|
||||
: '',
|
||||
openShare: fs.existsSync('../../npm') ? path.resolve('../../npm') : fs.existsSync(`${os.homedir()}/opx`) ? path.resolve(`${os.homedir()}/opx`) : '',
|
||||
}
|
||||
@ -41,6 +41,8 @@ const localEnv = Object.assign(
|
||||
|
||||
fs.writeFileSync(path.resolve('./env_loc.gitomit.sfomit.json'), JSON.stringify(localEnv, null, 2), 'utf8')
|
||||
|
||||
console.log('\n::*** Configuring local enviroment:')
|
||||
|
||||
console.log(localEnv)
|
||||
|
||||
module.exports = localEnv
|
||||
|
Loading…
Reference in New Issue
Block a user