Files
webstudio/packages/css-data/bin/css-to-ws.ts
T
Oleg Isonen 7f1af26ad8 fix: fix webflow html embed preset styles (#3791)
Fixes
https://discord.com/channels/955905230107738152/1265688229529784320

wf embed is display block by default, but we have nothing that would set
this because our own preset sets display to content

## Description

1. What is this PR about (link the issue and add a short description)

## Steps for reproduction

1 copy code embed/html embed from webflow
2.paste it and see the display is block, not contents

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-07-25 21:26:11 +02:00

48 lines
1.4 KiB
TypeScript
Executable File

#!/usr/bin/env tsx
import { parseArgs, type ParseArgsConfig } from "node:util";
import * as path from "node:path";
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { parseCss } from "../src/parse-css";
const cliOptions = {
allowPositionals: true,
strict: true,
} as const satisfies ParseArgsConfig;
const cliArgs = parseArgs({ args: process.argv.slice(2), ...cliOptions });
if (cliArgs.positionals.length < 2) {
console.error("Please provide the source and destination paths");
process.exit(1);
}
const sourcePath = path.resolve(process.cwd(), cliArgs.positionals[0]);
const destinationPath = path.resolve(process.cwd(), cliArgs.positionals[1]);
const objectGroupBy = <Item>(list: Item[], by: (item: Item) => string) => {
const records: Record<string, Item[]> = {};
for (const item of list) {
const key = by(item);
let list = records[key];
if (list === undefined) {
list = [];
records[key] = list;
}
list.push(item);
}
return records;
};
const css = readFileSync(sourcePath, "utf8");
const parsed = parseCss(css);
const records = objectGroupBy(parsed, (item) => item.selector);
mkdirSync(path.dirname(destinationPath), { recursive: true });
const code = `/* eslint-disable */
/* This file was generated by css-to-ws.ts */
export const styles = ${JSON.stringify(records, null, 2)};
`;
writeFileSync(destinationPath, code, "utf8");
console.info("✅ CSS parsed and Webstudio Data generated");