2020-11-26 22:21:55 +00:00
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
|
|
const fse = require('fs-extra');
|
|
|
|
const Bundler = require('parcel-bundler');
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
outDir: './dist',
|
|
|
|
outFile: 'index.html',
|
|
|
|
publicUrl: '/',
|
|
|
|
watch: process.env.NODE_ENV !== 'production',
|
2020-11-28 21:33:51 +00:00
|
|
|
cache: process.env.NODE_ENV !== 'production',
|
2020-11-26 22:21:55 +00:00
|
|
|
cacheDir: '.cache',
|
|
|
|
contentHash: false,
|
2021-01-26 17:46:26 +00:00
|
|
|
minify: false,
|
2020-11-26 22:21:55 +00:00
|
|
|
scopeHoist: false,
|
|
|
|
target: 'browser',
|
|
|
|
bundleNodeModules: false,
|
|
|
|
https: true,
|
|
|
|
logLevel: 3,
|
2020-12-09 19:36:28 +00:00
|
|
|
hmr: false,
|
2020-11-26 22:21:55 +00:00
|
|
|
hmrPort: 1235,
|
|
|
|
sourceMaps: true,
|
|
|
|
hmrHostname: '',
|
|
|
|
detailedReport: false,
|
|
|
|
autoInstall: true
|
|
|
|
};
|
|
|
|
|
2021-03-08 14:34:34 +00:00
|
|
|
((async function () {
|
2020-12-14 10:24:35 +00:00
|
|
|
let configPath = process.env.CONFIG_PATH || 'config.json';
|
2021-03-08 14:34:34 +00:00
|
|
|
if (!fs.existsSync(configPath)) throw console.error(Error(`(Mandatory) Missing ${configPath} file`));
|
2020-12-14 10:24:35 +00:00
|
|
|
console.log(`Using ${configPath} config file`);
|
2020-11-26 22:21:55 +00:00
|
|
|
|
2020-12-14 10:24:35 +00:00
|
|
|
let config = JSON.parse(fs.readFileSync(configPath));
|
2020-11-26 22:21:55 +00:00
|
|
|
|
|
|
|
let manifest = {
|
|
|
|
"lang": "fr",
|
|
|
|
"dir": "ltr",
|
2021-02-22 20:27:58 +00:00
|
|
|
"name": config.client.name || "My Personal Hubl",
|
|
|
|
"description": `Hubl of ${config.client.name || "My Personal Hubl"}`,
|
|
|
|
"short_name": config.client.name || "My Personal Hubl",
|
2020-11-26 22:21:55 +00:00
|
|
|
"icons": [{
|
2021-02-22 20:27:58 +00:00
|
|
|
"src": config.client.logo || '/images/logo.webp',
|
2020-11-26 22:21:55 +00:00
|
|
|
"purpose": "any"
|
|
|
|
}, {
|
|
|
|
"src": "/images/hubl-icon-192.png",
|
|
|
|
"sizes": "192x192",
|
|
|
|
"type": "image/png"
|
|
|
|
}, {
|
|
|
|
"src": "/images/hubl-icon-512.png",
|
|
|
|
"sizes": "512x512",
|
|
|
|
"type": "image/png"
|
|
|
|
}],
|
|
|
|
"start_url": ".",
|
|
|
|
"display": "standalone",
|
|
|
|
"orientation": "portrait",
|
|
|
|
"background_color": "#fff",
|
|
|
|
'theme_color': "white"
|
|
|
|
}
|
|
|
|
|
|
|
|
await fse.writeJSON('./src/manifest.webmanifest', manifest)
|
2021-02-22 20:27:58 +00:00
|
|
|
console.log(`Created manifest for ${config.client.name || "My Personal Hubl"}`);
|
2020-11-26 22:21:55 +00:00
|
|
|
|
|
|
|
await fse.copy("./src/locales", "./dist/locales")
|
|
|
|
console.log(`Copied locales to dist folder`);
|
|
|
|
|
|
|
|
await fse.copy("./src/components", "./dist/components")
|
|
|
|
console.log(`Copied components to dist folder`);
|
|
|
|
|
|
|
|
const bundler = new Bundler('./src/index.pug', options);
|
|
|
|
bundler.addAssetType('html', require.resolve('./assets.js'));
|
2021-03-08 14:34:34 +00:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2020-11-26 22:21:55 +00:00
|
|
|
await bundler.serve();
|
|
|
|
} else {
|
|
|
|
await bundler.bundle();
|
|
|
|
}
|
2021-03-08 14:34:34 +00:00
|
|
|
})()).catch((e) => {
|
|
|
|
process.exitCode = 1;
|
|
|
|
});
|