rn-package-installer 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/.rn-package-installer.lock +1 -0
- package/bin/cli.js +41 -0
- package/package.json +29 -0
- package/src/detectPm.js +18 -0
- package/src/installer.js +17 -0
- package/src/packages.js +7 -0
- package/src/prompts.js +33 -0
- package/src/utils.js +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
installed
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { getUserChoices } from "../src/prompts.js";
|
|
5
|
+
import { installPackages } from "../src/installer.js";
|
|
6
|
+
import { hasRunBefore, markAsRun } from "../src/utils.js";
|
|
7
|
+
|
|
8
|
+
// Skip non-interactive / CI
|
|
9
|
+
if (!process.stdout.isTTY || process.env.CI) {
|
|
10
|
+
process.exit(0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ā
Run-only-once check
|
|
14
|
+
if (hasRunBefore()) {
|
|
15
|
+
console.log("rn-package-installer already ran. Skipping.");
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(chalk.cyan.bold("\nš RN Package Installer\n"));
|
|
20
|
+
|
|
21
|
+
(async () => {
|
|
22
|
+
try {
|
|
23
|
+
const { selectedPackages, packageManager } =
|
|
24
|
+
await getUserChoices();
|
|
25
|
+
|
|
26
|
+
if (!selectedPackages.length) {
|
|
27
|
+
console.log("No packages selected.");
|
|
28
|
+
markAsRun(); // still mark as done
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
await installPackages(selectedPackages, packageManager);
|
|
33
|
+
|
|
34
|
+
// ā
Mark successful run
|
|
35
|
+
markAsRun();
|
|
36
|
+
|
|
37
|
+
console.log(chalk.green("\n !!!!! Packages Installation complete!\n"));
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.error(chalk.red("Error:"), err.message);
|
|
40
|
+
}
|
|
41
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rn-package-installer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Interactive package installer for React and React Native",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "bin/cli.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"rn-package-installer": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"postinstall": "node bin/cli.js"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"react",
|
|
16
|
+
"cli",
|
|
17
|
+
"installer",
|
|
18
|
+
"packages"
|
|
19
|
+
],
|
|
20
|
+
"author": "Akash",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.13.4",
|
|
24
|
+
"chalk": "^5.3.0",
|
|
25
|
+
"execa": "^8.0.1",
|
|
26
|
+
"inquirer": "^9.2.12",
|
|
27
|
+
"moment": "^2.30.1"
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/detectPm.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { execaSync } from "execa";
|
|
2
|
+
|
|
3
|
+
export function detectPackageManagers() {
|
|
4
|
+
let hasNpm = false;
|
|
5
|
+
let hasYarn = false;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
execaSync("npm", ["-v"]);
|
|
9
|
+
hasNpm = true;
|
|
10
|
+
} catch { }
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
execaSync("yarn", ["-v"]);
|
|
14
|
+
hasYarn = true;
|
|
15
|
+
} catch { }
|
|
16
|
+
|
|
17
|
+
return { hasNpm, hasYarn };
|
|
18
|
+
}
|
package/src/installer.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { execa } from "execa";
|
|
2
|
+
|
|
3
|
+
export async function installPackages(packages, pm) {
|
|
4
|
+
if (!packages.length) {
|
|
5
|
+
console.log("No packages selected.");
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const args =
|
|
10
|
+
pm === "yarn"
|
|
11
|
+
? ["add", ...packages]
|
|
12
|
+
: ["install", ...packages];
|
|
13
|
+
|
|
14
|
+
console.log(`\nInstalling using ${pm}...\n`);
|
|
15
|
+
|
|
16
|
+
await execa(pm, args, { stdio: "inherit" });
|
|
17
|
+
}
|
package/src/packages.js
ADDED
package/src/prompts.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import inquirer from "inquirer";
|
|
2
|
+
import { PACKAGES } from "./packages.js";
|
|
3
|
+
import { detectPackageManagers } from "./detectPm.js";
|
|
4
|
+
|
|
5
|
+
export async function getUserChoices() {
|
|
6
|
+
// multi-select packages
|
|
7
|
+
const { selectedPackages } = await inquirer.prompt({
|
|
8
|
+
type: "checkbox",
|
|
9
|
+
name: "selectedPackages",
|
|
10
|
+
message: "Select packages to install:",
|
|
11
|
+
choices: PACKAGES.map(p => ({
|
|
12
|
+
name: p.name,
|
|
13
|
+
value: p.name
|
|
14
|
+
}))
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const { hasNpm, hasYarn } = detectPackageManagers();
|
|
18
|
+
let packageManager = "npm";
|
|
19
|
+
|
|
20
|
+
if (hasNpm && hasYarn) {
|
|
21
|
+
const res = await inquirer.prompt({
|
|
22
|
+
type: "list",
|
|
23
|
+
name: "packageManager",
|
|
24
|
+
message: "Both npm and yarn detected. Choose one:",
|
|
25
|
+
choices: ["npm", "yarn"]
|
|
26
|
+
});
|
|
27
|
+
packageManager = res.packageManager;
|
|
28
|
+
} else if (hasYarn) {
|
|
29
|
+
packageManager = "yarn";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { selectedPackages, packageManager };
|
|
33
|
+
}
|
package/src/utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
const LOCK_FILE = ".rn-package-installer.lock";
|
|
5
|
+
|
|
6
|
+
export function hasRunBefore() {
|
|
7
|
+
return fs.existsSync(path.join(process.cwd(), LOCK_FILE));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function markAsRun() {
|
|
11
|
+
fs.writeFileSync(
|
|
12
|
+
path.join(process.cwd(), LOCK_FILE),
|
|
13
|
+
"installed",
|
|
14
|
+
"utf8"
|
|
15
|
+
);
|
|
16
|
+
}
|