@triptease/icons 1.3.11 → 1.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @triptease/icons
2
2
 
3
+ ## 1.3.12
4
+
5
+ ### Patch Changes
6
+
7
+ - ff30018: Generate an icon manifest at build time and expose to NPM
8
+
3
9
  ## 1.3.11
4
10
 
5
11
  ### Patch Changes
@@ -817,6 +817,12 @@
817
817
  }
818
818
  ]
819
819
  },
820
+ {
821
+ "kind": "javascript-module",
822
+ "path": "scripts/generate-icon-manifest/generate-icon-manifest.ts",
823
+ "declarations": [],
824
+ "exports": []
825
+ },
820
826
  {
821
827
  "kind": "javascript-module",
822
828
  "path": "src/icons/account.ts",
@@ -2937,6 +2943,190 @@
2937
2943
  }
2938
2944
  }
2939
2945
  ]
2946
+ },
2947
+ {
2948
+ "kind": "javascript-module",
2949
+ "path": "scripts/generate-icon-manifest/__mocks__/account.js",
2950
+ "declarations": [
2951
+ {
2952
+ "kind": "variable",
2953
+ "name": "account",
2954
+ "type": {
2955
+ "text": "string"
2956
+ },
2957
+ "default": "'<svg></svg>'"
2958
+ }
2959
+ ],
2960
+ "exports": [
2961
+ {
2962
+ "kind": "js",
2963
+ "name": "account",
2964
+ "declaration": {
2965
+ "name": "account",
2966
+ "module": "scripts/generate-icon-manifest/__mocks__/account.js"
2967
+ }
2968
+ }
2969
+ ]
2970
+ },
2971
+ {
2972
+ "kind": "javascript-module",
2973
+ "path": "scripts/generate-icon-manifest/__mocks__/align-center.js",
2974
+ "declarations": [
2975
+ {
2976
+ "kind": "variable",
2977
+ "name": "alignCenter",
2978
+ "type": {
2979
+ "text": "string"
2980
+ },
2981
+ "default": "'<svg></svg>'"
2982
+ }
2983
+ ],
2984
+ "exports": [
2985
+ {
2986
+ "kind": "js",
2987
+ "name": "alignCenter",
2988
+ "declaration": {
2989
+ "name": "alignCenter",
2990
+ "module": "scripts/generate-icon-manifest/__mocks__/align-center.js"
2991
+ }
2992
+ }
2993
+ ]
2994
+ },
2995
+ {
2996
+ "kind": "javascript-module",
2997
+ "path": "scripts/generate-icon-manifest/__mocks__/checkbox-checked.js",
2998
+ "declarations": [
2999
+ {
3000
+ "kind": "variable",
3001
+ "name": "checkboxChecked",
3002
+ "type": {
3003
+ "text": "string"
3004
+ },
3005
+ "default": "'<svg></svg>'"
3006
+ }
3007
+ ],
3008
+ "exports": [
3009
+ {
3010
+ "kind": "js",
3011
+ "name": "checkboxChecked",
3012
+ "declaration": {
3013
+ "name": "checkboxChecked",
3014
+ "module": "scripts/generate-icon-manifest/__mocks__/checkbox-checked.js"
3015
+ }
3016
+ }
3017
+ ]
3018
+ },
3019
+ {
3020
+ "kind": "javascript-module",
3021
+ "path": "scripts/generate-icon-manifest/__mocks__/empty-icon.js",
3022
+ "declarations": [],
3023
+ "exports": []
3024
+ },
3025
+ {
3026
+ "kind": "javascript-module",
3027
+ "path": "scripts/generate-icon-manifest/helpers/createManifest.spec.ts",
3028
+ "declarations": [],
3029
+ "exports": []
3030
+ },
3031
+ {
3032
+ "kind": "javascript-module",
3033
+ "path": "scripts/generate-icon-manifest/helpers/createManifest.ts",
3034
+ "declarations": [
3035
+ {
3036
+ "kind": "function",
3037
+ "name": "createManifest",
3038
+ "parameters": [
3039
+ {
3040
+ "name": "MANIFEST_FILE_NAME",
3041
+ "type": {
3042
+ "text": "string"
3043
+ }
3044
+ },
3045
+ {
3046
+ "name": "moduleName",
3047
+ "type": {
3048
+ "text": "string"
3049
+ }
3050
+ },
3051
+ {
3052
+ "name": "packageJsonExports",
3053
+ "type": {
3054
+ "text": "Record<string, string>"
3055
+ }
3056
+ }
3057
+ ]
3058
+ }
3059
+ ],
3060
+ "exports": [
3061
+ {
3062
+ "kind": "js",
3063
+ "name": "createManifest",
3064
+ "declaration": {
3065
+ "name": "createManifest",
3066
+ "module": "scripts/generate-icon-manifest/helpers/createManifest.ts"
3067
+ }
3068
+ }
3069
+ ]
3070
+ },
3071
+ {
3072
+ "kind": "javascript-module",
3073
+ "path": "scripts/generate-icon-manifest/helpers/createTimestamp.spec.ts",
3074
+ "declarations": [],
3075
+ "exports": []
3076
+ },
3077
+ {
3078
+ "kind": "javascript-module",
3079
+ "path": "scripts/generate-icon-manifest/helpers/createTimestamp.ts",
3080
+ "declarations": [
3081
+ {
3082
+ "kind": "function",
3083
+ "name": "createTimestamp"
3084
+ }
3085
+ ],
3086
+ "exports": [
3087
+ {
3088
+ "kind": "js",
3089
+ "name": "createTimestamp",
3090
+ "declaration": {
3091
+ "name": "createTimestamp",
3092
+ "module": "scripts/generate-icon-manifest/helpers/createTimestamp.ts"
3093
+ }
3094
+ }
3095
+ ]
3096
+ },
3097
+ {
3098
+ "kind": "javascript-module",
3099
+ "path": "scripts/generate-icon-manifest/helpers/writeManifest.ts",
3100
+ "declarations": [
3101
+ {
3102
+ "kind": "function",
3103
+ "name": "writeManifest",
3104
+ "parameters": [
3105
+ {
3106
+ "name": "MANIFEST_FILE_PATH",
3107
+ "type": {
3108
+ "text": "string"
3109
+ }
3110
+ },
3111
+ {
3112
+ "name": "manifest",
3113
+ "type": {
3114
+ "text": "Record<string, string>"
3115
+ }
3116
+ }
3117
+ ]
3118
+ }
3119
+ ],
3120
+ "exports": [
3121
+ {
3122
+ "kind": "js",
3123
+ "name": "writeManifest",
3124
+ "declaration": {
3125
+ "name": "writeManifest",
3126
+ "module": "scripts/generate-icon-manifest/helpers/writeManifest.ts"
3127
+ }
3128
+ }
3129
+ ]
2940
3130
  }
2941
3131
  ]
2942
3132
  }
@@ -0,0 +1 @@
1
+ {"account":"@triptease/icons/account.js","alert":"@triptease/icons/alert.js","alignCenter":"@triptease/icons/align-center.js","alignLeft":"@triptease/icons/align-left.js","alignRight":"@triptease/icons/align-right.js","arrowDown":"@triptease/icons/arrow-down.js","arrowLeft":"@triptease/icons/arrow-left.js","arrowRight":"@triptease/icons/arrow-right.js","arrowUp":"@triptease/icons/arrow-up.js","audienceTargeting":"@triptease/icons/audience-targeting.js","bold":"@triptease/icons/bold.js","bulletList":"@triptease/icons/bullet-list.js","button":"@triptease/icons/button.js","calendarIcon":"@triptease/icons/calendar.js","campaigns":"@triptease/icons/campaigns.js","channels":"@triptease/icons/channels.js","checkboxChecked":"@triptease/icons/checkbox-checked.js","chevron":"@triptease/icons/chevron.js","chevronDown":"@triptease/icons/chevron-down.js","chevronRight":"@triptease/icons/chevron-right.js","chevronUp":"@triptease/icons/chevron-up.js","clock":"@triptease/icons/clock.js","close":"@triptease/icons/close.js","cog":"@triptease/icons/cog.js","coin":"@triptease/icons/coin.js","collapsible":"@triptease/icons/collapsible.js","column":"@triptease/icons/column.js","comparison":"@triptease/icons/comparison.js","container":"@triptease/icons/container.js","countdown":"@triptease/icons/countdown.js","dateBoost":"@triptease/icons/date-boost.js","deleteIcon":"@triptease/icons/delete.js","desktop":"@triptease/icons/desktop.js","disabled":"@triptease/icons/disabled.js","dismissible":"@triptease/icons/dismissible.js","divider":"@triptease/icons/divider.js","doubleChevron":"@triptease/icons/double-chevron.js","download":"@triptease/icons/download.js","dropdown":"@triptease/icons/dropdown.js","duplicate":"@triptease/icons/duplicate.js","edit":"@triptease/icons/edit.js","email":"@triptease/icons/email.js","embed":"@triptease/icons/embed.js","experiment":"@triptease/icons/experiment.js","external":"@triptease/icons/external.js","filter":"@triptease/icons/filter.js","gallery":"@triptease/icons/gallery.js","form":"@triptease/icons/form.js","gear":"@triptease/icons/gear.js","globe":"@triptease/icons/globe.js","help":"@triptease/icons/help.js","graph":"@triptease/icons/graph.js","handle":"@triptease/icons/handle.js","home":"@triptease/icons/home.js","horizontal":"@triptease/icons/horizontal.js","hotel":"@triptease/icons/hotel.js","info":"@triptease/icons/info.js","insights":"@triptease/icons/insights.js","italic":"@triptease/icons/italic.js","keyboard":"@triptease/icons/keyboard.js","lightningBolt":"@triptease/icons/lightning-bolt.js","link":"@triptease/icons/link.js","logout":"@triptease/icons/logout.js","messages":"@triptease/icons/messages.js","minus":"@triptease/icons/minus.js","mobile":"@triptease/icons/mobile.js","moveToParent":"@triptease/icons/move-to-parent.js","multiMessage":"@triptease/icons/multi-message.js","newTab":"@triptease/icons/new-tab.js","numberedList":"@triptease/icons/numbered-list.js","pause":"@triptease/icons/pause.js","pauseFilled":"@triptease/icons/pause-filled.js","pieChart":"@triptease/icons/pie-chart.js","plus":"@triptease/icons/plus.js","radioChecked":"@triptease/icons/radio-checked.js","preview":"@triptease/icons/preview.js","redo":"@triptease/icons/redo.js","rename":"@triptease/icons/rename.js","section":"@triptease/icons/section.js","send":"@triptease/icons/send.js","share":"@triptease/icons/share.js","sidebarCollapsed":"@triptease/icons/sidebar-collapsed.js","sidebarExpanded":"@triptease/icons/sidebar-expanded.js","stop":"@triptease/icons/stop.js","stopFilled":"@triptease/icons/stop-filled.js","strikethrough":"@triptease/icons/strikethrough.js","tag":"@triptease/icons/tag.js","target":"@triptease/icons/target.js","templates":"@triptease/icons/templates.js","text":"@triptease/icons/text.js","textInput":"@triptease/icons/text-input.js","tick":"@triptease/icons/tick.js","ticket":"@triptease/icons/ticket.js","treeGraph":"@triptease/icons/tree-graph.js","underline":"@triptease/icons/underline.js","undo":"@triptease/icons/undo.js","unlink":"@triptease/icons/unlink.js","user":"@triptease/icons/user.js","vertical":"@triptease/icons/vertical.js","wallet":"@triptease/icons/wallet.js","warning":"@triptease/icons/warning.js"}
package/package.json CHANGED
@@ -3,12 +3,13 @@
3
3
  "description": "Triptease icon set",
4
4
  "license": "MIT",
5
5
  "author": "@triptease",
6
- "version": "1.3.11",
6
+ "version": "1.3.12",
7
7
  "type": "module",
8
8
  "main": "dist/src/index.js",
9
9
  "module": "dist/src/index.js",
10
10
  "exports": {
11
11
  ".": "./dist/src/index.js",
12
+ "./manifest.json": "./dist/manifest.json",
12
13
  "./account.js": "./dist/src/icons/account.js",
13
14
  "./alert.js": "./dist/src/icons/alert.js",
14
15
  "./align-center.js": "./dist/src/icons/align-center.js",
@@ -113,15 +114,19 @@
113
114
  },
114
115
  "scripts": {
115
116
  "analyze": "cem analyze --litelement",
116
- "build": "yarn build:node && yarn build:web && npm run analyze -- --exclude dist",
117
+ "generate-icon-manifest": "npx tsx scripts/generate-icon-manifest/generate-icon-manifest.ts",
118
+ "build": "yarn build:node && yarn build:web && yarn generate-icon-manifest && npm run analyze -- --exclude dist",
117
119
  "build:node": "tsc",
118
120
  "build:node:watch": "tsc --watch",
119
121
  "build:web": "node ../../scripts/esbuild.mjs",
122
+ "test": "vitest run",
123
+ "test:watch": "vitest",
120
124
  "prepublish": "yarn build:node && npm run analyze -- --exclude dist"
121
125
  },
122
126
  "devDependencies": {
123
127
  "tslib": "^2.6.3",
124
- "typescript": "^5.5.3"
128
+ "typescript": "^5.5.3",
129
+ "vitest": "^4.0.16"
125
130
  },
126
131
  "publishConfig": {
127
132
  "access": "public"
@@ -0,0 +1 @@
1
+ export const account = '<svg></svg>';
@@ -0,0 +1 @@
1
+ export const alignCenter = '<svg></svg>';
@@ -0,0 +1 @@
1
+ export const checkboxChecked = '<svg></svg>';
@@ -0,0 +1 @@
1
+ // File is intentionally empty
@@ -0,0 +1,23 @@
1
+ import { createTimestamp } from './helpers/createTimestamp';
2
+ import { createManifest } from './helpers/createManifest';
3
+ import { writeManifest } from './helpers/writeManifest';
4
+ import packageJson from '../../package.json';
5
+
6
+ const MANIFEST_FILE_NAME = 'manifest.json';
7
+ const MANIFEST_FILE_PATH = `./dist/${MANIFEST_FILE_NAME}`;
8
+
9
+ (async () => {
10
+ try {
11
+ console.info(`${createTimestamp()} 🏗️ Generating icon manifest...`);
12
+ const { name, exports } = packageJson;
13
+ const manifest = await createManifest(MANIFEST_FILE_NAME, name, exports);
14
+ await writeManifest(MANIFEST_FILE_PATH, manifest);
15
+
16
+ console.info(`${createTimestamp()} ✅ Icon manifest generated successfully!`);
17
+ process.exit(0);
18
+ } catch (error) {
19
+ console.error(`${createTimestamp()} ❌ Failed to generate icon manifest:`);
20
+ console.error(error);
21
+ process.exit(1);
22
+ }
23
+ })();
@@ -0,0 +1,40 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createManifest } from './createManifest';
3
+
4
+ const MANIFEST_FILE_NAME = 'manifest.json';
5
+
6
+ describe('createManifest', () => {
7
+ it('should correctly create the manifest', async () => {
8
+ const manifest = await createManifest(MANIFEST_FILE_NAME, 'test-module', {
9
+ './account.js': '../../scripts/generate-icon-manifest/__mocks__/account.js',
10
+ './align-center.js': '../../scripts/generate-icon-manifest/__mocks__/align-center.js',
11
+ './checkbox-checked.js': '../../scripts/generate-icon-manifest/__mocks__/checkbox-checked.js',
12
+ });
13
+
14
+ expect(manifest).toEqual({
15
+ account: 'test-module/account.js',
16
+ alignCenter: 'test-module/align-center.js',
17
+ checkboxChecked: 'test-module/checkbox-checked.js',
18
+ });
19
+ });
20
+
21
+ it('should error if the icon file is empty', async () => {
22
+ await expect(
23
+ createManifest(MANIFEST_FILE_NAME, 'test-module', {
24
+ './empty-icon.js': '../../scripts/generate-icon-manifest/__mocks__/empty-icon.js',
25
+ })
26
+ ).rejects.toThrowError(
27
+ 'Failed to generate manifest for ./empty-icon.js: The imported icon file does not export a variable.'
28
+ );
29
+ });
30
+
31
+ it('should error if the icon file cannot be found', async () => {
32
+ await expect(
33
+ createManifest(MANIFEST_FILE_NAME, 'test-module', {
34
+ './missing-icon.js': './missing-icon.js',
35
+ })
36
+ ).rejects.toThrowError(
37
+ /^Failed to generate manifest for \.\/missing-icon\.js: Cannot find module '.*' imported from .*$/
38
+ );
39
+ });
40
+ });
@@ -0,0 +1,35 @@
1
+ export const createManifest = async (
2
+ MANIFEST_FILE_NAME: string,
3
+ moduleName: string,
4
+ packageJsonExports: Record<string, string>
5
+ ) => {
6
+ const EXCLUDE_LIST = ['.', `./${MANIFEST_FILE_NAME}`];
7
+ const manifest: Record<string, string> = {};
8
+
9
+ const exportsArray = Object.entries(packageJsonExports).filter(([key]) => !EXCLUDE_LIST.includes(key));
10
+
11
+ await Promise.all(
12
+ exportsArray.map(async ([key, value]) => {
13
+ try {
14
+ const module = await import(`../../../${value}`);
15
+
16
+ const [varName] = Object.entries(module).flat();
17
+ // 'typeof' is needed to appease TypeScript, exported variable names will always be strings
18
+ if (!varName || typeof varName !== 'string')
19
+ throw new Error('The imported icon file does not export a variable.');
20
+
21
+ const importPath = key.split('./')[1];
22
+ manifest[varName] = `${moduleName}/${importPath}`;
23
+ } catch (error) {
24
+ // Catch is needed to catch failed imports and throw a more descriptive error message
25
+ if (error instanceof Error) {
26
+ throw new Error(`Failed to generate manifest for ${key}: ${error.message}`);
27
+ } else {
28
+ throw error;
29
+ }
30
+ }
31
+ })
32
+ );
33
+
34
+ return manifest;
35
+ };
@@ -0,0 +1,35 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { createTimestamp } from './createTimestamp';
3
+
4
+ describe('createTimestamp', () => {
5
+ beforeEach(() => {
6
+ // tell vitest we use mocked time
7
+ vi.useFakeTimers();
8
+
9
+ const date = new Date(2000, 1, 1, 13, 30, 10);
10
+ vi.setSystemTime(date);
11
+ });
12
+
13
+ afterEach(() => {
14
+ // restoring date after each test run
15
+ vi.useRealTimers();
16
+ });
17
+
18
+ it('should return a timestamp in the format [HH:mm:ss AM]', () => {
19
+ const date = new Date(2000, 1, 1, 9, 30, 10);
20
+ vi.setSystemTime(date);
21
+
22
+ const timestamp = createTimestamp();
23
+
24
+ expect(timestamp).toEqual('[9:30:10 AM]');
25
+ });
26
+
27
+ it('should return a timestamp in the format [HH:mm:ss PM]', () => {
28
+ const date = new Date(2000, 1, 1, 13, 30, 10);
29
+ vi.setSystemTime(date);
30
+
31
+ const timestamp = createTimestamp();
32
+
33
+ expect(timestamp).toEqual('[1:30:10 PM]');
34
+ });
35
+ });
@@ -0,0 +1 @@
1
+ export const createTimestamp = () => `[${new Date().toLocaleTimeString(undefined, { hour12: true })}]`;
@@ -0,0 +1,9 @@
1
+ import fs from 'fs';
2
+
3
+ export const writeManifest = (MANIFEST_FILE_PATH: string, manifest: Record<string, string>) =>
4
+ new Promise((resolve, reject) => {
5
+ fs.writeFile(MANIFEST_FILE_PATH, JSON.stringify(manifest), (err) => {
6
+ if (err) reject(err);
7
+ resolve(true);
8
+ });
9
+ });
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "outDir": "dist"
6
6
  },
7
7
  "include": ["**/*.ts"],
8
- "exclude": ["node_modules", "test", "dist"]
8
+ "exclude": ["node_modules", "test", "dist", "scripts"]
9
9
  }