Skip to content
Permalink
Browse files

fix: import fonts into views

  • Loading branch information...
dariocravero committed May 25, 2019
1 parent 130f8f5 commit 6e861c100294925c9348fdca80b5bf57c9d46afe
Showing with 21 additions and 231 deletions.
  1. +4 −3 fonts.js
  2. +2 −1 maybe-morph.js
  3. +2 −0 morph-all-views.js
  4. +2 −2 morph/react-dom.js
  5. +2 −2 morph/react-native.js
  6. +1 −1 morph/react-native/morph-fonts.js
  7. +5 −7 morph/react/get-dependencies.js
  8. +3 −215 watch.js
@@ -4,6 +4,7 @@ import morphFontAsReactDom from './morph/react-dom/morph-font.js'
import morphFontAsReactNative from './morph/react-native/morph-fonts.js'
import path from 'path'
import sort from 'bubblesort'
import relativise from './relativise.js'

let morphFont = {
'react-dom': morphFontAsReactDom,
@@ -44,8 +45,6 @@ export async function morphAllFonts({ as, customFonts, src, viewsToFiles }) {
let fontsDirectory = path.join(src, 'Fonts')
let fontsInUse = new Set()

console.log('fontsDirectory', fontsDirectory)

let mapCustomFont = file => ({
type: FONT_TYPES[path.extname(file)],
file: file.replace(fontsDirectory, '.'),
@@ -65,7 +64,6 @@ export async function morphAllFonts({ as, customFonts, src, viewsToFiles }) {
let customFontSources = []
if (customFonts.has(font)) {
customFontSources = [...customFonts.get(font)].map(mapCustomFont)
console.log(customFontSources)
}

let code = morphFont[as](
@@ -96,4 +94,7 @@ let FONT_TYPES = {
'.woff2': 'woff2',
}

export let makeGetFontImport = src => (font, view) =>
`import "${relativise(view.file, path.join(src, 'Fonts', `${font}.js`))}"`

// let isFont = f => Object.keys(FONT_TYPES).includes(path.extname(f))
@@ -5,6 +5,7 @@ import prettier from 'prettier'

export default async function maybeMorph({
as,
getFontImport,
getSystemImport,
local,
track,
@@ -15,7 +16,7 @@ export default async function maybeMorph({
}) {
try {
let result = morphers[as]({
// getFont,
getFontImport,
getSystemImport,
// isStory,
local,
@@ -2,6 +2,7 @@ import maybeMorph from './maybe-morph.js'

export default async function morphAllViews({
as,
getFontImport,
getSystemImport,
local,
track,
@@ -13,6 +14,7 @@ export default async function morphAllViews({

await maybeMorph({
as,
getFontImport,
getSystemImport,
local,
track,
@@ -17,7 +17,7 @@ let imports = {
}

export default ({
getFont = () => false,
getFontImport,
getSystemImport,
isStory = () => true,
local,
@@ -45,7 +45,7 @@ export default ({
dependencies: new Set(),
flow: null,
flowSetState: false,
getFont,
getFontImport: font => getFontImport(font, view),
getStyleForProperty,
getValueForProperty,
hasRefs: false,
@@ -17,7 +17,7 @@ let imports = {
}

export default ({
getFont = () => false,
getFontImport,
getImport,
isStory = () => true,
local,
@@ -40,7 +40,7 @@ export default ({
animated: new Set(),
images: [],
dependencies: new Set(),
getFont,
getFontImport: font => getFontImport(font, view),
getStyleForProperty,
getValueForProperty,
hasRefs: false,
@@ -1,6 +1,6 @@
export default (font, sources) => {
return `export default {}`
// TODO implement
return `export default "${font.id}"`

// let body = `export default {\n`
// fonts.forEach(font => {
@@ -64,14 +64,12 @@ export default (state, getImport) => {
})

if (state.isReactNative) {
state.getFont(state.fonts)
// TODO fonts in RN
// state.getFont(state.fonts)
} else {
state.fonts.forEach(usedFont => {
let font = state.getFont(usedFont)
if (font) {
dependencies.push(`import "${font}"`)
}
})
state.fonts.forEach(usedFont =>
dependencies.push(state.getFontImport(usedFont.id))
)
}

// TODO we probably want to check that the file exists and do something if it

0 comments on commit 6e861c1

Please sign in to comment.
You can’t perform that action at this time.