Skip to content

Commit

Permalink
fixed reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoloza committed Oct 21, 2024
1 parent f3a8fdc commit 4ec6a68
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/create/src/utilImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { scratchUtils, scratchSystem, set } from '@symbo.ls/scratch'
export { scratchUtils, scratchSystem, set }
export * from '@domql/utils'
export * from '@symbo.ls/utils'
export { init, reInit, applyCSS } from '@symbo.ls/init'
export { init, reinit, applyCSS } from '@symbo.ls/init'
export * from '@domql/report'
export * from '@domql/router'
19 changes: 12 additions & 7 deletions packages/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import DYNAMIC_JSON from './dynamic.json'

const CONFIG = getActiveConfig()

const mergeWithLocalFile = (config = CONFIG, RC_FILE) => {
const rcfile = isObject(RC_FILE) ? RC_FILE : DYNAMIC_JSON || {}
const mergeWithLocalFile = (config = CONFIG, options) => {
const rcfile = isObject(options.localFile) ? options.localFile : DYNAMIC_JSON || {}
const clonedFile = deepClone(rcfile.designSystem || {})
return deepMerge(config, clonedFile)
}
Expand All @@ -35,7 +35,7 @@ const SET_OPTIONS = {

export const init = (config, options = SET_OPTIONS) => {
const emotion = options.emotion || defaultEmotion
const resultConfig = mergeWithLocalFile(config || {})
const resultConfig = mergeWithLocalFile(config || {}, options)

const conf = set({
verbose: options.verbose,
Expand Down Expand Up @@ -76,15 +76,20 @@ const UPDATE_OPTIONS = {
emotion: defaultEmotion
}

export const reInit = (config, RC_FILE, options = UPDATE_OPTIONS) => {
export const reinit = (config, options = UPDATE_OPTIONS) => {
const emotion = options.emotion || defaultEmotion
const resultConfig = mergeWithLocalFile(config || {}, RC_FILE)
const resultConfig = mergeWithLocalFile(config || {}, options)
const prevStyles = document.querySelector('[data-emotion="smbls"]')
console.log(prevStyles)
const conf = set({
verbose: false,
...resultConfig
})
emotion.injectGlobal({ ':root': conf.CSS_VARS })
emotion.injectGlobal(conf.RESET)
if (!options.preventInject) {
emotion.injectGlobal({ ':root': conf.CSS_VARS })
emotion.injectGlobal(conf.RESET)
}
return conf
}

export const applyCSS = (styles, options = UPDATE_OPTIONS) => {
Expand Down
1 change: 1 addition & 0 deletions packages/smbls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"module": "index.js",
"files": [
"index.js",
"package.json",
"dist"
],
"dependencies": {
Expand Down

0 comments on commit 4ec6a68

Please sign in to comment.