Skip to content

Commit

Permalink
Merge pull request #12 from biutas/chore/update-to-angular-13
Browse files Browse the repository at this point in the history
Chore: Update deps; Angular to v13
  • Loading branch information
biutas authored Dec 16, 2021
2 parents fba2edf + 0a6621f commit cc1bcc1
Show file tree
Hide file tree
Showing 1,532 changed files with 10,064 additions and 5,590 deletions.
117 changes: 61 additions & 56 deletions generate.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,70 @@
const del = require('del');
const fs = require('fs-extra');
const uppercamelcase = require('uppercamelcase');
const del = require("del");
const fs = require("fs-extra");
const uppercamelcase = require("uppercamelcase");

const iconsSrcFolder = 'node_modules/bootstrap-icons/icons';
const iconsSrcFolder = "node_modules/bootstrap-icons/icons";

const iconsDestFolder = 'icons/svg';
const indexFile = 'icons/index.ts';
const allFile = 'icons/all.ts';
const iconsDestFolder = "icons/svg";
const indexFile = "icons/index.ts";
const allFile = "icons/all.ts";

let exportAllString = `\nexport const allIcons = {\n`;

const componentTemplate = fs.readFileSync('src/templates/component.ts.tpl', 'utf-8');

return Promise.resolve()
// delete feather folder and index
.then(() => del([iconsDestFolder, indexFile, allFile]))
// create destination folder
.then(() => fs.mkdirSync(iconsDestFolder))
.then(() => {
fs.readdirSync(`${iconsSrcFolder}`).forEach(filename => {
'use strict';
const iconName = stripExtension(filename);
const exportName = uppercamelcase(iconName);
// console.log(filename);

const markup = fs.readFileSync(`${iconsSrcFolder}/${filename}`);
const payload = String(markup).match(/^<svg[^>]+?>[^]*<\/svg>$/);
let output = componentTemplate
.replace(/__EXPORT_NAME__/g, exportName)
.replace(/__PAYLOAD__/, payload);

fs.writeFileSync(`${iconsDestFolder}/${iconName}.ts`, output, 'utf-8');

fs.appendFileSync(
indexFile,
`export { ${exportName} } from './svg/${iconName}';\n`
);

fs.appendFileSync(
allFile,
`import { ${exportName} } from './svg/${iconName}';\n`
);

exportAllString += ` ${exportName},\n`;
});

exportAllString += `};\n`;

fs.appendFileSync(
allFile,
exportAllString
);

fs.appendFileSync(
indexFile,
`\nexport { allIcons } from './all';\n`
);
})
.catch((err) => console.log(err));
const componentTemplate = fs.readFileSync(
"src/templates/component.ts.tpl",
"utf-8"
);

return (
Promise.resolve()
// delete feather folder and index
.then(() => del([iconsDestFolder, indexFile, allFile]))
// create destination folder
.then(() => fs.mkdirSync(iconsDestFolder))
.then(() => {
fs.readdirSync(`${iconsSrcFolder}`).forEach((filename) => {
"use strict";
const iconName = stringify(stripExtension(filename));
const exportName = stringify(uppercamelcase(iconName));

const markup = fs.readFileSync(`${iconsSrcFolder}/${filename}`);
let payload = String(markup)
.replace(/width="[0-9]+"/, 'width="100%"')
.replace(/height="[0-9]+"/, 'height="100%"')
.match(/^<svg[^>]+?>[^]*<\/svg>$/);

let output = componentTemplate
.replace(/__EXPORT_NAME__/g, exportName)
.replace(/__PAYLOAD__/, payload);

fs.writeFileSync(`${iconsDestFolder}/${iconName}.ts`, output, "utf-8");

fs.appendFileSync(
indexFile,
`export { ${exportName} } from './svg/${iconName}';\n`
);

fs.appendFileSync(
allFile,
`import { ${exportName} } from './svg/${iconName}';\n`
);

exportAllString += ` ${exportName},\n`;
});

exportAllString += `};\n`;

fs.appendFileSync(allFile, exportAllString);

fs.appendFileSync(indexFile, `\nexport { allIcons } from './all';\n`);
})
.catch((err) => console.log(err))
);

function stripExtension(str) {
return str.substr(0, str.lastIndexOf('.'));
return str.substr(0, str.lastIndexOf("."));
}

function stringify(str) {
return Number(str) ? `_${str}` : str;
}
Loading

0 comments on commit cc1bcc1

Please sign in to comment.