@rohilaharsh/react-kit 0.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/README.md +87 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +35 -0
- package/dist/commands/init.d.ts +1 -0
- package/dist/commands/init.js +47 -0
- package/dist/detectPackageManager.d.ts +6 -0
- package/dist/detectPackageManager.js +62 -0
- package/dist/installDeps.d.ts +12 -0
- package/dist/installDeps.js +68 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @rohilaharsh/react-kit
|
|
2
|
+
|
|
3
|
+
A small CLI that installs a React-related toolkit into an existing Node/React project.
|
|
4
|
+
|
|
5
|
+
It detects your package manager from lockfiles and runs the appropriate install command for:
|
|
6
|
+
|
|
7
|
+
- `singleton-injection`
|
|
8
|
+
- `context-scoped-state`
|
|
9
|
+
- `axios`
|
|
10
|
+
- `rxjs`
|
|
11
|
+
|
|
12
|
+
## Installation & usage
|
|
13
|
+
|
|
14
|
+
You do **not** install this package as a dependency of your app. Instead, run it via your preferred runner:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bunx @rohilaharsh/react-kit init
|
|
18
|
+
# or
|
|
19
|
+
npx @rohilaharsh/react-kit init
|
|
20
|
+
# or
|
|
21
|
+
pnpm dlx @rohilaharsh/react-kit init
|
|
22
|
+
# or
|
|
23
|
+
yarn dlx @rohilaharsh/react-kit init
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Run the command **inside an existing project** that already has a `package.json`.
|
|
27
|
+
|
|
28
|
+
## What it does
|
|
29
|
+
|
|
30
|
+
1. Verifies there is a `package.json` in the current working directory.
|
|
31
|
+
2. Detects your package manager in this order:
|
|
32
|
+
- `bun.lockb` → Bun
|
|
33
|
+
- `pnpm-lock.yaml` → pnpm
|
|
34
|
+
- `yarn.lock` → Yarn
|
|
35
|
+
- `package-lock.json` → npm
|
|
36
|
+
- Otherwise, falls back to the `packageManager` field in `package.json` if present.
|
|
37
|
+
- If nothing else matches, defaults to npm.
|
|
38
|
+
3. Runs the matching install command to add:
|
|
39
|
+
- `singleton-injection`
|
|
40
|
+
- `context-scoped-state`
|
|
41
|
+
- `axios`
|
|
42
|
+
- `rxjs`
|
|
43
|
+
|
|
44
|
+
## Local development (with Bun)
|
|
45
|
+
|
|
46
|
+
This repo is built and tested using [Bun](https://bun.sh).
|
|
47
|
+
|
|
48
|
+
Install dependencies:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
bun install
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Build the CLI:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
bun run build
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Run tests:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
bun test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Publishing to npm (using Bun)
|
|
67
|
+
|
|
68
|
+
Before publishing, make sure you are logged in with npm:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm login
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Then use the provided scripts:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Bump version (patch/minor/major) and create a git tag, per npm conventions
|
|
78
|
+
npm version patch
|
|
79
|
+
|
|
80
|
+
# Or use the generic script wired through Bun
|
|
81
|
+
bun run version
|
|
82
|
+
|
|
83
|
+
# Build and publish
|
|
84
|
+
bun run publish
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The `prepublishOnly` hook ensures that the TypeScript sources are compiled to `dist/` before `npm publish` runs.
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const init_1 = require("./commands/init");
|
|
5
|
+
async function main() {
|
|
6
|
+
const [, , command, ...rest] = process.argv;
|
|
7
|
+
switch (command) {
|
|
8
|
+
case "init":
|
|
9
|
+
await (0, init_1.runInit)(rest);
|
|
10
|
+
break;
|
|
11
|
+
case "--help":
|
|
12
|
+
case "-h":
|
|
13
|
+
default:
|
|
14
|
+
printHelp();
|
|
15
|
+
process.exit(0);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function printHelp() {
|
|
19
|
+
console.log(`
|
|
20
|
+
@rohilaharsh/react-kit
|
|
21
|
+
|
|
22
|
+
Usage:
|
|
23
|
+
bunx @rohilaharsh/react-kit init
|
|
24
|
+
npx @rohilaharsh/react-kit init
|
|
25
|
+
pnpm dlx @rohilaharsh/react-kit init
|
|
26
|
+
yarn dlx @rohilaharsh/react-kit init
|
|
27
|
+
|
|
28
|
+
Commands:
|
|
29
|
+
init Install React-related toolkit dependencies into the current project.
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
main().catch((error) => {
|
|
33
|
+
console.error("[react-kit] Unexpected error:", error);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runInit(_args: string[]): Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runInit = runInit;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const detectPackageManager_1 = require("../detectPackageManager");
|
|
10
|
+
const installDeps_1 = require("../installDeps");
|
|
11
|
+
const REACT_DEPS = [
|
|
12
|
+
"singleton-injection",
|
|
13
|
+
"context-scoped-state",
|
|
14
|
+
"axios",
|
|
15
|
+
"rxjs",
|
|
16
|
+
];
|
|
17
|
+
async function runInit(_args) {
|
|
18
|
+
const cwd = process.cwd();
|
|
19
|
+
const pkgJsonPath = path_1.default.join(cwd, "package.json");
|
|
20
|
+
if (!fs_1.default.existsSync(pkgJsonPath)) {
|
|
21
|
+
console.error("[react-kit] No package.json found in the current directory. Please run this inside a Node/React project.");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
console.log("[react-kit] Detected package.json in current directory.");
|
|
25
|
+
const { manager, source } = (0, detectPackageManager_1.detectPackageManager)(cwd);
|
|
26
|
+
console.log(`[react-kit] Detected package manager: ${manager} (via ${source}).`);
|
|
27
|
+
console.log(`[react-kit] Installing dependencies: ${REACT_DEPS.join(", ")}...`);
|
|
28
|
+
try {
|
|
29
|
+
await (0, installDeps_1.installDeps)({
|
|
30
|
+
manager,
|
|
31
|
+
deps: REACT_DEPS,
|
|
32
|
+
cwd,
|
|
33
|
+
});
|
|
34
|
+
console.log("[react-kit] Successfully installed singleton-injection, context-scoped-state, axios, rxjs.");
|
|
35
|
+
console.log("[react-kit] You can now wire these into your React app (e.g., providers, hooks, data fetching).");
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error("[react-kit] Failed to install dependencies.");
|
|
39
|
+
if (error instanceof Error) {
|
|
40
|
+
console.error(error.message);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error(error);
|
|
44
|
+
}
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.detectPackageManager = detectPackageManager;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function fileExistsSync(filePath) {
|
|
10
|
+
try {
|
|
11
|
+
fs_1.default.accessSync(filePath, fs_1.default.constants.F_OK);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function detectPackageManager(cwd = process.cwd()) {
|
|
19
|
+
const lockfiles = {
|
|
20
|
+
bun: path_1.default.join(cwd, "bun.lockb"),
|
|
21
|
+
pnpm: path_1.default.join(cwd, "pnpm-lock.yaml"),
|
|
22
|
+
yarn: path_1.default.join(cwd, "yarn.lock"),
|
|
23
|
+
npm: path_1.default.join(cwd, "package-lock.json"),
|
|
24
|
+
};
|
|
25
|
+
if (fileExistsSync(lockfiles.bun)) {
|
|
26
|
+
return { manager: "bun", source: "lockfile" };
|
|
27
|
+
}
|
|
28
|
+
if (fileExistsSync(lockfiles.pnpm)) {
|
|
29
|
+
return { manager: "pnpm", source: "lockfile" };
|
|
30
|
+
}
|
|
31
|
+
if (fileExistsSync(lockfiles.yarn)) {
|
|
32
|
+
return { manager: "yarn", source: "lockfile" };
|
|
33
|
+
}
|
|
34
|
+
if (fileExistsSync(lockfiles.npm)) {
|
|
35
|
+
return { manager: "npm", source: "lockfile" };
|
|
36
|
+
}
|
|
37
|
+
// Fallback: try package.json "packageManager" field
|
|
38
|
+
const pkgJsonPath = path_1.default.join(cwd, "package.json");
|
|
39
|
+
if (fileExistsSync(pkgJsonPath)) {
|
|
40
|
+
try {
|
|
41
|
+
const pkgRaw = fs_1.default.readFileSync(pkgJsonPath, "utf8");
|
|
42
|
+
const pkg = JSON.parse(pkgRaw);
|
|
43
|
+
if (pkg.packageManager?.startsWith("bun")) {
|
|
44
|
+
return { manager: "bun", source: "packageManager-field" };
|
|
45
|
+
}
|
|
46
|
+
if (pkg.packageManager?.startsWith("pnpm")) {
|
|
47
|
+
return { manager: "pnpm", source: "packageManager-field" };
|
|
48
|
+
}
|
|
49
|
+
if (pkg.packageManager?.startsWith("yarn")) {
|
|
50
|
+
return { manager: "yarn", source: "packageManager-field" };
|
|
51
|
+
}
|
|
52
|
+
if (pkg.packageManager?.startsWith("npm")) {
|
|
53
|
+
return { manager: "npm", source: "packageManager-field" };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// ignore parse errors and fall through
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Default to npm if nothing else is detected.
|
|
61
|
+
return { manager: "npm", source: "default" };
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PackageManager } from "./detectPackageManager";
|
|
2
|
+
export interface InstallDepsOptions {
|
|
3
|
+
manager: PackageManager;
|
|
4
|
+
deps: string[];
|
|
5
|
+
isDev?: boolean;
|
|
6
|
+
cwd?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function buildInstallCommand(options: InstallDepsOptions): {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function installDeps(options: InstallDepsOptions): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildInstallCommand = buildInstallCommand;
|
|
7
|
+
exports.installDeps = installDeps;
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
function buildInstallCommand(options) {
|
|
11
|
+
const { manager, deps, isDev } = options;
|
|
12
|
+
switch (manager) {
|
|
13
|
+
case "npm":
|
|
14
|
+
return {
|
|
15
|
+
command: "npm",
|
|
16
|
+
args: ["install", ...(isDev ? ["--save-dev"] : []), ...deps],
|
|
17
|
+
};
|
|
18
|
+
case "yarn":
|
|
19
|
+
return {
|
|
20
|
+
command: "yarn",
|
|
21
|
+
args: ["add", ...(isDev ? ["-D"] : []), ...deps],
|
|
22
|
+
};
|
|
23
|
+
case "pnpm":
|
|
24
|
+
return {
|
|
25
|
+
command: "pnpm",
|
|
26
|
+
args: ["add", ...(isDev ? ["-D"] : []), ...deps],
|
|
27
|
+
};
|
|
28
|
+
case "bun":
|
|
29
|
+
return {
|
|
30
|
+
command: "bun",
|
|
31
|
+
args: ["add", ...(isDev ? ["-d"] : []), ...deps],
|
|
32
|
+
};
|
|
33
|
+
default: {
|
|
34
|
+
const exhaustiveCheck = manager;
|
|
35
|
+
throw new Error(`Unsupported package manager: ${exhaustiveCheck}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function installDeps(options) {
|
|
40
|
+
const { command, args } = buildInstallCommand(options);
|
|
41
|
+
const cwd = options.cwd ?? process.cwd();
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
console.log(`[react-kit] Running: ${command} ${args.join(" ")} (cwd: ${path_1.default.resolve(cwd)})`);
|
|
44
|
+
const child = (0, child_process_1.spawn)(command, args, {
|
|
45
|
+
cwd,
|
|
46
|
+
stdio: "inherit",
|
|
47
|
+
shell: process.platform === "win32",
|
|
48
|
+
});
|
|
49
|
+
child.on("error", (error) => {
|
|
50
|
+
console.error("[react-kit] Failed to start install process:", error);
|
|
51
|
+
reject(error);
|
|
52
|
+
});
|
|
53
|
+
child.on("close", (code, signal) => {
|
|
54
|
+
if (signal) {
|
|
55
|
+
const err = new Error(`[react-kit] Install process was terminated with signal ${signal}`);
|
|
56
|
+
reject(err);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (code === 0) {
|
|
60
|
+
resolve();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const err = new Error(`[react-kit] Install command exited with code ${code}`);
|
|
64
|
+
reject(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rohilaharsh/react-kit",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "CLI to initialize a React-related toolkit by installing singleton-injection, context-scoped-state, axios, and rxjs using the detected package manager.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"main": "dist/cli.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"react-kit": "dist/cli.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "bun run tsc -p tsconfig.json",
|
|
17
|
+
"test": "bun test",
|
|
18
|
+
"version": "npm version",
|
|
19
|
+
"prepublishOnly": "bun run build",
|
|
20
|
+
"publish": "bun run build && npm publish"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"react",
|
|
24
|
+
"cli",
|
|
25
|
+
"bun",
|
|
26
|
+
"toolkit",
|
|
27
|
+
"singleton-injection",
|
|
28
|
+
"context-scoped-state",
|
|
29
|
+
"axios",
|
|
30
|
+
"rxjs"
|
|
31
|
+
],
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=16"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/node": "^22.10.2",
|
|
40
|
+
"typescript": "^5.7.2"
|
|
41
|
+
}
|
|
42
|
+
}
|