setup-nativewind 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Farhan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # setup-nativewind
2
+
3
+ > One command to set up NativeWind in your Expo or React Native project.
4
+
5
+ ## Usage
6
+ ```bash
7
+ npx setup-nativewind
8
+ ```
9
+
10
+ ## What it does
11
+
12
+ - ✅ Detects your project type (Expo managed, Expo bare, React Native CLI)
13
+ - ✅ Installs `nativewind` and `tailwindcss` automatically
14
+ - ✅ Creates `tailwind.config.js`, `babel.config.js`, `global.css` and other required files
15
+
16
+ ## Supported Project Types
17
+
18
+ | Project Type | Supported |
19
+ |---|---|
20
+ | Expo Managed | ✅ |
21
+ | Expo Bare | ✅ |
22
+ | React Native CLI | ✅ |
23
+
24
+ ## Requirements
25
+
26
+ - Node.js 16+
27
+ - An existing Expo or React Native project
28
+
29
+ ## License
30
+
31
+ MIT
32
+ ```
33
+
34
+ ---
35
+
36
+ ## LICENSE
37
+ ```
38
+ MIT License
39
+
40
+ Copyright (c) 2025 Farhan
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining a copy
43
+ of this software and associated documentation files (the "Software"), to deal
44
+ in the Software without restriction, including without limitation the rights
45
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ copies of the Software, and to permit persons to whom the Software is
47
+ furnished to do so, subject to the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be included in all
50
+ copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58
+ SOFTWARE.
package/bin/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import("../src/index.js");
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "setup-nativewind",
3
+ "version": "1.0.0",
4
+ "description": "One command NativeWind setup for Expo and React Native",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "setup-nativewind": "./bin/index.js"
9
+ },
10
+ "files": [
11
+ "bin",
12
+ "src"
13
+ ],
14
+ "keywords": [
15
+ "nativewind",
16
+ "tailwindcss",
17
+ "react-native",
18
+ "expo",
19
+ "cli",
20
+ "setup"
21
+ ],
22
+ "author": "Your Name <you@email.com>",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/YOUR_USERNAME/setup-nativewind.git"
27
+ },
28
+ "homepage": "https://github.com/YOUR_USERNAME/setup-nativewind#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/YOUR_USERNAME/setup-nativewind/issues"
31
+ },
32
+ "dependencies": {
33
+ "chalk": "^5.3.0",
34
+ "commander": "^11.1.0",
35
+ "fs-extra": "^11.2.0",
36
+ "ora": "^7.0.1",
37
+ "prompts": "^2.4.2"
38
+ }
39
+ }
@@ -0,0 +1,31 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+
4
+ export function detectProjectType() {
5
+ const pkgPath = path.join(process.cwd(), 'package.json');
6
+
7
+ if (!fs.existsSync(pkgPath)) {
8
+ throw new Error('No package.json found. Are you in the root of a React Native project?');
9
+ }
10
+
11
+ const pkg = fs.readJsonSync(pkgPath);
12
+ const deps = {
13
+ ...pkg.dependencies,
14
+ ...pkg.devDependencies,
15
+ };
16
+
17
+ if (deps['expo']) {
18
+ // Check if it's bare or managed
19
+ if (fs.existsSync(path.join(process.cwd(), 'android')) ||
20
+ fs.existsSync(path.join(process.cwd(), 'ios'))) {
21
+ return 'expo-bare';
22
+ }
23
+ return 'expo-managed';
24
+ }
25
+
26
+ if (deps['react-native']) {
27
+ return 'rn-cli';
28
+ }
29
+
30
+ throw new Error('Could not detect project type. Make sure you are in a React Native or Expo project.');
31
+ }
@@ -0,0 +1,25 @@
1
+ import fs from 'fs-extra';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+
7
+ export async function writeConfigFiles(projectType) {
8
+ const templateDir = path.join(__dirname, 'templates', projectType);
9
+ const targetDir = process.cwd();
10
+
11
+ const files = fs.readdirSync(templateDir);
12
+
13
+ for (const file of files) {
14
+ const src = path.join(templateDir, file);
15
+ const dest = path.join(targetDir, file);
16
+
17
+ if (fs.existsSync(dest)) {
18
+ console.warn(`⚠️ Skipping ${file} — already exists`);
19
+ continue;
20
+ }
21
+
22
+ await fs.copy(src, dest);
23
+ console.log(`✅ Created ${file}`);
24
+ }
25
+ }
package/src/index.js ADDED
@@ -0,0 +1,48 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import { detectProjectType } from './detector.js';
4
+ import { installDependencies } from './installer.js';
5
+ import { writeConfigFiles } from './fileWriter.js';
6
+
7
+ async function run() {
8
+ console.log(chalk.bold.cyan('\n🚀 NativeWind Setup\n'));
9
+
10
+ // Step 1: Detect project
11
+ let projectType;
12
+ const detectSpinner = ora('Detecting project type...').start();
13
+ try {
14
+ projectType = detectProjectType();
15
+ detectSpinner.succeed(`Detected: ${chalk.green(projectType)}`);
16
+ } catch (err) {
17
+ detectSpinner.fail(err.message);
18
+ process.exit(1);
19
+ }
20
+
21
+ // Step 2: Install dependencies
22
+ const installSpinner = ora('Installing NativeWind & TailwindCSS...').start();
23
+ try {
24
+ installDependencies(projectType);
25
+ installSpinner.succeed('Dependencies installed');
26
+ } catch (err) {
27
+ installSpinner.fail('Installation failed: ' + err.message);
28
+ process.exit(1);
29
+ }
30
+
31
+ // Step 3: Write config files
32
+ const fileSpinner = ora('Creating config files...').start();
33
+ try {
34
+ await writeConfigFiles(projectType);
35
+ fileSpinner.succeed('Config files created');
36
+ } catch (err) {
37
+ fileSpinner.fail('File creation failed: ' + err.message);
38
+ process.exit(1);
39
+ }
40
+
41
+ // Done!
42
+ console.log(chalk.bold.green('\n✅ NativeWind setup complete!\n'));
43
+ console.log(chalk.yellow('Next steps:'));
44
+ console.log(' 1. Import global.css in your root layout');
45
+ console.log(' 2. Start using Tailwind classes in your components\n');
46
+ }
47
+
48
+ run();
@@ -0,0 +1,12 @@
1
+ import { execSync } from 'child_process';
2
+
3
+ const packages = {
4
+ 'expo-managed': 'nativewind tailwindcss',
5
+ 'expo-bare': 'nativewind tailwindcss',
6
+ 'rn-cli': 'nativewind tailwindcss react-native-reanimated react-native-safe-area-context',
7
+ };
8
+
9
+ export function installDependencies(projectType) {
10
+ const pkgs = packages[projectType];
11
+ execSync(`npm install ${pkgs}`, { stdio: 'inherit' });
12
+ }
@@ -0,0 +1,9 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+ return {
4
+ presets: [
5
+ ["babel-preset-expo", { jsxImportSource: "nativewind" }],
6
+ "nativewind/babel",
7
+ ],
8
+ };
9
+ };
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,6 @@
1
+ const { getDefaultConfig } = require("expo/metro-config");
2
+ const { withNativeWind } = require("nativewind/metro");
3
+
4
+ const config = getDefaultConfig(__dirname);
5
+
6
+ module.exports = withNativeWind(config, { input: "./global.css" });
@@ -0,0 +1,11 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: [
4
+ "./app/**/*.{js,jsx,ts,tsx}",
5
+ "./components/**/*.{js,jsx,ts,tsx}",
6
+ "./src/**/*.{js,jsx,ts,tsx}"
7
+ ],
8
+ presets: [require("nativewind/preset")],
9
+ theme: { extend: {} },
10
+ plugins: [],
11
+ };
@@ -0,0 +1,9 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+ return {
4
+ presets: [
5
+ ["babel-preset-expo", { jsxImportSource: "nativewind" }],
6
+ "nativewind/babel",
7
+ ],
8
+ };
9
+ };
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,7 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: ["./app/**/*.{js,jsx,ts,tsx}", "./components/**/*.{js,jsx,ts,tsx}"],
4
+ presets: [require("nativewind/preset")],
5
+ theme: { extend: {} },
6
+ plugins: [],
7
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ presets: ['module:@react-native/babel-preset'],
3
+ plugins: ["nativewind/babel"],
4
+ };
@@ -0,0 +1,3 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
@@ -0,0 +1,8 @@
1
+ const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
2
+ const { withNativeWind } = require("nativewind/metro");
3
+
4
+ const config = mergeConfig(getDefaultConfig(__dirname), {
5
+ /* your custom config */
6
+ });
7
+
8
+ module.exports = withNativeWind(config, { input: "./global.css" });
@@ -0,0 +1,12 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: [
4
+ "./App.{js,jsx,ts,tsx}",
5
+ "./src/**/*.{js,jsx,ts,tsx}",
6
+ "./screens/**/*.{js,jsx,ts,tsx}",
7
+ "./components/**/*.{js,jsx,ts,tsx}"
8
+ ],
9
+ presets: [require("nativewind/preset")],
10
+ theme: { extend: {} },
11
+ plugins: [],
12
+ };