2020-06-01 21:20:11 +00:00
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
2020-04-28 09:47:35 +00:00
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
2022-03-31 11:41:37 +00:00
|
|
|
import buble from '@rollup/plugin-buble';
|
2020-04-28 09:47:35 +00:00
|
|
|
import { terser } from 'rollup-plugin-terser';
|
|
|
|
import replace from '@rollup/plugin-replace';
|
|
|
|
|
2020-07-01 13:13:34 +00:00
|
|
|
const names = ['iconify', 'iconify.without-api'];
|
2020-04-28 09:47:35 +00:00
|
|
|
const global = 'Iconify';
|
|
|
|
|
|
|
|
// Wrapper to export module as global and as ES module
|
|
|
|
const header = `/**
|
2020-06-01 21:20:11 +00:00
|
|
|
* (c) Iconify
|
2020-04-28 09:47:35 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the license.txt or license.gpl.txt
|
|
|
|
* files at https://github.com/iconify/iconify
|
|
|
|
*
|
2022-05-01 06:56:33 +00:00
|
|
|
* Licensed under MIT.
|
2020-04-28 09:47:35 +00:00
|
|
|
*
|
2022-05-01 06:56:33 +00:00
|
|
|
* @license MIT
|
2021-09-24 08:41:54 +00:00
|
|
|
* @version __iconify_version__
|
2020-04-28 09:47:35 +00:00
|
|
|
*/`;
|
|
|
|
|
2021-09-24 16:03:49 +00:00
|
|
|
const defaultFooter = `
|
2020-04-28 09:47:35 +00:00
|
|
|
// Export to window or web worker
|
|
|
|
try {
|
|
|
|
if (self.Iconify === void 0) {
|
|
|
|
self.Iconify = Iconify;
|
|
|
|
}
|
|
|
|
} catch (err) {
|
2021-09-24 16:03:49 +00:00
|
|
|
}`;
|
2020-04-28 09:47:35 +00:00
|
|
|
|
2021-09-24 16:03:49 +00:00
|
|
|
const iifeFooter = `
|
|
|
|
// Export as ES module
|
2020-04-28 09:47:35 +00:00
|
|
|
if (typeof exports === 'object') {
|
|
|
|
try {
|
|
|
|
exports.__esModule = true;
|
|
|
|
exports.default = Iconify;
|
2021-09-24 16:03:49 +00:00
|
|
|
for (var key in Iconify) {
|
|
|
|
exports[key] = Iconify[key];
|
|
|
|
}
|
2020-04-28 09:47:35 +00:00
|
|
|
} catch (err) {
|
|
|
|
}
|
2021-09-24 16:03:49 +00:00
|
|
|
}
|
2020-04-28 09:47:35 +00:00
|
|
|
|
2021-09-24 16:03:49 +00:00
|
|
|
${defaultFooter}`;
|
2021-09-24 08:41:54 +00:00
|
|
|
|
2020-04-28 09:47:35 +00:00
|
|
|
// Get replacements
|
2021-06-16 13:58:27 +00:00
|
|
|
const replacements = {
|
|
|
|
preventAssignment: true,
|
|
|
|
};
|
2020-04-28 09:47:35 +00:00
|
|
|
const packageJSON = JSON.parse(readFileSync('package.json', 'utf8'));
|
|
|
|
replacements['__iconify_version__'] = packageJSON.version;
|
|
|
|
|
2020-06-01 21:20:11 +00:00
|
|
|
// Update README.md
|
|
|
|
let readme = readFileSync('README.md', 'utf8');
|
|
|
|
const oldReadme = readme;
|
|
|
|
const replaceCodeLink = (search) => {
|
|
|
|
let start = 0;
|
|
|
|
let pos;
|
|
|
|
while ((pos = readme.indexOf(search, start)) !== -1) {
|
|
|
|
start = pos + search.length;
|
|
|
|
let pos2 = readme.indexOf('/', start);
|
|
|
|
if (pos2 === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
readme =
|
|
|
|
readme.slice(0, start) + packageJSON.version + readme.slice(pos2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
replaceCodeLink('/code.iconify.design/2/');
|
|
|
|
replaceCodeLink('/@iconify/iconify@');
|
|
|
|
|
|
|
|
if (readme !== oldReadme) {
|
|
|
|
console.log('Updatead README');
|
|
|
|
writeFileSync('README.md', readme, 'utf8');
|
|
|
|
}
|
|
|
|
|
2020-04-28 09:47:35 +00:00
|
|
|
// Export configuration
|
|
|
|
const config = [];
|
2020-07-01 13:13:34 +00:00
|
|
|
names.forEach((name) => {
|
2021-09-24 08:41:54 +00:00
|
|
|
// Full and minified
|
|
|
|
[false, true].forEach((minify) => {
|
|
|
|
// Parse all formats
|
|
|
|
['js', 'cjs', 'mjs'].forEach((ext) => {
|
|
|
|
if (minify && ext !== 'js') {
|
|
|
|
// Minify only .js files
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-24 16:03:49 +00:00
|
|
|
// Get export format and footer
|
2021-09-24 08:41:54 +00:00
|
|
|
let format = ext;
|
2021-09-24 16:03:49 +00:00
|
|
|
let footer = defaultFooter;
|
2021-09-24 08:41:54 +00:00
|
|
|
switch (ext) {
|
|
|
|
case 'js':
|
|
|
|
format = 'iife';
|
2021-09-24 16:03:49 +00:00
|
|
|
footer = iifeFooter;
|
2021-09-24 08:41:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'mjs':
|
|
|
|
format = 'es';
|
2021-09-24 16:03:49 +00:00
|
|
|
break;
|
2021-09-24 08:41:54 +00:00
|
|
|
}
|
2021-09-24 16:03:49 +00:00
|
|
|
|
2021-09-24 08:41:54 +00:00
|
|
|
const item = {
|
|
|
|
input: `lib/${name}.js`,
|
|
|
|
output: [
|
|
|
|
{
|
|
|
|
file: `dist/${name}${minify ? '.min' : ''}.${ext}`,
|
|
|
|
format,
|
2021-09-24 16:03:49 +00:00
|
|
|
exports: 'named',
|
2021-09-24 08:41:54 +00:00
|
|
|
name: global,
|
|
|
|
banner: header,
|
2021-09-24 16:03:49 +00:00
|
|
|
footer,
|
2021-09-24 08:41:54 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
resolve({
|
|
|
|
browser: true,
|
|
|
|
}),
|
|
|
|
replace(replacements),
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2022-03-31 11:41:37 +00:00
|
|
|
if (ext === 'js') {
|
|
|
|
// Support old browsers only in .js files.
|
|
|
|
// Other files are for modern browsers that don't need it or
|
|
|
|
// for bundlers that should handle old browser support themselves.
|
|
|
|
item.plugins.push(
|
|
|
|
buble({
|
|
|
|
objectAssign: 'Object.assign',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-24 08:41:54 +00:00
|
|
|
if (minify) {
|
|
|
|
item.plugins.push(terser());
|
|
|
|
}
|
|
|
|
|
|
|
|
config.push(item);
|
|
|
|
});
|
2020-07-01 13:13:34 +00:00
|
|
|
});
|
2020-04-28 09:47:35 +00:00
|
|
|
});
|
2021-09-24 08:41:54 +00:00
|
|
|
|
2020-04-28 09:47:35 +00:00
|
|
|
export default config;
|