tailwind-react-setup 1.0.1 → 1.1.1
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/bin/index.js +21 -36
- package/package.json +35 -12
- package/src/install.js +7 -0
- package/src/modifyCSS.js +16 -0
- package/src/modifyVite.js +59 -0
- package/src/utils.js +0 -0
package/bin/index.js
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { execSync } from "child_process";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import ora from "ora";
|
|
6
3
|
import chalk from "chalk";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
fs.appendFileSync(
|
|
26
|
-
cssPath,
|
|
27
|
-
`
|
|
28
|
-
@tailwind base;
|
|
29
|
-
@tailwind components;
|
|
30
|
-
@tailwind utilities;
|
|
31
|
-
`
|
|
32
|
-
);
|
|
33
|
-
console.log(chalk.green("Tailwind CSS imported successfully!"));
|
|
34
|
-
} else {
|
|
35
|
-
console.log(chalk.red("index.css not found!"));
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import { installPackages } from "../src/install.js";
|
|
6
|
+
import { modifyViteConfig } from "../src/modifyVite.js";
|
|
7
|
+
import { modifyCSS } from "../src/modifyCSS.js";
|
|
8
|
+
|
|
9
|
+
async function run() {
|
|
10
|
+
const spinner = ora("Starting Tailwind setup...").start();
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
await installPackages();
|
|
14
|
+
await modifyViteConfig();
|
|
15
|
+
await modifyCSS();
|
|
16
|
+
|
|
17
|
+
spinner.succeed(chalk.green("Tailwind setup completed successfully 🚀"));
|
|
18
|
+
} catch (err) {
|
|
19
|
+
spinner.fail(chalk.red("Setup failed"));
|
|
20
|
+
console.error(err.message);
|
|
21
|
+
process.exit(1);
|
|
36
22
|
}
|
|
23
|
+
}
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
spinner.fail("Error installing Tailwind");
|
|
40
|
-
}
|
|
25
|
+
run();
|
package/package.json
CHANGED
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwind-react-setup",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Production-grade Tailwind auto setup for Vite React projects",
|
|
6
5
|
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"tailwind-react-setup": "./bin/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
7
13
|
"scripts": {
|
|
8
|
-
"
|
|
14
|
+
"start": "node bin/index.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"vite",
|
|
19
|
+
"tailwind",
|
|
20
|
+
"cli",
|
|
21
|
+
"automation",
|
|
22
|
+
"setup"
|
|
23
|
+
],
|
|
24
|
+
"author": "Aashish Prasad",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/YOUR_GITHUB_USERNAME/tailwind-react-setup.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/YOUR_GITHUB_USERNAME/tailwind-react-setup/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/YOUR_GITHUB_USERNAME/tailwind-react-setup#readme",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
9
36
|
},
|
|
10
|
-
"keywords": [],
|
|
11
|
-
"author": "",
|
|
12
|
-
"license": "ISC",
|
|
13
37
|
"dependencies": {
|
|
38
|
+
"@babel/parser": "^7.29.0",
|
|
14
39
|
"chalk": "^5.6.2",
|
|
15
|
-
"
|
|
16
|
-
"ora": "^9.3.0"
|
|
17
|
-
|
|
18
|
-
"bin": {
|
|
19
|
-
"tailwind-react-setup": "./bin/index.js"
|
|
40
|
+
"execa": "^9.6.1",
|
|
41
|
+
"ora": "^9.3.0",
|
|
42
|
+
"recast": "^0.23.11"
|
|
20
43
|
}
|
|
21
44
|
}
|
package/src/install.js
ADDED
package/src/modifyCSS.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export async function modifyCSS() {
|
|
5
|
+
const cssPath = path.join(process.cwd(), "src", "App.css");
|
|
6
|
+
|
|
7
|
+
if (!fs.existsSync(cssPath)) {
|
|
8
|
+
throw new Error("App.css not found");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const content = fs.readFileSync(cssPath, "utf-8");
|
|
12
|
+
|
|
13
|
+
if (!content.includes('@import "tailwindcss"')) {
|
|
14
|
+
fs.writeFileSync(cssPath, `@import "tailwindcss";\n${content}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import recast from "recast";
|
|
4
|
+
import parser from "@babel/parser";
|
|
5
|
+
|
|
6
|
+
export async function modifyViteConfig() {
|
|
7
|
+
const vitePath = path.join(process.cwd(), "vite.config.js");
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(vitePath)) {
|
|
10
|
+
throw new Error("vite.config.js not found");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const code = fs.readFileSync(vitePath, "utf-8");
|
|
14
|
+
|
|
15
|
+
const ast = recast.parse(code, {
|
|
16
|
+
parser: {
|
|
17
|
+
parse(source) {
|
|
18
|
+
return parser.parse(source, {
|
|
19
|
+
sourceType: "module",
|
|
20
|
+
plugins: ["jsx"],
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const b = recast.types.builders;
|
|
27
|
+
|
|
28
|
+
let hasImport = false;
|
|
29
|
+
|
|
30
|
+
recast.types.visit(ast, {
|
|
31
|
+
visitImportDeclaration(path) {
|
|
32
|
+
if (path.node.source.value === "@tailwindcss/vite") {
|
|
33
|
+
hasImport = true;
|
|
34
|
+
}
|
|
35
|
+
this.traverse(path);
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
if (!hasImport) {
|
|
40
|
+
ast.program.body.unshift(
|
|
41
|
+
b.importDeclaration(
|
|
42
|
+
[b.importDefaultSpecifier(b.identifier("tailwindcss"))],
|
|
43
|
+
b.literal("@tailwindcss/vite")
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
recast.types.visit(ast, {
|
|
49
|
+
visitArrayExpression(path) {
|
|
50
|
+
if (path.parent.node.key?.name === "plugins") {
|
|
51
|
+
path.node.elements.unshift(b.callExpression(b.identifier("tailwindcss"), []));
|
|
52
|
+
}
|
|
53
|
+
this.traverse(path);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const output = recast.print(ast).code;
|
|
58
|
+
fs.writeFileSync(vitePath, output);
|
|
59
|
+
}
|
package/src/utils.js
ADDED
|
File without changes
|