You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
seacms-theme/js/extract-files-from-node-mod...

197 lines
4.7 KiB

/*
* 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))
// }
// })
// }
// knacss
copySync(
'node_modules/knacss/css/knacss-mini/knacss.css',
'css/vendor/knacss/knacss.min.css',
{ overwrite: true }
)
copySync(
'node_modules/knacss/LICENSE',
'css/vendor/knacss/LICENSE',
{ overwrite: true }
)
// modernizr
const modernizr = require("modernizr")
modernizr.build({
"minify": true,
"options": [
"setClasses"
],
"feature-detects": [
"test/requestanimationframe",
"test/css/transitions",
"test/dom/classlist"
]
}, function (result) {
let src = 'js/vendor/modernizr'
let currentPath = path.join(basePath, src)
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath,{recursive :true})
}
fs.writeFileSync(path.join(currentPath, 'modernizr.min.js'), result);// the build
});
copySync(
'node_modules/modernizr/LICENSE',
'js/vendor/modernizr/LICENSE',
{ overwrite: true }
)
// icomoon free
copySync(
'node_modules/icomoon-free-npm/license.txt',
'fonts/vendor/icomoon-free-npm/license.txt',
{ overwrite: true }
)
var previousCSSContent = fs.readFileSync( path.join(basePath,'node_modules/icomoon-free-npm/Font/demo-files/demo.css'),{encoding:'utf8', flag:'r'} )
var position = previousCSSContent.search(/@font-face/)
fs.writeFileSync(
path.join(
basePath,
'fonts/vendor/icomoon-free-npm/icomoon.css'
),
previousCSSContent.substr(position).replace(
/url\('..\/IcoMoon-Free.ttf'\) format\('truetype'\)/,
"url('./IcoMoon-Free.woff') format('woff')"
)
)
const execSync = require('child_process').execSync;
execSync('node node_modules/ttf2woff/ttf2woff.js node_modules/icomoon-free-npm/Font/IcoMoon-Free.ttf fonts/vendor/icomoon-free-npm/IcoMoon-Free.woff', { encoding: 'utf-8' });
// font Luciole
fetch('https://www.luciole-vision.com/Fichiers/Luciole_webfonts.zip')
.then((response)=>{
if (!response.ok){
throw 'response not ok'
} else {
}
})
const http = require('http');
let src = 'node_modules/Luciole/'
let currentPath = path.join(basePath, src)
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath,{recursive :true})
}
const zipPath = path.join(currentPath,'Luciole_webfonts.zip')
const file = fs.createWriteStream(zipPath)
const request = http.get("http://www.luciole-vision.com/Fichiers/Luciole_webfonts.zip", function(response) {
response.pipe(file)
response.on('end', () => {
setTimeout(()=>{
var AdmZip = require("adm-zip")
var zip = new AdmZip(zipPath)
zip.extractAllTo(/*target path*/ currentPath, /*overwrite*/ true)
},500)
})
});
copySync(
'node_modules/Luciole/Luciole_webfonts/Read Me.txt',
'fonts/vendor/Luciole/Read Me.txt',
{ overwrite: true }
)
var arr = [
{
name:'Luciole-Regular',
style:'normal',
weight:'normal'
},
{
name:'Luciole-Italic',
style:'italic',
weight:'normal'
},
{
name:'Luciole-Bold',
style:'normal',
weight:'bold'
},
{
name:'Luciole-BoldItalic',
style:'italic',
weight:'bold'
}
]
let css = "/* Webfont: Luciole */\n\n"
arr.forEach((data)=>{
let name = data.name
copySync(
`node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`,
`fonts/vendor/Luciole/${name}/${name}.woff`,
{ overwrite: true }
)
css +=
`/* Webfont: ${name} */
@font-face {
font-family: 'Luciole';
src: url('./${name}/${name}.woff') format('woff');
font-style: ${data.style};
font-weight: ${data.weight};
text-rendering: optimizeLegibility;
}
`
})
fs.writeFileSync(
path.join(
basePath,
'fonts/vendor/Luciole/Luciole.css'
),
css
)
// example
// mergeFilesSync(
// [
// 'node_modules/file1.js',
// 'node_modules/file2.js',
// ],
// 'javascripts/vendor/output-file.js');