react-apps-ui 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/dist/index.js +78 -0
- package/package.json +28 -0
- package/src/index.ts +99 -0
- package/tsconfig.json +11 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
// base URL to GitHub Raw folder
|
|
13
|
+
const REGISTRY_URL = "https://raw.githubusercontent.com/anandvyas2021/react-apps-ui-registry/refs/heads/prod/__registry__";
|
|
14
|
+
const program = new commander_1.Command();
|
|
15
|
+
program
|
|
16
|
+
.name("react-apps-ui")
|
|
17
|
+
.description("Add high-quality components to your React Native app")
|
|
18
|
+
.version("1.0.0");
|
|
19
|
+
// --- THE INIT COMMAND ---
|
|
20
|
+
program
|
|
21
|
+
.command("init")
|
|
22
|
+
.description("Configure your Expo project and install the ThemeProvider")
|
|
23
|
+
.action(async () => {
|
|
24
|
+
console.log(chalk_1.default.blue("Welcome to React Apps UI!\n"));
|
|
25
|
+
// Ask the user which engine they want
|
|
26
|
+
const response = await (0, prompts_1.default)({
|
|
27
|
+
type: "select",
|
|
28
|
+
name: "engine",
|
|
29
|
+
message: "Which styling engine are you using?",
|
|
30
|
+
choices: [
|
|
31
|
+
{
|
|
32
|
+
title: "StyleSheet (Zero dependencies)",
|
|
33
|
+
value: "mobile-stylesheet",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
title: "NativeWind (Tailwind CSS)",
|
|
37
|
+
value: "mobile-nativewind",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
});
|
|
41
|
+
if (!response.engine) {
|
|
42
|
+
console.log(chalk_1.default.red("Initialization cancelled."));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// 2. USE THE REGISTRY_URL to fetch the correct JSON manifest
|
|
46
|
+
const manifestUrl = `${REGISTRY_URL}/${response.engine}.json`;
|
|
47
|
+
console.log(chalk_1.default.dim(`\nFetching registry from GitHub...`));
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(manifestUrl);
|
|
50
|
+
if (!res.ok)
|
|
51
|
+
throw new Error(`Failed to fetch registry: ${res.statusText}`);
|
|
52
|
+
const registry = await res.json();
|
|
53
|
+
// 3. Find the "theme" component inside the giant JSON
|
|
54
|
+
const themeComponent = registry.find((item) => item.name === "theme");
|
|
55
|
+
if (!themeComponent) {
|
|
56
|
+
console.log(chalk_1.default.red("Error: Could not find 'theme' in the registry."));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log(chalk_1.default.green(`ā Found theme provider. Installing...`));
|
|
60
|
+
// 4. Loop through the files (tokens.ts and ThemeProvider.tsx) and create them!
|
|
61
|
+
for (const file of themeComponent.files) {
|
|
62
|
+
// file.target is exactly what we wrote earlier (e.g., "theme/tokens.ts")
|
|
63
|
+
const targetPath = path_1.default.join(process.cwd(), file.target);
|
|
64
|
+
// Ensure the folder exists (e.g., creates the "theme/" folder if it doesn't exist)
|
|
65
|
+
fs_1.default.mkdirSync(path_1.default.dirname(targetPath), { recursive: true });
|
|
66
|
+
// Write the raw React code to their hard drive!
|
|
67
|
+
fs_1.default.writeFileSync(targetPath, file.content, "utf-8");
|
|
68
|
+
console.log(chalk_1.default.green(`Created ${file.target}`));
|
|
69
|
+
}
|
|
70
|
+
console.log(chalk_1.default.blue("\nš Initialization complete!"));
|
|
71
|
+
console.log(chalk_1.default.dim("Wrap your app in the <ThemeProvider> to get started."));
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.log(chalk_1.default.red(`\nFailed to initialize:`));
|
|
75
|
+
console.error(error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-apps-ui",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The React Native UI CLI",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"react-apps-ui": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"dev": "tsx src/index.ts",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"chalk": "^5.6.2",
|
|
19
|
+
"commander": "^14.0.3",
|
|
20
|
+
"prompts": "^2.4.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.20.2",
|
|
24
|
+
"@types/prompts": "^2.4.9",
|
|
25
|
+
"tsx": "^4.23.13",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import prompts from "prompts";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
// base URL to GitHub Raw folder
|
|
9
|
+
const REGISTRY_URL =
|
|
10
|
+
"https://raw.githubusercontent.com/anandvyas2021/react-apps-ui-registry/refs/heads/prod/__registry__";
|
|
11
|
+
|
|
12
|
+
const program = new Command();
|
|
13
|
+
|
|
14
|
+
program
|
|
15
|
+
.name("react-apps-ui")
|
|
16
|
+
.description("Add high-quality components to your React Native app")
|
|
17
|
+
.version("1.0.0");
|
|
18
|
+
|
|
19
|
+
// --- THE INIT COMMAND ---
|
|
20
|
+
program
|
|
21
|
+
.command("init")
|
|
22
|
+
.description("Configure your Expo project and install the ThemeProvider")
|
|
23
|
+
.action(async () => {
|
|
24
|
+
console.log(chalk.blue("Welcome to React Apps UI!\n"));
|
|
25
|
+
|
|
26
|
+
// Ask the user which engine they want
|
|
27
|
+
const response = await prompts({
|
|
28
|
+
type: "select",
|
|
29
|
+
name: "engine",
|
|
30
|
+
message: "Which styling engine are you using?",
|
|
31
|
+
choices: [
|
|
32
|
+
{
|
|
33
|
+
title: "StyleSheet (Zero dependencies)",
|
|
34
|
+
value: "mobile-stylesheet",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: "NativeWind (Tailwind CSS)",
|
|
38
|
+
value: "mobile-nativewind",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (!response.engine) {
|
|
44
|
+
console.log(chalk.red("Initialization cancelled."));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 2. USE THE REGISTRY_URL to fetch the correct JSON manifest
|
|
49
|
+
const manifestUrl = `${REGISTRY_URL}/${response.engine}.json`;
|
|
50
|
+
console.log(chalk.dim(`\nFetching registry from GitHub...`));
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
const res = await fetch(manifestUrl);
|
|
54
|
+
if (!res.ok)
|
|
55
|
+
throw new Error(`Failed to fetch registry: ${res.statusText}`);
|
|
56
|
+
|
|
57
|
+
const registry = await res.json();
|
|
58
|
+
|
|
59
|
+
// 3. Find the "theme" component inside the giant JSON
|
|
60
|
+
const themeComponent = registry.find(
|
|
61
|
+
(item: any) => item.name === "theme",
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (!themeComponent) {
|
|
65
|
+
console.log(
|
|
66
|
+
chalk.red("Error: Could not find 'theme' in the registry."),
|
|
67
|
+
);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
console.log(chalk.green(`ā Found theme provider. Installing...`));
|
|
72
|
+
|
|
73
|
+
// 4. Loop through the files (tokens.ts and ThemeProvider.tsx) and create them!
|
|
74
|
+
for (const file of themeComponent.files) {
|
|
75
|
+
// file.target is exactly what we wrote earlier (e.g., "theme/tokens.ts")
|
|
76
|
+
const targetPath = path.join(process.cwd(), file.target);
|
|
77
|
+
|
|
78
|
+
// Ensure the folder exists (e.g., creates the "theme/" folder if it doesn't exist)
|
|
79
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true });
|
|
80
|
+
|
|
81
|
+
// Write the raw React code to their hard drive!
|
|
82
|
+
fs.writeFileSync(targetPath, file.content, "utf-8");
|
|
83
|
+
|
|
84
|
+
console.log(chalk.green(`Created ${file.target}`));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
console.log(chalk.blue("\nš Initialization complete!"));
|
|
88
|
+
console.log(
|
|
89
|
+
chalk.dim(
|
|
90
|
+
"Wrap your app in the <ThemeProvider> to get started.",
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.log(chalk.red(`\nFailed to initialize:`));
|
|
95
|
+
console.error(error);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
program.parse();
|