Skip to content

Commit

Permalink
fix(cli-utils): cli command was failing
Browse files Browse the repository at this point in the history
  • Loading branch information
acd02 committed Feb 22, 2023
1 parent a7cfc56 commit 719200e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
"license": "MIT",
"scripts": {
"prepare": "husky install",
"postinstall": "lerna run build --scope=@spark-ui/{theme-utils,theme-utils-node}",
"postinstall": "lerna run build --scope=@spark-ui/theme-utils",
"clean": "lerna clean --yes && lerna exec -- rm -rf dist",
"build": "lerna run build",
"build:watch": "lerna run build && lerna watch -- lerna run build --since",
"release": "lerna publish --yes --include-merged-tags --no-verify-access",
"bloop": "npx spark-setup-theme",
"storybook:start": "npx spark-setup-theme && storybook dev -p 6006",
"storybook:build": "storybook build -o dist",
"test": "vitest",
Expand Down
10 changes: 5 additions & 5 deletions packages/utils/cli/bin/spark-setup-theme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ if (!configFile) {
}

const configFilePath = join(process.cwd(), configFile)
const configFileIsInJS = configFile === 'spark.theme.config.js'
const configFileIsMJS = /spark\.theme\.config\.(mjs)$/.test(configFile)

const allowedExtensions = ['.ts', '.mts', '.cts', '.js', '.cjs', '.mjs']
const jsFileExtension = '.js'
const jsFileExtension = '.mjs'
const configFileExtension = extname(configFilePath)
if (!allowedExtensions.includes(configFileExtension)) {
system.exit(`Your spark.theme.config file extension (${configFileExtension}) is not supported.`)
Expand All @@ -36,10 +36,10 @@ if (!allowedExtensions.includes(configFileExtension)) {
const configFileContent = readFileSync(configFilePath, 'utf-8')
const jsCode = transformSync(configFileContent, { loader: 'ts' }).code

const jsFilePath = configFilePath.replace(/\.ts$|\.mts$|\.cts$|\.mjs|\.cjs$/, jsFileExtension)
const jsFilePath = configFilePath.replace(/\.ts$|\.mts$|\.cts$|\.js|\.cjs$/, jsFileExtension)
const jsFileContents = jsCode

if (!configFileIsInJS) writeFileSync(jsFilePath, jsFileContents)
if (!configFileIsMJS) writeFileSync(jsFilePath, jsFileContents)

import(jsFilePath)
.then(module => {
Expand All @@ -53,7 +53,7 @@ import(jsFilePath)
})

child.on('exit', code => {
if (!configFileIsInJS) unlinkSync(jsFilePath)
if (!configFileIsMJS) unlinkSync(jsFilePath)
logger.success(
`✨ Your Spark Tailwind theme config file has been successfully created: ${join(
process.cwd(),
Expand Down
2 changes: 2 additions & 0 deletions packages/utils/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"camel-case": "4.1.2",
"chalk": "5.2.0",
"commander": "10.0.0",
"deepmerge": "4.3.0",
"esbuild": "0.17.8",
"fs-extra": "11.1.0",
"glob": "8.1.0",
"hex-rgb": "5.0.0",
"pascal-case": "3.1.2"
},
"repository": {
Expand Down

0 comments on commit 719200e

Please sign in to comment.