pui-inject 0.1.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.
Files changed (2) hide show
  1. package/bin/pui-create.js +82 -0
  2. package/package.json +12 -0
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+
3
+ import axios from "axios";
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import chalk from "chalk";
7
+ import ora from "ora";
8
+
9
+ const componentName = process.argv[2];
10
+
11
+ if (!componentName) {
12
+ console.log(
13
+ chalk.red("✖ Usage: pui-create <component-name>\nExample: pui-create sidebar01")
14
+ );
15
+ process.exit(1);
16
+ }
17
+
18
+ const REGISTRY_URL =
19
+ "https://raw.githubusercontent.com/komal-rastogi080/PUI_flutter_cli/main/manifest.json";
20
+
21
+ async function run() {
22
+ const spinner = ora("Fetching PUI registry...").start();
23
+
24
+ try {
25
+ // 1. Fetch manifest
26
+ const { data: manifest } = await axios.get(REGISTRY_URL);
27
+
28
+ const component = manifest.components[componentName];
29
+
30
+ if (!component) {
31
+ spinner.fail("Component not found in registry");
32
+ console.log(
33
+ chalk.yellow("Available components:"),
34
+ Object.keys(manifest.components).join(", ")
35
+ );
36
+ process.exit(1);
37
+ }
38
+
39
+ spinner.succeed("Component found");
40
+
41
+ const baseRawUrl = REGISTRY_URL
42
+ .replace("/manifest.json", "");
43
+
44
+ const targetDir = path.join(
45
+ process.cwd(),
46
+ "lib",
47
+ "components",
48
+ componentName
49
+ );
50
+
51
+ fs.ensureDirSync(targetDir);
52
+
53
+ // 2. Download files
54
+ for (const file of component.files) {
55
+ const fileUrl = `${baseRawUrl}/${component.path}/${file}`;
56
+ const targetPath = path.join(targetDir, file);
57
+
58
+ const fileSpinner = ora(`Downloading ${file}`).start();
59
+
60
+ try {
61
+ const response = await axios.get(fileUrl);
62
+ fs.writeFileSync(targetPath, response.data);
63
+ fileSpinner.succeed(`${file} added`);
64
+ } catch (err) {
65
+ fileSpinner.fail(`Failed to download ${file}`);
66
+ console.log(chalk.red("URL:"), fileUrl);
67
+ process.exit(1);
68
+ }
69
+ }
70
+
71
+ console.log(
72
+ chalk.green(`\n✔ ${componentName} successfully added to:`),
73
+ chalk.cyan(`lib/components/${componentName}`)
74
+ );
75
+ } catch (error) {
76
+ spinner.fail("Failed to fetch registry");
77
+ console.error(error.message);
78
+ process.exit(1);
79
+ }
80
+ }
81
+
82
+ run();
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "pui-inject",
3
+ "version": "0.1.0",
4
+ "bin": {
5
+ "pui-create": "bin/pui-create.js"
6
+ },
7
+ "type": "module",
8
+ "files": ["bin"],
9
+ "keywords": ["flutter", "ui", "cli", "components"],
10
+ "author": "Komal Rastogi",
11
+ "license": "MIT"
12
+ }