@fydemy/cms 1.0.2 → 1.0.4

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.mjs CHANGED
@@ -1829,6 +1829,9 @@ function createAuthMiddleware(options = {}) {
1829
1829
  // src/init/setup.ts
1830
1830
  import fs2 from "fs/promises";
1831
1831
  import path3 from "path";
1832
+ import { exec } from "child_process";
1833
+ import { promisify } from "util";
1834
+ var execAsync = promisify(exec);
1832
1835
  async function initCMS(config = {}) {
1833
1836
  const contentDir = config.contentDir || "public/content";
1834
1837
  const fullPath = path3.join(process.cwd(), contentDir);
@@ -1842,6 +1845,48 @@ async function initCMS(config = {}) {
1842
1845
  return;
1843
1846
  }
1844
1847
  console.log("\u{1F680} Initializing @fydemy/cms...");
1848
+ console.log("\u{1F4E6} Checking dependencies...");
1849
+ try {
1850
+ const packageJsonPath = path3.join(process.cwd(), "package.json");
1851
+ const packageJson = JSON.parse(await fs2.readFile(packageJsonPath, "utf-8"));
1852
+ const dependencies = {
1853
+ ...packageJson.dependencies,
1854
+ ...packageJson.devDependencies
1855
+ };
1856
+ const missingDeps = [];
1857
+ if (!dependencies["@fydemy/cms"]) missingDeps.push("@fydemy/cms");
1858
+ if (!dependencies["tailwindcss"]) missingDeps.push("tailwindcss");
1859
+ if (!dependencies["class-variance-authority"])
1860
+ missingDeps.push("class-variance-authority");
1861
+ if (!dependencies["clsx"]) missingDeps.push("clsx");
1862
+ if (!dependencies["tailwind-merge"]) missingDeps.push("tailwind-merge");
1863
+ if (!dependencies["@radix-ui/react-slot"])
1864
+ missingDeps.push("@radix-ui/react-slot");
1865
+ if (!dependencies["@radix-ui/react-label"])
1866
+ missingDeps.push("@radix-ui/react-label");
1867
+ if (missingDeps.length > 0) {
1868
+ console.log(
1869
+ `\u{1F527} Installing missing dependencies: ${missingDeps.join(", ")}...`
1870
+ );
1871
+ let installCmd = "npm install";
1872
+ try {
1873
+ await fs2.access("pnpm-lock.yaml");
1874
+ installCmd = "pnpm add";
1875
+ } catch {
1876
+ try {
1877
+ await fs2.access("yarn.lock");
1878
+ installCmd = "yarn add";
1879
+ } catch {
1880
+ }
1881
+ }
1882
+ await execAsync(`${installCmd} ${missingDeps.join(" ")}`);
1883
+ console.log("\u2705 Dependencies installed");
1884
+ }
1885
+ } catch (error) {
1886
+ console.warn(
1887
+ "\u26A0\uFE0F Could not check/install dependencies automatically. Please ensure all dependencies are installed."
1888
+ );
1889
+ }
1845
1890
  await fs2.mkdir(fullPath, { recursive: true });
1846
1891
  const exampleContent = `---
1847
1892
  title: Example Post
@@ -1867,23 +1912,55 @@ This is an example markdown file. You can edit or delete it from the admin dashb
1867
1912
  const adminDir = path3.join(appDir, "admin");
1868
1913
  const loginDir = path3.join(adminDir, "login");
1869
1914
  await fs2.mkdir(loginDir, { recursive: true });
1870
- await fs2.writeFile(
1871
- path3.join(adminDir, "page.tsx"),
1872
- `import { AdminDashboard } from '@fydemy/cms';
1873
-
1874
- export default AdminDashboard;
1875
- `,
1915
+ const loginTemplate = await fs2.readFile(
1916
+ path3.join(__dirname, "login.template.tsx"),
1917
+ "utf-8"
1918
+ );
1919
+ const adminTemplate = await fs2.readFile(
1920
+ path3.join(__dirname, "admin.template.tsx"),
1921
+ "utf-8"
1922
+ );
1923
+ await fs2.writeFile(path3.join(adminDir, "page.tsx"), adminTemplate, "utf-8");
1924
+ await fs2.writeFile(path3.join(loginDir, "page.tsx"), loginTemplate, "utf-8");
1925
+ console.log("\u2705 Scaffolded Admin UI (shadcn/ui components)");
1926
+ const componentsDir = path3.join(process.cwd(), "components", "ui");
1927
+ const libDir = path3.join(process.cwd(), "lib");
1928
+ await fs2.mkdir(componentsDir, { recursive: true });
1929
+ await fs2.mkdir(libDir, { recursive: true });
1930
+ const utilsTemplate = await fs2.readFile(
1931
+ path3.join(__dirname, "lib", "utils.ts"),
1932
+ "utf-8"
1933
+ );
1934
+ await fs2.writeFile(path3.join(libDir, "utils.ts"), utilsTemplate, "utf-8");
1935
+ const componentFiles = [
1936
+ "button.tsx",
1937
+ "input.tsx",
1938
+ "card.tsx",
1939
+ "label.tsx",
1940
+ "textarea.tsx",
1941
+ "badge.tsx"
1942
+ ];
1943
+ for (const componentFile of componentFiles) {
1944
+ const componentTemplate = await fs2.readFile(
1945
+ path3.join(__dirname, "components", "ui", componentFile),
1946
+ "utf-8"
1947
+ );
1948
+ await fs2.writeFile(
1949
+ path3.join(componentsDir, componentFile),
1950
+ componentTemplate,
1951
+ "utf-8"
1952
+ );
1953
+ }
1954
+ const componentsJsonTemplate = await fs2.readFile(
1955
+ path3.join(__dirname, "components.json"),
1876
1956
  "utf-8"
1877
1957
  );
1878
1958
  await fs2.writeFile(
1879
- path3.join(loginDir, "page.tsx"),
1880
- `import { Login } from '@fydemy/cms';
1881
-
1882
- export default Login;
1883
- `,
1959
+ path3.join(process.cwd(), "components.json"),
1960
+ componentsJsonTemplate,
1884
1961
  "utf-8"
1885
1962
  );
1886
- console.log("\u2705 Created Admin UI pages");
1963
+ console.log("\u2705 Scaffolded shadcn/ui components");
1887
1964
  const apiCmsDir = path3.join(appDir, "api", "cms");
1888
1965
  await fs2.mkdir(path3.join(apiCmsDir, "login"), { recursive: true });
1889
1966
  await fs2.writeFile(
@@ -1915,9 +1992,17 @@ export { handleUpload as POST };
1915
1992
  await fs2.writeFile(
1916
1993
  path3.join(apiCmsDir, "list", "[[...path]]", "route.ts"),
1917
1994
  `import { createListApiHandlers } from '@fydemy/cms';
1995
+ import { NextRequest } from 'next/server';
1918
1996
 
1919
1997
  const handlers = createListApiHandlers();
1920
- export const GET = handlers.GET;
1998
+
1999
+ export async function GET(
2000
+ request: NextRequest,
2001
+ context: { params: Promise<{ path?: string[] }> }
2002
+ ) {
2003
+ const params = await context.params;
2004
+ return handlers.GET(request, { params });
2005
+ }
1921
2006
  `,
1922
2007
  "utf-8"
1923
2008
  );
@@ -1927,11 +2012,33 @@ export const GET = handlers.GET;
1927
2012
  await fs2.writeFile(
1928
2013
  path3.join(apiCmsDir, "content", "[...path]", "route.ts"),
1929
2014
  `import { createContentApiHandlers } from '@fydemy/cms';
2015
+ import { NextRequest } from 'next/server';
1930
2016
 
1931
2017
  const handlers = createContentApiHandlers();
1932
- export const GET = handlers.GET;
1933
- export const POST = handlers.POST;
1934
- export const DELETE = handlers.DELETE;
2018
+
2019
+ export async function GET(
2020
+ request: NextRequest,
2021
+ context: { params: Promise<{ path: string[] }> }
2022
+ ) {
2023
+ const params = await context.params;
2024
+ return handlers.GET(request, { params });
2025
+ }
2026
+
2027
+ export async function POST(
2028
+ request: NextRequest,
2029
+ context: { params: Promise<{ path: string[] }> }
2030
+ ) {
2031
+ const params = await context.params;
2032
+ return handlers.POST(request, { params });
2033
+ }
2034
+
2035
+ export async function DELETE(
2036
+ request: NextRequest,
2037
+ context: { params: Promise<{ path: string[] }> }
2038
+ ) {
2039
+ const params = await context.params;
2040
+ return handlers.DELETE(request, { params });
2041
+ }
1935
2042
  `,
1936
2043
  "utf-8"
1937
2044
  );
@@ -1966,6 +2073,7 @@ export function middleware(request: NextRequest) {
1966
2073
 
1967
2074
  export const config = {
1968
2075
  matcher: ['/admin/:path*'],
2076
+ runtime: 'nodejs',
1969
2077
  };
1970
2078
  `,
1971
2079
  "utf-8"