-
Notifications
You must be signed in to change notification settings - Fork 0
/
maybe-morph.js
75 lines (65 loc) · 1.53 KB
/
maybe-morph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import chalk from 'chalk'
import morphers from './morphers.js'
// import prettier from 'prettier'
export default function maybeMorph({
as,
getFontImport,
getSystemImport,
profile,
src,
tools,
view,
viewsById,
viewsToFiles,
verbose,
designSystemImportRoot,
}) {
let result = null
try {
result = morphers[as]({
getFontImport,
getSystemImport,
profile,
src,
tools,
view,
viewsById,
viewsToFiles,
designSystemImportRoot,
})
view.version++
verbose &&
console.log(
`${chalk.green('M')} ${view.id}@${view.version}:${chalk.dim(view.file)}`
)
return { content: result.code, extraFiles: result.extraFiles }
// return prettier.format(result.code, {
// parser: 'babel',
// singleQuote: true,
// trailingComma: 'es5',
// })
} catch (error) {
console.error(chalk.red('M'), view, error.codeFrame || error)
return {
content: `import { useEffect } from 'react'
export default function ${view.id}() {
useEffect(() => {
console.error({
type: 'morph',
view: '${view.id}',
file: '${view.file}',
todo: "Report to https://github.com/viewstools/morph/issues/new with .view and .view.js files and what changed when it failed. This will help us improve the morpher. Thanks!",
})
}, [])
return "😳 Can't morph '${view.id}'. See console for more details."
}
/*
>>> CODE
${result && result.code.replace(/(\/\*|\*\/)/g, '')}
>>> ERROR
${error.message}
${error.stack}
*/`,
}
}
}