Skip to content

Commit 4b2297b

Browse files
committed
refactor(ui-scripts): trying to fix JSON error bug
1 parent adf5872 commit 4b2297b

File tree

4 files changed

+63
-23
lines changed

4 files changed

+63
-23
lines changed

package-lock.json

Lines changed: 0 additions & 14 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: 10 additions & 4 deletions
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'
@@ -91,13 +92,18 @@ export default {
9192
: path.join(themePath, outputDir)
9293
const sourcePath = path.join(outputPath, 'source.json')
9394
// eslint-disable-next-line no-console
94-
console.log('!!!!! starting', themeKey, sourceTokens)
95-
// eslint-disable-next-line no-console
96-
console.log('!!!!tokens', JSON.stringify(tokens).substring(0, 600))
95+
console.log(
96+
'!!!!! starting',
97+
themeKey,
98+
sourceTokens,
99+
outputPath,
100+
sourcePath,
101+
fs.existsSync(sourcePath)
102+
)
97103
// eslint-disable-next-line no-console
98104
console.log(
99105
'!!!!styleDictionarySource',
100-
JSON.stringify(styleDictionarySource).substring(0, 600)
106+
JSON.stringify(styleDictionarySource).substring(0, 400)
101107
)
102108
generators.push(
103109
handleGenerateTokens({

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

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,70 @@
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+
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+
//fse.outputFileSync(sourcePath, JSON.stringify(styleDictionarySource))
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'
59+
}
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+
})
82+
/*
3583
return fse
3684
.outputFile(sourcePath, JSON.stringify(styleDictionarySource))
3785
.then(() => {
86+
// eslint-disable-next-line no-console
87+
console.log("!!!! init StyleDictionary", JSON.stringify(styleDictionarySource)?.substring(0, 500))
88+
3889
const dictionary = new StyleDictionary({
3990
source: [sourcePath],
4091
platforms: {
@@ -66,11 +117,9 @@ export async function handleGenerateTokens({
66117
// }
67118
}
68119
})
69-
// eslint-disable-next-line no-console
70-
console.log('Building tokens for', themeKey)
71120
return dictionary.buildAllPlatforms()
72121
})
73122
.then((builds) => {
74123
return builds
75-
})
124+
})*/
76125
}

packages/ui-scripts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
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",

0 commit comments

Comments
 (0)