2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 06:28:24 +00:00
iconify/iconify-icon/icon/rollup.config.js

105 lines
2.1 KiB
JavaScript
Raw Normal View History

import { readFileSync, writeFileSync } from 'fs';
2022-04-29 20:19:22 +00:00
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
2022-04-30 16:16:10 +00:00
// Header
2022-04-29 20:19:22 +00:00
const header = `/**
* (c) Iconify
*
2022-04-30 16:16:10 +00:00
* For the full copyright and license information, please view the license.txt
2022-04-29 20:19:22 +00:00
* files at https://github.com/iconify/iconify
*
2022-04-30 16:16:10 +00:00
* Licensed under MIT.
2022-04-29 20:19:22 +00:00
*
2022-04-30 16:16:10 +00:00
* @license MIT
2022-04-29 20:19:22 +00:00
* @version __iconify_version__
*/`;
// Get replacements
const replacements = {
preventAssignment: true,
};
const packageJSON = JSON.parse(readFileSync('package.json', 'utf8'));
replacements['__iconify_version__'] = packageJSON.version;
// 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/iconify-icon/');
replaceCodeLink('/npm/iconify-icon@');
if (readme !== oldReadme) {
console.log('Updatead README');
writeFileSync('README.md', readme, 'utf8');
}
2022-04-29 20:19:22 +00:00
// Export configuration
const config = [];
2022-04-30 16:16:10 +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;
}
2022-04-29 20:19:22 +00:00
2022-04-30 16:16:10 +00:00
// Get export format
let format = ext;
let input = 'lib/index.js';
let exportType = 'named';
switch (ext) {
case 'js':
format = 'iife';
exportType = void 0;
input = 'lib/script.js';
break;
case 'mjs':
format = 'es';
break;
}
2022-04-29 20:19:22 +00:00
2022-04-30 16:16:10 +00:00
const item = {
input,
output: [
{
file: `dist/iconify-icon${minify ? '.min' : ''}.${ext}`,
format,
exports: exportType,
banner: header,
},
],
plugins: [
resolve({
browser: true,
}),
replace(replacements),
],
};
if (minify) {
item.plugins.push(terser());
}
2022-04-29 20:19:22 +00:00
2022-04-30 16:16:10 +00:00
config.push(item);
2022-04-29 20:19:22 +00:00
});
});
export default config;