diff --git a/packages/design-tokens/README.md b/packages/design-tokens/README.md index 6390f1b4..2de7e78b 100644 --- a/packages/design-tokens/README.md +++ b/packages/design-tokens/README.md @@ -1,6 +1,6 @@ -# Design Tokens for BC Design System +# Design Tokens for B.C. Design System -[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md) +[![Lifecycle:Maturing](https://img.shields.io/badge/Lifecycle-Maturing-007EC6)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md) This package is used to export and publish design tokens from Figma to npm for the B.C. Design System. The tokens generated by this package are available for install from npm: [@bcgov/design-tokens](https://www.npmjs.com/package/@bcgov/design-tokens) @@ -25,23 +25,28 @@ See `dist/README.md` for how to use the design tokens in your project. 5. Manually update the package version in `dist/package.json`. 6. Run `npm run publish-npm-package` to publish the contents of `dist` to npm. +## Test the build script + +A Node.js test script is included to confirm that the build script runs as intended: `npm run test` + ## Folder structure ``` . -├── CHANGELOG.md - log of notable changes by version -├── README.md - this file -├── build - output of build script from style-dictionary -├── build-output.js - build script -├── dist - published to npm as @bcgov/design-tokens -│   ├── README.md - instructions for using @bcgov/design-tokens -│   ├── cjs - CommonJS tokens -│   ├── cjs-prefixed - CommonJS tokens with "bcds" added -│   ├── css - CSS tokens -│   ├── css-prefixed - CSS tokens with "bcds" added -│   ├── js - ECMAScript Module (ESM) tokens -│   ├── js-prefixed - ESM tokens with "bcds" added -│   └── package.json - package.json for @bcgov/design-tokens -├── input - raw design tokens JSON data from Tokens Studio for Figma -└── package.json - package.json for tokens transformation pipeline +├── CHANGELOG.md - log of notable changes by version +├── README.md - this file +├── build - output of build script from style-dictionary +├── build-output.js - build script +├── build-output.test.js - test suite for build script +├── dist - published to npm as @bcgov/design-tokens +│   ├── README.md - instructions for using @bcgov/design-tokens +│   ├── cjs - CommonJS tokens +│   ├── cjs-prefixed - CommonJS tokens with "bcds" added +│   ├── css - CSS tokens +│   ├── css-prefixed - CSS tokens with "bcds" added +│   ├── js - ECMAScript Module (ESM) tokens +│   ├── js-prefixed - ESM tokens with "bcds" added +│   └── package.json - package.json for @bcgov/design-tokens +├── input - raw design tokens JSON data from Tokens Studio for Figma +└── package.json - package.json for tokens transformation pipeline ``` diff --git a/packages/design-tokens/build-output.test.js b/packages/design-tokens/build-output.test.js index 8b9f1165..d8884ef3 100644 --- a/packages/design-tokens/build-output.test.js +++ b/packages/design-tokens/build-output.test.js @@ -1,23 +1,49 @@ import { exec } from "child_process"; +import { existsSync } from "fs"; import { test } from "node:test"; import assert from "node:assert"; +import { join } from "path"; test("build-output.js should complete without errors", async () => { try { await new Promise((resolve, reject) => { - // Execute the build script using Node.js - exec("node build-output.js", (error, stdout, stderr) => { - // If there was an error, the test should fail - if (error) { - console.error("Error executing build-output.js:", stderr); - return reject(new Error("build-output.js threw an error")); + // Execute the `build` script from package.json, removing the build + // directory contents before running build-output.js. + exec( + "rm -rf build/cjs* && rm -rf build/css* && rm -rf build/js* && node build-output.js", + (error, stdout, stderr) => { + // If there was an error, the test should fail. + if (error) { + console.error("Error executing build-output.js:", stderr); + return reject(new Error("build-output.js threw an error")); + } + console.log("build-output.js executed successfully:", stdout); + resolve(); } - console.log("build-output.js executed successfully:", stdout); - resolve(); - }); + ); }); assert.ok(true); } catch (error) { assert.fail(error.message); } }); + +test("output files should exist after running build-output.js", async () => { + const outputFiles = [ + "build/css/variables.css", + "build/css-prefixed/variables.css", + "build/js/index.js", + "build/js/index.d.ts", + "build/js-prefixed/index.js", + "build/js-prefixed/index.d.ts", + "build/cjs/index.js", + "build/cjs/index.d.ts", + "build/cjs-prefixed/index.js", + "build/cjs-prefixed/index.d.ts", + ]; + + for (const file of outputFiles) { + const filePath = join(process.cwd(), file); + assert.ok(existsSync(filePath), `Expected file ${file} to exist`); + } +});