Skip to content

Commit

Permalink
fix(cli): resolve eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ruru-m07 committed Aug 11, 2024
1 parent 3eacea6 commit e3bfb72
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 49 deletions.
13 changes: 12 additions & 1 deletion packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
module.exports = {
extends: ["custom/library"],
// Exclude this file from ESLint's list of included files
ignorePatterns: [".eslintrc.cjs", "dist"],
plugins: ["@typescript-eslint/eslint-plugin", "eslint-plugin-tsdoc"],
extends: ["plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
ecmaVersion: 2018,
sourceType: "module",
},
rules: {
// 'tsdoc/syntax': 'warn'
"import/no-relative-packages": "off",
},
};
8 changes: 6 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function init() {
};

// TODO: we'll give the user the option to change this.
let cwd = process.cwd();
const cwd = process.cwd();

preFlight(cwd);
const projectConfig = await getProjectConfig(cwd);
Expand All @@ -62,7 +62,7 @@ export async function init() {
await runInit(cwd, config);
}

let nextSteps = `npx ruru-ui-cli add button `;
const nextSteps = `npx ruru-ui-cli add button `;

note(nextSteps, "Next steps.");

Expand Down Expand Up @@ -173,6 +173,10 @@ export async function promptForConfig(
defaultConfig: Config | null = null,
skip = false,
) {
if (defaultConfig) {
null;
}

const options = await group(
{
typescript: () =>
Expand Down
43 changes: 1 addition & 42 deletions packages/cli/src/utils/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { promises as fs } from "fs";
import { tmpdir } from "os";
import path from "path";
import { Config } from "@/utils/get-config";
import { registryBaseColorSchema } from "@/utils/registry/schema";
import { transformCssVars } from "@/utils/transformers/transform-css-vars";
// import { transformImport } from "@/utils/transformers/transform-import";
// import { transformJsx } from "@/utils/transformers/transform-jsx";
// import { transformRsc } from "@/utils/transformers/transform-rsc";
import { Project, ScriptKind, type SourceFile } from "ts-morph";
import { SourceFile } from "ts-morph";
import { z } from "zod";

import { transformTwPrefixes } from "./transform-tw-prefix";

export type TransformOpts = {
filename: string;
raw: string;
Expand All @@ -24,35 +15,3 @@ export type Transformer<Output = SourceFile> = (
sourceFile: SourceFile;
},
) => Promise<Output>;

const transformers: Transformer[] = [
// transformImport,
// transformRsc,
transformCssVars,
transformTwPrefixes,
];

const project = new Project({
compilerOptions: {},
});

async function createTempSourceFile(filename: string) {
const dir = await fs.mkdtemp(path.join(tmpdir(), "shadcn-"));
return path.join(dir, filename);
}

// export async function transform(opts: TransformOpts) {
// const tempFile = await createTempSourceFile(opts.filename);
// const sourceFile = project.createSourceFile(tempFile, opts.raw, {
// scriptKind: ScriptKind.TSX,
// });

// for (const transformer of transformers) {
// transformer({ sourceFile, ...opts });
// }

// return await transformJsx({
// sourceFile,
// ...opts,
// });
// }
4 changes: 2 additions & 2 deletions packages/cli/src/utils/transformers/transform-css-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function splitClassName(className: string): (string | null)[] {

const parts: (string | null)[] = [];
// First we split to find the alpha.
let [rest, alpha] = className.split("/");
const [rest, alpha] = className.split("/");

// Check if rest has a colon.
if (!rest.includes(":")) {
Expand Down Expand Up @@ -73,7 +73,7 @@ export function applyColorMapping(
const classNames = input.split(" ");
const lightMode = new Set<string>();
const darkMode = new Set<string>();
for (let className of classNames) {
for (const className of classNames) {
const [variant, value, modifier] = splitClassName(className);
const prefix = PREFIXES.find((prefix) => value?.startsWith(prefix));
if (!prefix) {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/utils/transformers/transform-tw-prefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const transformTwPrefixes: Transformer = async ({

// Find all jsx attributes with the name className.
sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach((node) => {
// @ts-expect-error - TS doesn't know that getName() returns a string.
if (node.getName() === "className") {
// className="..."
if (node.getInitializer()?.isKind(SyntaxKind.StringLiteral)) {
Expand Down Expand Up @@ -112,6 +113,7 @@ export const transformTwPrefixes: Transformer = async ({
}

// classNames={...}
// @ts-expect-error - TS doesn't know that getName() returns a string.
if (node.getName() === "classNames") {
if (node.getInitializer()?.isKind(SyntaxKind.JsxExpression)) {
node
Expand Down Expand Up @@ -173,7 +175,7 @@ export const transformTwPrefixes: Transformer = async ({
export function applyPrefix(input: string, prefix: string = "") {
const classNames = input.split(" ");
const prefixed: string[] = [];
for (let className of classNames) {
for (const className of classNames) {
const [variant, value, modifier] = splitClassName(className);
if (variant) {
modifier
Expand All @@ -190,7 +192,7 @@ export function applyPrefix(input: string, prefix: string = "") {

export function applyPrefixesCss(css: string, prefix: string) {
const lines = css.split("\n");
for (let line of lines) {
for (const line of lines) {
if (line.includes("@apply")) {
const originalTWCls = line.replace("@apply", "").trim();
const prefixedTwCls = applyPrefix(originalTWCls, prefix);
Expand Down

0 comments on commit e3bfb72

Please sign in to comment.