unframer 2.7.5 → 2.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -5
- package/dist/cli.d.ts +14 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -31
- package/dist/cli.js.map +1 -1
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.d.ts.map +1 -1
- package/dist/esbuild.js +15 -1
- package/dist/esbuild.js.map +1 -1
- package/dist/exporter.d.ts +7 -14
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +52 -14
- package/dist/exporter.js.map +1 -1
- package/dist/exporter.test.d.ts +2 -0
- package/dist/exporter.test.d.ts.map +1 -0
- package/dist/exporter.test.js +83 -0
- package/dist/exporter.test.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/unframer-loader.d.ts.map +1 -1
- package/dist/unframer-loader.js +4 -3
- package/dist/unframer-loader.js.map +1 -1
- package/esm/cli.d.ts +14 -0
- package/esm/cli.d.ts.map +1 -1
- package/esm/cli.js +7 -31
- package/esm/cli.js.map +1 -1
- package/esm/esbuild.d.ts +7 -0
- package/esm/esbuild.d.ts.map +1 -1
- package/esm/esbuild.js +13 -0
- package/esm/esbuild.js.map +1 -1
- package/esm/exporter.d.ts +7 -14
- package/esm/exporter.d.ts.map +1 -1
- package/esm/exporter.js +52 -15
- package/esm/exporter.js.map +1 -1
- package/esm/exporter.test.d.ts +2 -0
- package/esm/exporter.test.d.ts.map +1 -0
- package/esm/exporter.test.js +81 -0
- package/esm/exporter.test.js.map +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/unframer-loader.d.ts.map +1 -1
- package/esm/unframer-loader.js +4 -3
- package/esm/unframer-loader.js.map +1 -1
- package/package.json +2 -1
- package/src/cli.tsx +9 -40
- package/src/esbuild.ts +24 -2
- package/src/exporter.test.ts +116 -0
- package/src/exporter.ts +59 -20
- package/src/index.ts +2 -0
- package/src/unframer-loader.ts +7 -3
package/src/exporter.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BuildResult, context } from 'esbuild'
|
|
2
|
+
import { Config } from './cli'
|
|
2
3
|
import url from 'url'
|
|
3
4
|
|
|
4
5
|
import { Sema } from 'async-sema'
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
import {
|
|
22
23
|
esbuildPluginBundleDependencies,
|
|
23
24
|
externalPackages,
|
|
25
|
+
replaceWebPageIds,
|
|
24
26
|
resolveRedirect,
|
|
25
27
|
} from './esbuild'
|
|
26
28
|
import {
|
|
@@ -47,13 +49,17 @@ export type StyleToken = {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
export async function bundle({
|
|
52
|
+
config,
|
|
50
53
|
cwd: out = '',
|
|
51
54
|
watch = false,
|
|
52
|
-
components = {} as Record<string, string>,
|
|
53
|
-
tokens = [] as StyleToken[],
|
|
54
|
-
breakpoints = {} as BreakpointSizes,
|
|
55
55
|
signal = undefined as AbortSignal | undefined,
|
|
56
|
+
}: {
|
|
57
|
+
config: Config
|
|
58
|
+
cwd: string
|
|
59
|
+
watch?: boolean
|
|
60
|
+
signal?: AbortSignal
|
|
56
61
|
}) {
|
|
62
|
+
const { components, breakpoints, tokens, outDir, framerWebPages } = config
|
|
57
63
|
out ||= path.resolve(process.cwd(), 'example')
|
|
58
64
|
out = path.resolve(out)
|
|
59
65
|
try {
|
|
@@ -156,6 +162,12 @@ export async function bundle({
|
|
|
156
162
|
trailingCommas: 'always',
|
|
157
163
|
semiColons: 'always',
|
|
158
164
|
})
|
|
165
|
+
if (framerWebPages?.length) {
|
|
166
|
+
codeNew = replaceWebPageIds({
|
|
167
|
+
code: codeNew,
|
|
168
|
+
elements: framerWebPages,
|
|
169
|
+
})
|
|
170
|
+
}
|
|
159
171
|
const lines = findRelativeLinks(codeNew)
|
|
160
172
|
if (lines.length) {
|
|
161
173
|
spinner.error(
|
|
@@ -236,7 +248,7 @@ export async function bundle({
|
|
|
236
248
|
'/* This file was generated by Unframer, do not edit manually */\n' +
|
|
237
249
|
'/* This css file has all the necessary styles to run all your components */\n' +
|
|
238
250
|
'\n' +
|
|
239
|
-
getStyleTokensCss(tokens) +
|
|
251
|
+
getStyleTokensCss(tokens || []) +
|
|
240
252
|
breakpointsStyles(breakpoints) +
|
|
241
253
|
'\n\n' +
|
|
242
254
|
combinedCSSRules
|
|
@@ -317,11 +329,17 @@ export async function bundle({
|
|
|
317
329
|
console.log()
|
|
318
330
|
console.log()
|
|
319
331
|
|
|
320
|
-
let
|
|
332
|
+
let withBreakpoints = result?.components?.filter((x) => {
|
|
321
333
|
if (!x.propertyControls) return false
|
|
322
334
|
const variants = getVariantsFromPropControls(x.propertyControls)
|
|
323
335
|
return variants?.breakpoints.length >= 2
|
|
324
336
|
})
|
|
337
|
+
withBreakpoints = withBreakpoints?.sort((a, b) => {
|
|
338
|
+
const aProp = findExampleProperty(a.propertyControls)
|
|
339
|
+
const bProp = findExampleProperty(b.propertyControls)
|
|
340
|
+
return (bProp ? 1 : 0) - (aProp ? 1 : 0)
|
|
341
|
+
})
|
|
342
|
+
let exampleComponent = withBreakpoints?.[0]
|
|
325
343
|
if (!exampleComponent) {
|
|
326
344
|
logger.log(
|
|
327
345
|
`No example component found with breakpoints, using random example`,
|
|
@@ -507,10 +525,6 @@ export function getStyleTokensCss(
|
|
|
507
525
|
)
|
|
508
526
|
}
|
|
509
527
|
|
|
510
|
-
function decapitalize(str: string) {
|
|
511
|
-
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
512
|
-
}
|
|
513
|
-
|
|
514
528
|
export function findRelativeLinks(text: string) {
|
|
515
529
|
const regex = /webPageId:\s+/g
|
|
516
530
|
const lines = text.split('\n')
|
|
@@ -661,10 +675,6 @@ function getTokensCss({
|
|
|
661
675
|
|
|
662
676
|
const nodePath = process.argv[0] || 'node'
|
|
663
677
|
|
|
664
|
-
let UNFRAMER_RUNTIME_PATH = url.pathToFileURL(
|
|
665
|
-
require.resolve('../esm/index.js'),
|
|
666
|
-
).href
|
|
667
|
-
|
|
668
678
|
export async function extractPropControlsUnsafe(
|
|
669
679
|
filename,
|
|
670
680
|
name,
|
|
@@ -683,6 +693,11 @@ export async function extractPropControlsUnsafe(
|
|
|
683
693
|
)}); console.log(${propCode}) })`
|
|
684
694
|
|
|
685
695
|
const TIMEOUT = 5 * 1000
|
|
696
|
+
const UNFRAMER_MAP_PACKAGES = JSON.stringify({
|
|
697
|
+
unframer: url.pathToFileURL(require.resolve('../esm/index.js')).href,
|
|
698
|
+
react: url.pathToFileURL(require.resolve('react')).href,
|
|
699
|
+
'react-dom': url.pathToFileURL(require.resolve('react-dom')).href,
|
|
700
|
+
})
|
|
686
701
|
let stdout = await new Promise<string>((res, rej) => {
|
|
687
702
|
let childProcess = exec(
|
|
688
703
|
`${JSON.stringify(
|
|
@@ -693,14 +708,17 @@ export async function extractPropControlsUnsafe(
|
|
|
693
708
|
{
|
|
694
709
|
env: {
|
|
695
710
|
// ...process.env,
|
|
696
|
-
|
|
711
|
+
UNFRAMER_MAP_PACKAGES,
|
|
697
712
|
},
|
|
698
713
|
},
|
|
699
|
-
(err, stdout) => {
|
|
714
|
+
(err, stdout, stderr) => {
|
|
700
715
|
clearTimeout(timer)
|
|
701
716
|
if (err) {
|
|
717
|
+
spinner.error(`error extracting types for ${name}`)
|
|
718
|
+
spinner.error(stderr)
|
|
702
719
|
return rej(err)
|
|
703
720
|
}
|
|
721
|
+
|
|
704
722
|
res(stdout)
|
|
705
723
|
},
|
|
706
724
|
)
|
|
@@ -714,12 +732,15 @@ export async function extractPropControlsUnsafe(
|
|
|
714
732
|
)
|
|
715
733
|
}, TIMEOUT)
|
|
716
734
|
}).catch((e) => {
|
|
717
|
-
spinner.error(`error extracting types for ${name}`)
|
|
718
735
|
logger.log(e.stack)
|
|
719
|
-
|
|
736
|
+
return ''
|
|
720
737
|
})
|
|
721
738
|
|
|
722
|
-
stdout = stdout.split(delimiter)[1]
|
|
739
|
+
stdout = stdout.split(delimiter)[1] || ''
|
|
740
|
+
if (!stdout) {
|
|
741
|
+
return {}
|
|
742
|
+
}
|
|
743
|
+
|
|
723
744
|
// console.log(stdout)
|
|
724
745
|
return safeJsonParse(stdout)
|
|
725
746
|
}
|
|
@@ -788,7 +809,7 @@ export function propControlsToType(controls: PropertyControls, fileName) {
|
|
|
788
809
|
return 'Function'
|
|
789
810
|
}
|
|
790
811
|
}
|
|
791
|
-
let name =
|
|
812
|
+
let name = propCamelCase(value.title || key || '')
|
|
792
813
|
if (!name) {
|
|
793
814
|
return ''
|
|
794
815
|
}
|
|
@@ -990,5 +1011,23 @@ function findExampleProperty(propertyControls?: PropertyControls) {
|
|
|
990
1011
|
return null
|
|
991
1012
|
}
|
|
992
1013
|
|
|
993
|
-
return stringProp[
|
|
1014
|
+
return propCamelCase(stringProp[1]?.title || '')
|
|
1015
|
+
}
|
|
1016
|
+
export function propCamelCase(str: string) {
|
|
1017
|
+
if (!str) {
|
|
1018
|
+
return ''
|
|
1019
|
+
}
|
|
1020
|
+
// Convert dashes to camelCase (e.g. foo-bar -> fooBar)
|
|
1021
|
+
str = str.replace(/-([\w])/g, (g) => g[1].toUpperCase())
|
|
1022
|
+
// Convert underscores to camelCase (e.g. foo_bar -> fooBar)
|
|
1023
|
+
str = str.replace(/_([a-z])/g, (g) => g[1].toUpperCase())
|
|
1024
|
+
// Remove spaces (e.g. "Foo Bar" -> "fooBar")
|
|
1025
|
+
str = str.replace(/\s+(.)/g, (_, c) => c.toUpperCase())
|
|
1026
|
+
// Ensure first character is lowercase
|
|
1027
|
+
str = str[0].toLowerCase() + str.slice(1)
|
|
1028
|
+
// Add underscore prefix if starts with number
|
|
1029
|
+
if (/^\d/.test(str)) {
|
|
1030
|
+
str = '_' + str
|
|
1031
|
+
}
|
|
1032
|
+
return str
|
|
994
1033
|
}
|
package/src/index.ts
CHANGED
package/src/unframer-loader.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
const mapPackages = JSON.parse(process.env.UNFRAMER_MAP_PACKAGES || '{}')
|
|
2
|
+
|
|
1
3
|
export async function resolve(specifier, context, defaultResolve) {
|
|
2
|
-
if (specifier
|
|
4
|
+
if (mapPackages[specifier]) {
|
|
3
5
|
return {
|
|
4
|
-
url:
|
|
5
|
-
format: 'module', // Specify that unframer is an ES module
|
|
6
|
+
url: mapPackages[specifier],
|
|
7
|
+
// format: 'module', // Specify that unframer is an ES module
|
|
6
8
|
shortCircuit: true, // Signal that we're intentionally not calling next hook
|
|
7
9
|
}
|
|
8
10
|
}
|
|
11
|
+
|
|
12
|
+
|
|
9
13
|
return defaultResolve(specifier, context, defaultResolve)
|
|
10
14
|
}
|