unframer 2.7.7 → 2.7.9
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 +5 -1
- package/dist/babel-plugin-imports.d.ts +21 -0
- package/dist/babel-plugin-imports.d.ts.map +1 -0
- package/dist/babel-plugin-imports.js +375 -0
- package/dist/babel-plugin-imports.js.map +1 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -11
- package/dist/cli.js.map +1 -1
- package/dist/css.d.ts.map +1 -1
- package/dist/css.js +4 -3
- package/dist/css.js.map +1 -1
- package/dist/exporter.d.ts.map +1 -1
- package/dist/exporter.js +57 -30
- package/dist/exporter.js.map +1 -1
- package/dist/framer.d.ts.map +1 -1
- package/dist/framer.js +56 -1850
- package/dist/framer.js.map +1 -1
- package/dist/renamer.d.ts +12 -0
- package/dist/renamer.d.ts.map +1 -0
- package/dist/renamer.js +169 -0
- package/dist/renamer.js.map +1 -0
- package/esm/babel-plugin-imports.d.ts +21 -0
- package/esm/babel-plugin-imports.d.ts.map +1 -0
- package/esm/babel-plugin-imports.js +344 -0
- package/esm/babel-plugin-imports.js.map +1 -0
- package/esm/cli.d.ts.map +1 -1
- package/esm/cli.js +2 -11
- package/esm/cli.js.map +1 -1
- package/esm/css.d.ts.map +1 -1
- package/esm/css.js +3 -2
- package/esm/css.js.map +1 -1
- package/esm/exporter.d.ts.map +1 -1
- package/esm/exporter.js +55 -28
- package/esm/exporter.js.map +1 -1
- package/esm/framer.d.ts.map +1 -1
- package/esm/framer.js +57 -1850
- package/esm/framer.js.map +1 -1
- package/esm/renamer.d.ts +12 -0
- package/esm/renamer.d.ts.map +1 -0
- package/esm/renamer.js +140 -0
- package/esm/renamer.js.map +1 -0
- package/package.json +5 -4
- package/src/babel-plugin-imports.ts +441 -0
- package/src/cli.tsx +2 -12
- package/src/css.ts +3 -2
- package/src/exporter.ts +64 -29
- package/src/framer.js +61 -1896
- package/src/renamer.ts +184 -0
package/src/css.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import dedent from 'dedent'
|
|
1
|
+
import dedent from 'string-dedent'
|
|
2
2
|
import { ComponentFont } from './framer.js'
|
|
3
3
|
|
|
4
4
|
function deduplicateByKey<T>(arr: T[], key: (k: T) => string): T[] {
|
|
@@ -92,7 +92,8 @@ export function getFontsStyles(_fontsDefs: ComponentFontBundle[]) {
|
|
|
92
92
|
str += dedent`
|
|
93
93
|
@font-face {
|
|
94
94
|
font-family: '${x.family}';
|
|
95
|
-
src: url('${x.url}');\n
|
|
95
|
+
src: url('${x.url}');\n
|
|
96
|
+
`
|
|
96
97
|
if (x.style) {
|
|
97
98
|
str += ` font-style: ${x.style};\n`
|
|
98
99
|
}
|
package/src/exporter.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { BuildResult, context } from 'esbuild'
|
|
2
|
+
import {
|
|
3
|
+
babelPluginDeduplicateImports,
|
|
4
|
+
babelPluginJsxTransform,
|
|
5
|
+
} from './babel-plugin-imports.js'
|
|
6
|
+
|
|
2
7
|
import { Config } from './cli'
|
|
3
8
|
import url from 'url'
|
|
4
9
|
|
|
@@ -8,7 +13,7 @@ import dprint from 'dprint-node'
|
|
|
8
13
|
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill'
|
|
9
14
|
|
|
10
15
|
import { exec } from 'child_process'
|
|
11
|
-
import dedent from 'dedent'
|
|
16
|
+
import dedent from 'string-dedent'
|
|
12
17
|
import fs from 'fs'
|
|
13
18
|
import path from 'path'
|
|
14
19
|
import {
|
|
@@ -32,6 +37,7 @@ import {
|
|
|
32
37
|
combinedCSSRules,
|
|
33
38
|
} from './framer.js'
|
|
34
39
|
import { logger, spinner, terminalMarkdown } from './utils.js'
|
|
40
|
+
import { transform } from '@babel/core'
|
|
35
41
|
|
|
36
42
|
function validateUrl(url: string) {
|
|
37
43
|
try {
|
|
@@ -152,11 +158,26 @@ export async function bundle({
|
|
|
152
158
|
.readFile(file.path, 'utf-8')
|
|
153
159
|
.catch(() => null)
|
|
154
160
|
|
|
161
|
+
// let res = transform(file.text || '', {
|
|
162
|
+
// babelrc: false,
|
|
163
|
+
// sourceType: 'module',
|
|
164
|
+
// plugins: [
|
|
165
|
+
// babelPluginDeduplicateImports,
|
|
166
|
+
|
|
167
|
+
// babelPluginJsxTransform(),
|
|
168
|
+
// ],
|
|
169
|
+
// filename: 'x.js',
|
|
170
|
+
// compact: true,
|
|
171
|
+
// sourceMaps: false,
|
|
172
|
+
// })
|
|
173
|
+
// let inputCode = res!.code!
|
|
174
|
+
let inputCode = file.text
|
|
175
|
+
|
|
155
176
|
let codeNew =
|
|
156
177
|
`// @ts-nocheck\n` +
|
|
157
178
|
`/* eslint-disable */\n` +
|
|
158
179
|
'/* This file was generated by Unframer, do not edit manually */\n' +
|
|
159
|
-
dprint.format(
|
|
180
|
+
dprint.format('file.jsx', inputCode, {
|
|
160
181
|
lineWidth: 140,
|
|
161
182
|
quoteStyle: 'alwaysSingle',
|
|
162
183
|
trailingCommas: 'always',
|
|
@@ -171,10 +192,7 @@ export async function bundle({
|
|
|
171
192
|
const lines = findRelativeLinks(codeNew)
|
|
172
193
|
if (lines.length) {
|
|
173
194
|
spinner.error(
|
|
174
|
-
`found broken links for ${path.relative(
|
|
175
|
-
out,
|
|
176
|
-
file.path,
|
|
177
|
-
)}, don't use relative links in Framer components`,
|
|
195
|
+
`found broken links for ${path.relative(out, file.path)}`,
|
|
178
196
|
)
|
|
179
197
|
lines.forEach((line) => {
|
|
180
198
|
logger.log(`${path.resolve(out, file.path)}:${line + 1}`)
|
|
@@ -329,17 +347,21 @@ export async function bundle({
|
|
|
329
347
|
console.log()
|
|
330
348
|
console.log()
|
|
331
349
|
|
|
332
|
-
let
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
350
|
+
let exampleComponent = result?.components?.sort((a, b) => {
|
|
351
|
+
const aVariants = getVariantsFromPropControls(a.propertyControls)
|
|
352
|
+
const bVariants = getVariantsFromPropControls(b.propertyControls)
|
|
353
|
+
const aHasBreakpoints = (aVariants?.breakpoints?.length || 0) >= 2
|
|
354
|
+
const bHasBreakpoints = (bVariants?.breakpoints?.length || 0) >= 2
|
|
355
|
+
|
|
356
|
+
// Sort components with breakpoints first
|
|
357
|
+
if (aHasBreakpoints && !bHasBreakpoints) return -1
|
|
358
|
+
if (!aHasBreakpoints && bHasBreakpoints) return 1
|
|
359
|
+
|
|
360
|
+
// Within each group, prefer components with example properties
|
|
338
361
|
const aProp = findExampleProperty(a.propertyControls)
|
|
339
362
|
const bProp = findExampleProperty(b.propertyControls)
|
|
340
363
|
return (bProp ? 1 : 0) - (aProp ? 1 : 0)
|
|
341
|
-
})
|
|
342
|
-
let exampleComponent = withBreakpoints?.[0]
|
|
364
|
+
})?.[0]
|
|
343
365
|
if (!exampleComponent) {
|
|
344
366
|
logger.log(
|
|
345
367
|
`No example component found with breakpoints, using random example`,
|
|
@@ -365,22 +387,31 @@ export async function bundle({
|
|
|
365
387
|
const variants = getVariantsFromPropControls(
|
|
366
388
|
exampleComponent?.propertyControls,
|
|
367
389
|
)
|
|
368
|
-
const
|
|
369
|
-
if (!breakpoints) {
|
|
370
|
-
return
|
|
371
|
-
}
|
|
390
|
+
const outDir = path.posix.relative(process.cwd(), out)
|
|
372
391
|
logger.log(
|
|
373
392
|
'exampleComponent?.propertyControls',
|
|
374
393
|
exampleComponent?.propertyControls,
|
|
375
394
|
)
|
|
376
|
-
const
|
|
377
|
-
lg: breakpoints[1],
|
|
378
|
-
base: breakpoints[0],
|
|
379
|
-
}
|
|
380
|
-
let prop =
|
|
395
|
+
const prop =
|
|
381
396
|
findExampleProperty(exampleComponent?.propertyControls) ||
|
|
382
397
|
'exampleFramerVariable'
|
|
383
|
-
const
|
|
398
|
+
const responsiveComponent = (() => {
|
|
399
|
+
const breakpoints = variants?.breakpoints
|
|
400
|
+
if (!breakpoints?.length) {
|
|
401
|
+
return ''
|
|
402
|
+
}
|
|
403
|
+
const variantsExample = {
|
|
404
|
+
lg: breakpoints[1],
|
|
405
|
+
base: breakpoints[0],
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return dedent`
|
|
409
|
+
<${exampleComponent?.componentName}.Responsive
|
|
410
|
+
${prop}='example'
|
|
411
|
+
variants={${JSON.stringify(variantsExample || {})}}
|
|
412
|
+
/>
|
|
413
|
+
`
|
|
414
|
+
})()
|
|
384
415
|
console.log(
|
|
385
416
|
terminalMarkdown(dedent`
|
|
386
417
|
# How to use the Framer components
|
|
@@ -408,10 +439,10 @@ export async function bundle({
|
|
|
408
439
|
${prop}='example'
|
|
409
440
|
style={{ width: '100%' }}
|
|
410
441
|
/>
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
442
|
+
${responsiveComponent
|
|
443
|
+
.split('\n')
|
|
444
|
+
.map((line, i) => (!i ? line : ' ' + line))
|
|
445
|
+
.join('\n')}
|
|
415
446
|
</div>
|
|
416
447
|
);
|
|
417
448
|
};
|
|
@@ -422,6 +453,7 @@ export async function bundle({
|
|
|
422
453
|
To style components you can pass a \`style\` or \`className\` prop (but remember to use !important to increase the specificity).
|
|
423
454
|
|
|
424
455
|
Read more on GitHub: https://github.com/remorses/unframer
|
|
456
|
+
|
|
425
457
|
`),
|
|
426
458
|
)
|
|
427
459
|
return result
|
|
@@ -697,12 +729,15 @@ export async function extractPropControlsUnsafe(
|
|
|
697
729
|
unframer: url.pathToFileURL(require.resolve('../esm/index.js')).href,
|
|
698
730
|
react: url.pathToFileURL(require.resolve('react')).href,
|
|
699
731
|
'react-dom': url.pathToFileURL(require.resolve('react-dom')).href,
|
|
732
|
+
'react/jsx-runtime': url.pathToFileURL(
|
|
733
|
+
require.resolve('react/jsx-runtime'),
|
|
734
|
+
).href,
|
|
700
735
|
})
|
|
701
736
|
let stdout = await new Promise<string>((res, rej) => {
|
|
702
737
|
let childProcess = exec(
|
|
703
738
|
`${JSON.stringify(
|
|
704
739
|
nodePath,
|
|
705
|
-
)} --input-type=module --loader ${require.resolve(
|
|
740
|
+
)} --no-warnings --input-type=module --loader ${require.resolve(
|
|
706
741
|
'../dist/unframer-loader.js',
|
|
707
742
|
)} -e ${JSON.stringify(code)}`,
|
|
708
743
|
{
|