Skip to content

Commit

Permalink
Remove prettier from build scripts (#3823)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwooding authored Jul 16, 2024
1 parent ceff1ed commit 09268c7
Show file tree
Hide file tree
Showing 937 changed files with 1,566 additions and 1,106 deletions.
3 changes: 3 additions & 0 deletions docs/public/mockServiceWorker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable */
/* tslint:disable */

/**
* Mock Service Worker (1.2.1).
* @see https://github.com/mswjs/msw
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
},
"dependencies": {
"@biomejs/biome": "1.8.3",
"@biomejs/js-api": "^0.6.2",
"@biomejs/wasm-nodejs": "^1.8.3",
"@changesets/cli": "^2.25.2",
"@cypress/code-coverage": "^3.12.35",
"@faker-js/faker": "^8.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/countries/saltCountries.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/countries/saltSharpCountries.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 44 additions & 49 deletions packages/countries/scripts/generateCountrySymbol.mjs
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Biome, Distribution } from "@biomejs/js-api";
import glob from "glob";
import Mustache from "mustache";
import prettier from "prettier";
import { optimize } from "svgo";

import { svgAttributeMap } from "./svgAttributeMap.mjs";

const PRETTIER_SETTINGS = {
parser: "typescript",
useTabs: false,
tabWidth: 2,
printWidth: 80,
endOfLine: "lf",
};
const biome = await Biome.create({
distribution: Distribution.NODE,
});

biome.applyConfiguration({
organizeImports: {
enabled: true,
},
formatter: {
enabled: true,
indentStyle: "space",
},
});

const REPLACE_START = "$START";
const REPLACE_END = "$END";

const GENERATED_WARNING_COMMENT =
"// WARNING: This file was generated by a script. Do not modify it manually\n";
"// WARNING: This file was generated by a script. Do not modify it manually\n\n";
const CSS_GENERATED_WARNING_COMMENT =
"/** WARNING: This file was generated by a script. Do not modify it manually */\n";
"/** WARNING: This file was generated by a script. Do not modify it manually */\n\n";

function countryCodeToComponentName(countryCode) {
return countryCode.replace(/-/g, "_");
}

/** Change kebab casing to Pascal casing */
function pascalCase(str) {
const arr = str.split(" ");
const capital = arr.map(
(item) =>
item.charAt(0).toLocaleUpperCase("en-US") +
item.slice(1).toLocaleLowerCase("en-US"),
);

return capital.join("");
}

// Create the folder for the CountrySymbolComponents
const generateComponentsFolder = (basePath) => {
if (!fs.existsSync(path.join(basePath, "./components/"))) {
Expand Down Expand Up @@ -80,12 +75,12 @@ const generateCssAsBg = ({ basePath, cssOutputPath, fileArg }) => {

const ALL_CSS = `[class*=' saltCountry-'],[class^='saltCountry-'] {background-size: cover;height:var(--salt-size-base, 20px);width:var(--salt-size-base, 20px);}\n`;

const formattedResult = prettier.format(
const formattedResult = biome.formatContent(
CSS_GENERATED_WARNING_COMMENT.concat(ALL_CSS, countryCss),
{ ...PRETTIER_SETTINGS, parser: "css" },
{ filePath: cssOutputPath },
);

fs.writeFileSync(cssOutputPath, formattedResult, {
fs.writeFileSync(cssOutputPath, formattedResult.content, {
encoding: "utf8",
});
};
Expand Down Expand Up @@ -118,12 +113,12 @@ const generateSharpCssAsBg = ({ basePath, cssOutputPath, fileArg }) => {

const ALL_CSS = `[class*=' saltCountrySharp-'],[class^='saltCountrySharp-'] {background-size: cover;height:var(--salt-size-base, 20px);width:calc(var(--salt-size-base, 20px) * 1.44);}\n`;

const formattedResult = prettier.format(
const formattedResult = biome.formatContent(
CSS_GENERATED_WARNING_COMMENT.concat(ALL_CSS, countryCss),
{ ...PRETTIER_SETTINGS, parser: "css" },
{ filePath: cssOutputPath },
);

fs.writeFileSync(cssOutputPath, formattedResult, {
fs.writeFileSync(cssOutputPath, formattedResult.content, {
encoding: "utf8",
});
};
Expand All @@ -147,7 +142,7 @@ const generateCountrySymbolComponents = ({

const fileNames = glob.sync(globPath, options);

fileNames.forEach((fileName) => {
for (const fileName of fileNames) {
const svgString = fs.readFileSync(fileName, "utf-8");

const filenameWithoutExtension = path.parse(fileName).name;
Expand Down Expand Up @@ -347,23 +342,23 @@ const generateCountrySymbolComponents = ({
.replaceAll(`"${REPLACE_START}`, "")
.replaceAll(`${REPLACE_END}"`, "");

const formattedResult = prettier.format(
const formattedResult = biome.formatContent(
GENERATED_WARNING_COMMENT.concat(replacedText),
PRETTIER_SETTINGS,
{ filePath: newFilePath },
);

const formattedSharpResult = prettier.format(
const formattedSharpResult = biome.formatContent(
GENERATED_WARNING_COMMENT.concat(replacedSharpText),
PRETTIER_SETTINGS,
{ filePath: newSharpFilePath },
);

fs.writeFileSync(newFilePath, formattedResult, {
fs.writeFileSync(newFilePath, formattedResult.content, {
encoding: "utf8",
});
fs.writeFileSync(newSharpFilePath, formattedSharpResult, {
fs.writeFileSync(newSharpFilePath, formattedSharpResult.content, {
encoding: "utf8",
});
});
}

return countryMetaMap;
};
Expand All @@ -387,15 +382,15 @@ const generateIndex = ({ countryMetaMap, componentsPath }) => {
"\n",
);

const formattedResult = prettier.format(joinedText, PRETTIER_SETTINGS);

const outputFile = path.join(componentsPath, "index.ts");

const formattedResult = biome.formatContent(joinedText, {
filePath: outputFile,
});

console.log("creating index at:", outputFile);

fs.writeFile(outputFile, formattedResult, { encoding: "utf8" }, (err) => {
if (err) return console.log(err);
});
fs.writeFileSync(outputFile, formattedResult.content, { encoding: "utf8" });
};

// Generate countryMetaMap for use in stories and by consumers to map code to countryMeta
Expand Down Expand Up @@ -429,11 +424,11 @@ const generateCountryMetaMap = ({ countryMetaMap, basePath }) => {
endText,
].join("\n");

const formattedResult = prettier.format(joinedText, PRETTIER_SETTINGS);

fs.writeFile(outputFile, formattedResult, { encoding: "utf8" }, (err) => {
if (err) return console.log(err);
const formattedResult = biome.formatContent(joinedText, {
filePath: outputFile,
});

fs.writeFileSync(outputFile, formattedResult.content, { encoding: "utf8" });
};

// generate lazyMap for use in the LazyCountrySymbol component
Expand Down Expand Up @@ -467,11 +462,11 @@ const generateLazyMap = ({ countryMetaMap, basePath }) => {
lazyMapText.join("\n"),
].join("\n");

const formattedResult = prettier.format(joinedText, PRETTIER_SETTINGS);

fs.writeFile(outputFile, formattedResult, { encoding: "utf8" }, (err) => {
if (err) return console.log(err);
const formattedResult = biome.formatContent(joinedText, {
filePath: outputFile,
});

fs.writeFileSync(outputFile, formattedResult.content, { encoding: "utf8" });
};

// Run the script
Expand Down
3 changes: 1 addition & 2 deletions packages/countries/scripts/templateCountrySymbol.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { forwardRef } from "react";
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";

import { CountrySymbol, CountrySymbolProps } from "../country-symbol";
import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";

export type {{componentName}}Props = CountrySymbolProps;

Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AD.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AD_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AE.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AE_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AF.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AF_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AG.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AG_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AI.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AI_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AL.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AL_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AM.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AM_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AO.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AO_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AQ.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AQ_Sharp.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
4 changes: 2 additions & 2 deletions packages/countries/src/components/AR.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useId } from "@salt-ds/core";
import { clsx } from "clsx";
// WARNING: This file was generated by a script. Do not modify it manually

import { useId } from "@salt-ds/core";
import { forwardRef } from "react";

import { CountrySymbol, type CountrySymbolProps } from "../country-symbol";
Expand Down
Loading

0 comments on commit 09268c7

Please sign in to comment.