Skip to content

Commit

Permalink
Upgrade sveltekit out of alpha version and optimise code a bit to be …
Browse files Browse the repository at this point in the history
…less hacky
  • Loading branch information
RobBrazier committed Mar 3, 2023
1 parent 3f1b832 commit 2524d98
Show file tree
Hide file tree
Showing 1,588 changed files with 2,658 additions and 1,734 deletions.
10 changes: 6 additions & 4 deletions .semaphore/generate-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const svgfont2js = patch('./node_modules/svgfont2js/index.js', [
}
]);

const iconTemplate = `const <%= name %> = <%= data %>;
const iconTemplate = `const <%= name %>: Record<string, IconData> = <%= data %>;
export default <%= name %>;`;
const icons = svgfont2js(
fs.readFileSync(
Expand Down Expand Up @@ -87,7 +87,7 @@ for (const i in icons) {
};
const variableName = convertStringToVariable(name);
const contents = _.template(iconTemplate)({data: stringify(data), name: variableName});
fs.writeFileSync(path.join(sourceDir, `${variableName}.js`), contents);
fs.writeFileSync(path.join(sourceDir, `${variableName}.ts`), contents);
fs.writeFileSync(path.join(sourceDir, `${variableName}.json`), JSON.stringify(data));
filenames.push(variableName);
}
Expand All @@ -104,19 +104,21 @@ function convertStringToVariable(str) {
}

let index = '';
let iconsTs = '';
let iconIndex = [];
for (const i in filenames) {
if (Object.prototype.hasOwnProperty.call(filenames, i)) {
const filename = filenames[i];
let dataContents = fs.readFileSync(path.join(sourceDir, `${filename}.json`)).toString();
console.log(dataContents);
let fileData = JSON.parse(dataContents);
index += `export { default as ${convertStringToVariable(filename)} } from './${filename}';\n`;
iconsTs += `export const ${convertStringToVariable(filename)}: Record<string, IconData> = ${dataContents};\n`;
iconIndex.push({
fileName: filename,
iconName: Object.keys(fileData)[0]
})
}
}
fs.writeFileSync(path.join(sourceDir, 'index.js'), index);
fs.writeFileSync(path.join(sourceDir, 'index.ts'), index);
fs.writeFileSync(path.join(sourceDir, 'icons.ts'), iconsTs);
fs.writeFileSync(path.join(sourceDir, 'icons.json'), JSON.stringify(iconIndex, null, 2));
140 changes: 122 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"author": "Rob Brazier",
"license": "MIT",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit sync && svelte-kit package",
"preview": "svelte-kit preview",
"dev": "vite dev",
"build": "vite build",
"package": "svelte-kit sync && svelte-package",
"preview": "vite preview",
"icons": "node .semaphore/generate-icons",
"lint": "eslint ./src/**/*.{svelte,js}",
"test": "npm run lint",
Expand All @@ -31,8 +31,9 @@
],
"devDependencies": {
"@fortawesome/free-regular-svg-icons": "^5.10.1",
"@sveltejs/adapter-static": "^1.0.0-next.26",
"@sveltejs/kit": "^1.0.0-next.240",
"@sveltejs/adapter-static": "2.0.1",
"@sveltejs/kit": "1.9.2",
"@sveltejs/package": "1.0.2",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@typescript-eslint/parser": "^5.3.0",
"acorn": "^8.0.2",
Expand Down Expand Up @@ -63,5 +64,9 @@
},
"peerDependencies": {
"svelte": "^3.43.1"
},
"dependencies": {
"@fortawesome/fontawesome-common-types": "^6.3.0",
"@fortawesome/fontawesome-svg-core": "^6.3.0"
}
}
File renamed without changes.
20 changes: 20 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/// <reference types="@sveltejs/kit" />

interface IconPath {
id?: string
d: string
style?: string
stroke?: string
}

interface IconPolygon {
points: string,
style?: string
}

interface IconData {
width: number
height: number
paths?: IconPath[]
polygons?: IconPolygon[]
raw?: string
}
Loading

0 comments on commit 2524d98

Please sign in to comment.