Skip to content

Commit

Permalink
feat: build theme-data and type-declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Jun 7, 2022
1 parent fe9309b commit 42d4cab
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
!.figmaexportrc.js
theme-data.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/dist/
/toucan.css
/index.css
/theme-data.js
/theme-data.d.ts
/coverage/
yarn-error.log
33 changes: 33 additions & 0 deletions lib/build-theme-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'path';
import fs from 'fs/promises';
import { fileURLToPath } from 'url';
import fse from 'fs-extra';
import { stripIndent } from 'common-tags';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

const outputFile = 'theme-data.js';
const outputDeclarationsFile = 'theme-data.d.ts';
const themeJsonPath = path.join(__dirname, '..', 'themes.json');

async function build() {
let json = await fse.readJSON(themeJsonPath);

await fs.writeFile(
path.join(__dirname, '..', outputFile),
stripIndent`
export default ${JSON.stringify(json, null, 2)};
`
);

await fs.writeFile(
path.join(__dirname, '..', outputDeclarationsFile),
stripIndent`
declare let ThemeData = ${JSON.stringify(json, null, 2)};
export default ThemeData;
`
);
}

build();
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
"index.js",
"index.css",
"themes.json",
"theme-data.js",
"theme-data.d.ts",
"toucan.css",
"plugins/**/*.js"
],
"exports": {
".": "./index.js",
"./themes": "./themes.json",
"./themes.json": "./themes.json",
"./theme-data": "./theme-data.js"
},
"typesVersions": {
"*": {
"theme-data": ["./theme-data.d.ts"]
}
},
"scripts": {
"start": "pnpm run build && npx http-server ./dist",
"build": "npm-run-all clean build:cdn build:alias build:preview",
"build": "npm-run-all clean build:cdn build:alias build:preview build:theme-data",
"build:theme-data": "node ./lib/build-theme-data.mjs",
"build:preview": "node ./lib/build-preview.mjs",
"build:cdn": "NODE_ENV=production tailwind build -i ./lib/index.css -o ./index.css -c ./lib/tailwind.config.cdn.js",
"clean": "rm -f ./toucan.css ./index.css",
Expand Down

0 comments on commit 42d4cab

Please sign in to comment.