Skip to content

Commit 904244a

Browse files
committed
refactor(ui-scripts): refactor scss generator code and add debug logging
The debug statements help to investigate flaky CI builds that fail with "JSON5: invalid end of input at 1:1" Also remove 'fse', since the erro seems to be that 'styleDictionarySource' is not created in some cases
1 parent 2f8daaf commit 904244a

File tree

4 files changed

+89
-74
lines changed

4 files changed

+89
-74
lines changed

package-lock.json

Lines changed: 25 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ui-scripts/lib/build/generate-all-tokens.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
import path from 'path'
26+
import fs from 'fs'
2627
import { error } from '@instructure/command-utils'
2728
import { handleMapJSTokensToSource } from '../utils/handle-map-js-tokens-to-source.js'
2829
import { handleGenerateTokens } from '../utils/handle-generate-tokens.js'
@@ -90,7 +91,21 @@ export default {
9091
? path.join(themePath, outputDir, themeKey)
9192
: path.join(themePath, outputDir)
9293
const sourcePath = path.join(outputPath, 'source.json')
93-
94+
// this is just a debug code to find the JSON error here that occurs only in CI
95+
// eslint-disable-next-line no-console
96+
console.log(
97+
'!!!!! starting',
98+
themeKey,
99+
sourceTokens,
100+
outputPath,
101+
sourcePath,
102+
fs.existsSync(sourcePath)
103+
)
104+
// eslint-disable-next-line no-console
105+
console.log(
106+
'!!!! styleDictionarySource',
107+
JSON.stringify(styleDictionarySource)?.substring(0, 400)
108+
)
94109
generators.push(
95110
handleGenerateTokens({
96111
themeKey,

packages/ui-scripts/lib/utils/handle-generate-tokens.js

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,61 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import fse from 'fs-extra'
2625
import path from 'path'
2726
import StyleDictionary from 'style-dictionary'
27+
import fs from 'fs'
2828

2929
export async function handleGenerateTokens({
3030
themeKey,
3131
sourcePath,
3232
styleDictionarySource,
3333
outputPath
3434
}) {
35-
return fse
36-
.outputFile(sourcePath, JSON.stringify(styleDictionarySource))
37-
.then(() => {
38-
const dictionary = new StyleDictionary({
39-
source: [sourcePath],
40-
platforms: {
41-
scss: {
42-
transformGroup: 'scss',
43-
prefix: 'instui-' + themeKey,
44-
buildPath: path.join(outputPath, 'scss/'),
45-
files: [
46-
{
47-
destination: '_variables.scss',
48-
format: 'scss/variables'
49-
}
50-
]
35+
const dir = path.dirname(sourcePath)
36+
if (!fs.existsSync(dir)) {
37+
fs.mkdirSync(dir, { recursive: true })
38+
}
39+
fs.writeFileSync(sourcePath, JSON.stringify(styleDictionarySource))
40+
// this is just a debug code to find the JSON error here that occurs only in CI
41+
// eslint-disable-next-line no-console
42+
console.log(
43+
'!!!! handleGenerateTokens',
44+
sourcePath,
45+
fs.existsSync(sourcePath),
46+
JSON.stringify(styleDictionarySource)?.substring(0, 400)
47+
)
48+
const dictionary = new StyleDictionary({
49+
source: [sourcePath],
50+
platforms: {
51+
scss: {
52+
transformGroup: 'scss',
53+
prefix: 'instui-' + themeKey,
54+
buildPath: path.join(outputPath, 'scss/'),
55+
files: [
56+
{
57+
destination: '_variables.scss',
58+
format: 'scss/variables'
5159
}
52-
// TODO: Revisit the best way to distribute tokens for vanilla JS
53-
// js: {
54-
// transformGroup: 'js',
55-
// buildPath: path.join(outputPath, 'js/'),
56-
// files: [
57-
// {
58-
// destination: 'umd.js',
59-
// format: 'javascript/umd'
60-
// },
61-
// {
62-
// destination: 'es6.js',
63-
// format: 'javascript/es6'
64-
// }
65-
// ]
66-
// }
67-
}
68-
})
69-
return dictionary.buildAllPlatforms()
70-
})
71-
.then((builds) => {
72-
return builds
73-
})
60+
]
61+
}
62+
// TODO: Revisit the best way to distribute tokens for vanilla JS
63+
// js: {
64+
// transformGroup: 'js',
65+
// buildPath: path.join(outputPath, 'js/'),
66+
// files: [
67+
// {
68+
// destination: 'umd.js',
69+
// format: 'javascript/umd'
70+
// },
71+
// {
72+
// destination: 'es6.js',
73+
// format: 'javascript/es6'
74+
// }
75+
// ]
76+
// }
77+
}
78+
})
79+
dictionary.buildAllPlatforms().then((builds) => {
80+
return builds
81+
})
7482
}

packages/ui-scripts/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
"@lerna/project": "^6.4.1",
2727
"dotenv": "^16.4.7",
2828
"find-up": "^7.0.0",
29-
"fs-extra": "^11.2.0",
3029
"http-server": "^14.1.1",
3130
"jscodeshift": "^0.16.1",
3231
"karma-cli": "^2.0.0",
3332
"lerna": "^8.1.9",
3433
"lodash.isplainobject": "^4.0.6",
3534
"mocha": "^10.7.3",
3635
"semver": "^7.6.3",
37-
"style-dictionary": "4.1.2",
36+
"style-dictionary": "4.4.0",
3837
"webpack-cli": "^5.1.4",
3938
"webpack-dev-server": "^5.1.0",
4039
"yargs": "^17.7.2"

0 commit comments

Comments
 (0)