seacms-auth/js/extract-files-from-node-modules.js
2023-03-11 18:16:33 +01:00

61 lines
1.4 KiB
JavaScript

/*
* SPDX-License-Identifier: EUPL-1.2
* Authors: see README.md
*/
// Extract files that we need from the node_modules folder
// The extracted files are integrated to the repository, so production server don't need to
// have node installed
// Include fs and path module
const fs = require('fs-extra')
const path = require('path')
const basePath = path.join(__dirname, '../')
function copySync(src, dest, opts) {
if (fs.existsSync(src)) {
fs.copySync(path.join(basePath, src), path.join(basePath, dest), opts)
} else {
console.log(`${src} is not existing !`)
}
}
// function mergeFilesSync(sources, dest) {
// const fullDest = path.join(basePath, dest)
// if (!fs.existsSync(fullDest)) {
// fs.mkdirSync(path.dirname(fullDest), { recursive: true })
// } else {
// fs.unlinkSync(fullDest)
// }
// sources.forEach((file) => {
// const fullSrc = path.join(basePath, file)
// if (!fs.existsSync(fullSrc)) {
// console.log(`${fullSrc} is not existing !`)
// } else {
// fs.appendFileSync(fullDest, fs.readFileSync(fullSrc))
// }
// })
// }
// vue
copySync(
'node_modules/vue/dist/vue.global.prod.js',
'js/vendor/vue/vue.min.js',
{ overwrite: true }
)
copySync(
'node_modules/vue/LICENSE',
'js/vendor/vue/LICENSE',
{ overwrite: true }
)
// example
// mergeFilesSync(
// [
// 'node_modules/file1.js',
// 'node_modules/file2.js',
// ],
// 'javascripts/vendor/output-file.js');