-
Notifications
You must be signed in to change notification settings - Fork 1
/
package.json.js
204 lines (173 loc) · 5.85 KB
/
package.json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import * as fs from 'node:fs';
// Generator for package.json (to allow some more convenient syntax, like comments)
// Usage:
// $ node package.json.js # Generates an updated `package.json` file
const packageConfig = {
name: '@fortanix/baklava',
version: '1.0.0-beta-20241206',
license: 'MPL-2.0',
author: 'Fortanix',
description: 'Fortanix Baklava design system',
repository: { type: 'git', url: 'git+https://github.com/fortanix/baklava.git' },
files: [
'src',
'app',
'dist',
'LICENSE',
'CHANGELOG.md',
'README.md',
],
sideEffects: ['*.css'],
type: 'module',
exports: {
'.': {
'types': './dist/baklava.d.ts',
//'require': './dist/baklava.cjs',
'default': './dist/baklava.js',
},
'./styling/variables.scss': {
'default': './src/styling/variables.scss',
},
},
scripts: {
// Utilities
'gen-package': 'node package.json.js', // Update `package.json`
'install-project': 'npm run gen-package && npm install', // Project-specific version of `npm install`
// CLI
'node': 'node --import=tsx',
'repl': 'tsx',
'plop': 'NODE_OPTIONS="--import tsx" plop',
'import': 'tsx scripts/import.ts',
'automate': 'tsx scripts/automate.ts',
// Library
//'lib:build': '',
// App
'serve:dev': 'vite --config=./vite.config.ts serve',
//'build': 'vite --config=./vite.config.ts --emptyOutDir build && cp src/types/vite-env.d.ts dist && echo \'{"name": "@fortanix/baklava","main": "./baklava.js"}\' > dist/package.json',
'build': 'tsc -b && vite --config=./vite.config.ts build',
// Storybook
'storybook:serve': 'storybook dev -p 6006',
'storybook:build': 'storybook build --docs',
'chromatic': 'npx chromatic', // Must be run with `CHROMATIC_PROJECT_TOKEN` env variable (secret)
// Static analysis
'check:types': 'tsc -b',
'lint:style': `stylelint 'src/**/*.scss'`,
'lint:script': 'biome lint',
'lint': 'npm run lint:style && npm run lint:script',
// Test
// Note: use `vitest run --root=. src/...` to run a single test file
//'test': 'vitest run --root=.', // Need to specify `--root=.` since the vite root is set to `./app`
'test': 'npm run check:types && npm run lint:style',
'test-ui': 'vitest --ui',
'coverage': 'vitest run --coverage',
// Shorthands
'start': 'npm run storybook:serve',
// Hooks
'prepare': 'npm run build',
},
// Dev dependencies (only needed when building, or making changes to the code)
devDependencies: {
// CLI
'plop': '^4.0.1',
'tsx': '^4.19.2',
'glob': '^11.0.0',
// Build
'vite': '^5.4.11', // Cannot use vite v6, blocked by https://github.com/privatenumber/vite-css-modules/issues/13
'@vitejs/plugin-react': '^4.3.4',
'vite-plugin-dts': '^4.3.0',
'vite-plugin-lib-inject-css': '^2.1.1',
'vite-plugin-svg-icons': '^2.0.1',
// Static analysis
'typescript': '^5.7.2',
'@types/node': '^22.10.1',
'stylelint': '^16.11.0',
'stylelint-config-standard-scss': '^14.0.0',
'@biomejs/biome': '^1.9.4',
// Testing
'vitest': '^2.1.8',
'@vitest/ui': '^2.1.8',
// Storybook
'storybook': '^8.4.7',
'@storybook/react': '^8.4.7',
'@storybook/react-vite': '^8.4.7',
'@storybook/blocks': '^8.4.7',
'@storybook/test': '^8.4.7',
'@storybook/addon-essentials': '^8.4.7',
'@storybook/addon-a11y': '^8.4.7',
'@storybook/addon-interactions': '^8.4.7',
'@storybook/addon-links': '^8.4.7',
'@storybook/addon-storysource': '^8.4.7',
'@storybook/addon-designs': '^8.0.4',
'chromatic': '^11.20.0',
'@chromatic-com/storybook': '^3.2.2', // Chromatic integration for Storybook
//'storybook-addon-pseudo-states': '^3.1.1',
'storybook-dark-mode': '^4.0.2',
'@percy/cli': '^1.30.4',
'@percy/storybook': '^6.0.3',
// Styling
'vite-css-modules': '^1.6.0',
'typescript-plugin-css-modules': '^5.0.1',
'sass-embedded': '^1.82.0',
'postcss-color-contrast': '^1.1.0',
'lightningcss': '^1.28.2',
// React
'@types/react': '^19.0.1',
'@types/react-dom': '^19.0.1',
},
// Dependencies needed when running the generated build
dependencies: {
// Utilities
'date-fns': '^4.1.0',
'message-tag': '^0.10.0',
// React
'classnames': '^2.5.1',
'react': '^19.0.0',
'react-dom': '^19.0.0',
'react-error-boundary': '^4.1.2',
'@floating-ui/react': '^0.26.28',
'react-toastify': '^10.0.6',
'effect': '^3.11.3',
'react-hook-form': '^7.54.0',
'optics-ts': '^2.4.1',
},
peerDependencies: {
'react': '>= 19.0.0',
'react-dom': '>= 19.0.0',
},
peerDependenciesMeta: {},
overrides: {
// Issue: https://github.com/storybookjs/addon-designs/issues/246
'@storybook/addon-designs': {
'react': '$react',
'react-dom': '$react-dom',
},
// Issue: https://github.com/storybookjs/icons/issues/34
'@storybook/icons': {
'react': '$react',
'react-dom': '$react-dom',
},
},
};
const makePackageJson = () => {
const packageJson = {
// http://stackoverflow.com/questions/14221579/how-do-i-add-comments-to-package-json
'//': 'NOTE: This is a generated file. Do not edit this file directly, edit package.json.js instead.',
...packageConfig,
};
/*
const packageJsonCurrent = (() => {
try {
return JSON.parse(fs.readFileSync('./package.json'));
} catch (error) {
return null;
}
})();
// Inherit the version from the existing `package.json`, to allow facilitate version bumps through CI
if (packageJsonCurrent?.version && typeof packageJson.version !== 'string') {
packageJson.version = packageJsonCurrent.version;
}
*/
return packageJson;
};
// Write to `package.json`
fs.writeFileSync('./package.json', JSON.stringify(makePackageJson(), null, 2) + '\n');