@unciatech/file-manager 0.0.32 → 0.0.33

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/cli.js CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // cli.ts
4
- import * as fs from "fs";
5
- import * as path from "path";
4
+ import fs from "fs";
5
+ import path from "path";
6
6
  import { execSync } from "child_process";
7
- import * as readline from "readline";
7
+ import readline from "readline";
8
8
  var args = process.argv.slice(2);
9
9
  var command = args[0];
10
10
  var projectName = args[1];
@@ -12,14 +12,16 @@ var rl = readline.createInterface({
12
12
  input: process.stdin,
13
13
  output: process.stdout
14
14
  });
15
- var askQuestion = (query) => new Promise((resolve) => rl.question(query, resolve));
16
- var TEMPLATE = `"use client";
15
+ var askQuestion = (query) => {
16
+ return new Promise((resolve) => rl.question(query, resolve));
17
+ };
18
+ var getTemplate = (basePath = "/media") => `"use client";
17
19
 
18
- import React, { Suspense, useMemo } from "react";
20
+ import React, { Suspense } from "react";
19
21
  import { FileManager, MockProvider } from "@unciatech/file-manager";
20
22
 
21
23
  export default function FileManagerDemo() {
22
- const provider = useMemo(() => new MockProvider(), []);
24
+ const mockProvider = new MockProvider();
23
25
 
24
26
  return (
25
27
  <div className="h-screen w-full">
@@ -27,7 +29,8 @@ export default function FileManagerDemo() {
27
29
  <FileManager
28
30
  allowedFileTypes={["audios", "videos", "images", "files"]}
29
31
  viewMode="grid"
30
- provider={provider}
32
+ provider={mockProvider}
33
+ basePath="${basePath}"
31
34
  />
32
35
  </Suspense>
33
36
  </div>
@@ -40,30 +43,39 @@ async function main() {
40
43
  process.exit(0);
41
44
  }
42
45
  if (!projectName) {
43
- console.log("\u{1F680} Generating <FileManagerDemo /> component...");
46
+ console.log("\u{1F680} Generating <FileManagerDemo /> component in the current project...");
44
47
  let targetDir2 = process.cwd();
45
- if (fs.existsSync(path.join(process.cwd(), "src/components"))) {
46
- targetDir2 = path.join(process.cwd(), "src/components");
47
- } else if (fs.existsSync(path.join(process.cwd(), "components"))) {
48
+ if (fs.existsSync(path.join(process.cwd(), "components"))) {
48
49
  targetDir2 = path.join(process.cwd(), "components");
50
+ } else if (fs.existsSync(path.join(process.cwd(), "src", "components"))) {
51
+ targetDir2 = path.join(process.cwd(), "src", "components");
49
52
  }
50
- const file = path.join(targetDir2, "FileManagerDemo.tsx");
51
- fs.writeFileSync(file, TEMPLATE);
52
- console.log(`\u2705 Created ${file}`);
53
+ const targetFile = path.join(targetDir2, "FileManagerDemo.tsx");
54
+ if (fs.existsSync(targetFile)) {
55
+ console.error(`\u274C Error: ${targetFile} already exists.`);
56
+ process.exit(1);
57
+ }
58
+ fs.writeFileSync(targetFile, getTemplate("/"), "utf-8");
59
+ console.log(`\u2705 Success! Created ${targetFile}`);
60
+ console.log("");
61
+ console.log("You can now import and render <FileManagerDemo /> anywhere in your application.");
62
+ console.log("Don't forget to configure your Tailwind CSS content to scan the library for styles!");
53
63
  process.exit(0);
54
64
  }
55
65
  console.log(`
56
- \u{1F680} Initializing project: ${projectName}
66
+ \u{1F680} Initializing a new application: ${projectName}
57
67
  `);
58
- console.log("Choose framework:");
59
- console.log("1) Next.js");
60
- console.log("2) Vite (React)");
61
- console.log("3) Cancel");
62
- const choice = await askQuestion("\nSelect option (1-3): ");
63
- rl.close();
68
+ console.log("Which framework would you like to use?");
69
+ console.log(" 1) Next.js (App Router, Tailwind v4)");
70
+ console.log(" 2) Vite (React, Tailwind v4)");
71
+ console.log(" 3) Cancel");
72
+ const choice = await askQuestion("\nSelect an option (1-3): ");
64
73
  const targetDir = path.join(process.cwd(), projectName);
65
74
  if (fs.existsSync(targetDir)) {
66
- console.error("\u274C Directory already exists");
75
+ console.error(`
76
+ \u274C Error: Directory "${projectName}" already exists in ${process.cwd()}.`);
77
+ console.error(` Please choose a different project name or delete the existing directory first.`);
78
+ rl.close();
67
79
  process.exit(1);
68
80
  }
69
81
  try {
@@ -73,34 +85,40 @@ async function main() {
73
85
  await scaffoldVite(projectName, targetDir);
74
86
  } else {
75
87
  console.log("Canceled.");
88
+ process.exit(0);
76
89
  }
77
- } catch (e) {
78
- console.error("\u274C Error:", e);
90
+ } catch (error) {
91
+ console.error("\n\u274C Scaffolding failed:", error);
92
+ process.exit(1);
79
93
  }
94
+ process.exit(0);
80
95
  }
81
96
  async function scaffoldNextjs(projectName2, targetDir) {
82
- console.log("\n\u{1F4E6} Creating Next.js app...");
83
- execSync(
84
- `npx create-next-app@latest ${projectName2} --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-npm`,
85
- { stdio: "inherit" }
86
- );
87
- console.log("\n\u{1F4E6} Installing dependencies...");
88
- execSync("npm install @unciatech/file-manager tailwindcss-animate", {
89
- cwd: targetDir,
90
- stdio: "inherit"
91
- });
92
- const componentsDir = path.join(targetDir, "src/components");
93
- fs.mkdirSync(componentsDir, { recursive: true });
94
- fs.writeFileSync(
95
- path.join(componentsDir, "FileManagerDemo.tsx"),
96
- TEMPLATE
97
+ console.log("\n\u{1F4E6} Creating Next.js application (this may take a minute)...");
98
+ execSync(`npx create-next-app@latest ${projectName2} --ts --tailwind --eslint --app --src-dir --import-alias "@/*" --use-npm`, { stdio: "inherit" });
99
+ console.log("\n\u{1F4E6} Installing dependencies (@unciatech/file-manager, tailwindcss-animate)...");
100
+ execSync("npm install @unciatech/file-manager tailwindcss-animate", { cwd: targetDir, stdio: "inherit" });
101
+ const componentsDir = path.join(targetDir, "src", "components");
102
+ if (!fs.existsSync(componentsDir)) fs.mkdirSync(componentsDir, { recursive: true });
103
+ fs.writeFileSync(path.join(componentsDir, "FileManagerDemo.tsx"), getTemplate("/media"), "utf-8");
104
+ const pagePath = path.join(targetDir, "src", "app", "page.tsx");
105
+ fs.writeFileSync(pagePath, `import FileManagerDemo from "@/components/FileManagerDemo";
106
+
107
+ export default function Home() {
108
+ return (
109
+ <main className="min-h-screen bg-neutral-50">
110
+ <FileManagerDemo />
111
+ </main>
97
112
  );
98
- const pagePath = path.join(targetDir, "src/app/page.tsx");
113
+ }
114
+ `);
115
+ const mediaRouteDir = path.join(targetDir, "src", "app", "media", "[[...path]]");
116
+ fs.mkdirSync(mediaRouteDir, { recursive: true });
99
117
  fs.writeFileSync(
100
- pagePath,
118
+ path.join(mediaRouteDir, "page.tsx"),
101
119
  `import FileManagerDemo from "@/components/FileManagerDemo";
102
120
 
103
- export default function Home() {
121
+ export default function MediaPage() {
104
122
  return (
105
123
  <main className="min-h-screen bg-neutral-50">
106
124
  <FileManagerDemo />
@@ -109,49 +127,61 @@ export default function Home() {
109
127
  }
110
128
  `
111
129
  );
130
+ const layoutPath = path.join(targetDir, "src", "app", "layout.tsx");
131
+ if (fs.existsSync(layoutPath)) {
132
+ let layoutContent = fs.readFileSync(layoutPath, "utf8");
133
+ if (!layoutContent.includes("@unciatech/file-manager/styles")) {
134
+ layoutContent = layoutContent.replace(
135
+ /^(import type)/m,
136
+ `import '@unciatech/file-manager/styles';
137
+ $1`
138
+ );
139
+ fs.writeFileSync(layoutPath, layoutContent);
140
+ }
141
+ }
142
+ const cssPath = path.join(targetDir, "src", "app", "globals.css");
143
+ fs.writeFileSync(cssPath, `@import "tailwindcss";
144
+ @import "@unciatech/file-manager/styles";
145
+ @import "tw-animate-css";
146
+
147
+ @source "../../node_modules/@unciatech/file-manager";
148
+
149
+ @theme {
150
+ --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
151
+ --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
152
+ }
153
+ `);
112
154
  printSuccess(projectName2);
113
155
  }
114
156
  async function scaffoldVite(projectName2, targetDir) {
115
- console.log("\n\u{1F4E6} Creating Vite app...");
116
- execSync(
117
- `npm create vite@latest ${projectName2} -- --template react-ts`,
118
- { stdio: "inherit" }
119
- );
120
- console.log("\n\u{1F4E6} Installing dependencies...");
157
+ console.log("\n\u{1F4E6} Creating Vite React application...");
158
+ execSync(`npm create vite@latest ${projectName2} -- --template react-ts`, { stdio: "inherit" });
159
+ console.log("\n\u{1F4E6} Installing dependencies (Tailwind + File Manager)...");
121
160
  execSync("npm install", { cwd: targetDir, stdio: "inherit" });
122
- execSync(
123
- "npm install tailwindcss @tailwindcss/vite tw-animate-css @unciatech/file-manager",
124
- { cwd: targetDir, stdio: "inherit" }
125
- );
161
+ execSync("npm install tailwindcss @tailwindcss/vite @unciatech/file-manager", { cwd: targetDir, stdio: "inherit" });
162
+ const viteConfigPath = path.join(targetDir, "vite.config.ts");
126
163
  const viteConfig = `import { defineConfig } from 'vite'
127
164
  import react from '@vitejs/plugin-react'
128
165
  import tailwindcss from '@tailwindcss/vite'
129
166
 
130
167
  export default defineConfig({
131
- plugins: [react(), tailwindcss()],
168
+ plugins: [
169
+ react(),
170
+ tailwindcss(),
171
+ ],
132
172
  })
133
173
  `;
134
- fs.writeFileSync(path.join(targetDir, "vite.config.ts"), viteConfig);
135
- const css = `@import "tailwindcss";
136
- @import "tw-animate-css";
137
-
138
- @source "../node_modules/@unciatech/file-manager/dist/**/*.{js,ts,jsx,tsx}";
139
- `;
140
- fs.writeFileSync(path.join(targetDir, "src/index.css"), css);
141
- const mainFile = path.join(targetDir, "src/main.tsx");
142
- let main2 = fs.readFileSync(mainFile, "utf8");
143
- if (!main2.includes("@unciatech/file-manager/styles")) {
144
- main2 = `import "@unciatech/file-manager/styles";
145
- ` + main2;
146
- }
147
- fs.writeFileSync(mainFile, main2);
148
- const compDir = path.join(targetDir, "src/components");
149
- fs.mkdirSync(compDir, { recursive: true });
150
- fs.writeFileSync(
151
- path.join(compDir, "FileManagerDemo.tsx"),
152
- TEMPLATE
153
- );
154
- const app = `import FileManagerDemo from "./components/FileManagerDemo";
174
+ fs.writeFileSync(viteConfigPath, viteConfig);
175
+ const cssPath = path.join(targetDir, "src", "index.css");
176
+ fs.writeFileSync(cssPath, `@import "tailwindcss";
177
+ @import "@unciatech/file-manager/styles";
178
+ @source "../node_modules/@unciatech/file-manager";
179
+ `);
180
+ const componentsDir = path.join(targetDir, "src", "components");
181
+ if (!fs.existsSync(componentsDir)) fs.mkdirSync(componentsDir, { recursive: true });
182
+ fs.writeFileSync(path.join(componentsDir, "FileManagerDemo.tsx"), getTemplate("/"), "utf-8");
183
+ const appPath = path.join(targetDir, "src", "App.tsx");
184
+ fs.writeFileSync(appPath, `import FileManagerDemo from "./components/FileManagerDemo";
155
185
 
156
186
  function App() {
157
187
  return (
@@ -162,18 +192,16 @@ function App() {
162
192
  }
163
193
 
164
194
  export default App;
165
- `;
166
- fs.writeFileSync(path.join(targetDir, "src/App.tsx"), app);
167
- printSuccess(projectName2);
168
- }
169
- function printSuccess(projectName2) {
170
- console.log("\n=================================");
171
- console.log("\u{1F389} Project ready!");
172
- console.log("=================================");
173
- console.log(`
174
- Next steps:`);
175
- console.log(`cd ${projectName2}`);
176
- console.log(`npm run dev
177
195
  `);
196
+ printSuccess(projectName2, "npm run dev");
197
+ }
198
+ function printSuccess(projectName2, devCmd = "npm run dev") {
199
+ console.log("\n=========================================");
200
+ console.log("\u{1F389} Your Media Library application is ready!");
201
+ console.log("=========================================");
202
+ console.log("\nNext steps:");
203
+ console.log(` cd ${projectName2}`);
204
+ console.log(` ${devCmd}`);
205
+ console.log("\nEnjoy building! \u{1F5C2}\uFE0F\n");
178
206
  }
179
207
  main();