sparkzen 0.0.3 → 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.
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli/index.ts
4
+ import { Command as Command4 } from "commander";
5
+
6
+ // src/cli/commands/init.ts
7
+ import { execSync } from "child_process";
8
+ import { Command } from "commander";
9
+ import degit from "degit";
10
+ import enquirer from "enquirer";
11
+ import fs from "fs-extra";
12
+ import path from "path";
13
+ var { prompt } = enquirer;
14
+ var init = new Command().name("init").description("Initialize a new SparkZen project").action(async () => {
15
+ const { projectName, packageManager, installNow } = await prompt([
16
+ {
17
+ type: "input",
18
+ name: "projectName",
19
+ message: "Project name:",
20
+ required: true
21
+ },
22
+ {
23
+ type: "select",
24
+ name: "packageManager",
25
+ message: "Package manager:",
26
+ choices: ["npm", "pnpm", "yarn", "bun"]
27
+ },
28
+ {
29
+ type: "confirm",
30
+ name: "installNow",
31
+ message: "Do you want to install dependencies now?",
32
+ initial: true
33
+ }
34
+ ]);
35
+ const targetPath = path.resolve(process.cwd(), projectName);
36
+ console.log("\u{1F4C1} Creating project folder...");
37
+ await fs.mkdir(targetPath, { recursive: true });
38
+ console.log("\u{1F4E6} Copying template...");
39
+ const template = degit("MatheusSantos360/sparkzen-templates/default", {
40
+ cache: false,
41
+ force: true
42
+ });
43
+ await template.clone(projectName);
44
+ const pkgJsonPath = path.join(targetPath, "package.json");
45
+ const pkgJson = JSON.parse(await fs.readFile(pkgJsonPath, "utf-8"));
46
+ pkgJson.name = projectName;
47
+ await fs.writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
48
+ console.log(`
49
+ \u{1F680} Project "${projectName}" created successfully!`);
50
+ if (installNow) {
51
+ console.log(`\u26A1 Installing dependencies with ${packageManager}...`);
52
+ execSync(`${packageManager} install`, {
53
+ cwd: targetPath,
54
+ stdio: "inherit",
55
+ shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
56
+ });
57
+ }
58
+ console.log(`\u2705 Project ${projectName} created successfully!`);
59
+ console.log(`
60
+ Next steps:
61
+ cd ${projectName}
62
+ ${packageManager} run dev`);
63
+ });
64
+ var init_default = init;
65
+
66
+ // src/cli/commands/dev.ts
67
+ import { execSync as execSync2 } from "child_process";
68
+ import { Command as Command2 } from "commander";
69
+ import path2 from "path";
70
+ var dev = new Command2().name("dev").description("Run the project in development mode").action(() => {
71
+ const projectPath = process.cwd();
72
+ const tsxPath = path2.join(projectPath, "node_modules", ".bin", "tsx");
73
+ console.log("\u{1F680} Starting dev server...");
74
+ execSync2(`${tsxPath} watch src/index.ts`, {
75
+ cwd: projectPath,
76
+ stdio: "inherit",
77
+ shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
78
+ });
79
+ });
80
+ var dev_default = dev;
81
+
82
+ // src/cli/commands/build.ts
83
+ import { execSync as execSync3 } from "child_process";
84
+ import { Command as Command3 } from "commander";
85
+ import path3 from "path";
86
+ var build = new Command3().name("build").description("Build the project").action(() => {
87
+ const projectPath = process.cwd();
88
+ console.log("\u{1F680} Building the project...");
89
+ const tsupPath = path3.join(process.cwd(), "node_modules", ".bin", "tsup");
90
+ execSync3(`${tsupPath} src/index.ts --format esm --dts --out-dir dist`, {
91
+ cwd: projectPath,
92
+ stdio: "inherit",
93
+ shell: process.platform === "win32" ? "cmd.exe" : "/bin/sh"
94
+ });
95
+ });
96
+ var build_default = build;
97
+
98
+ // src/cli/commands.ts
99
+ function registerCommands(program2) {
100
+ program2.addCommand(init_default);
101
+ program2.addCommand(dev_default);
102
+ program2.addCommand(build_default);
103
+ }
104
+
105
+ // src/cli/index.ts
106
+ var program = new Command4();
107
+ program.name("sparkzen").description("SparkZen CLI").version("1.0.0");
108
+ registerCommands(program);
109
+ program.parse();
package/dist/index.d.ts CHANGED
@@ -1,3 +1,40 @@
1
- declare const add: (a: number, b: number) => number;
1
+ import * as fastify from 'fastify';
2
+ import { FastifyRequest, FastifyReply } from 'fastify';
3
+ import * as http from 'http';
4
+ import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox';
5
+ import { TSchema, Static } from '@sinclair/typebox';
6
+ export { Static, Type as T } from '@sinclair/typebox';
2
7
 
3
- export { add };
8
+ declare function sparkzen(): Promise<fastify.FastifyInstance<http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, TypeBoxTypeProvider>>;
9
+
10
+ type RouteSchema = {
11
+ params?: TSchema;
12
+ body?: TSchema;
13
+ querystring?: TSchema;
14
+ headers?: TSchema;
15
+ response?: Record<number, TSchema>;
16
+ };
17
+ type ResponsePayload<Schema extends RouteSchema, Status extends number> = Schema["response"] extends Record<number, TSchema> ? Status extends keyof Schema["response"] ? Static<Schema["response"][Status]> : unknown : unknown;
18
+ type ResponseKeys<Schema extends RouteSchema> = Schema["response"] extends Record<number, TSchema> ? keyof Schema["response"] & number : number;
19
+ type TypedReply<Schema extends RouteSchema> = Omit<FastifyReply, "send" | "status"> & {
20
+ status: <Status extends ResponseKeys<Schema>>(statusCode: Status) => {
21
+ send: (payload: ResponsePayload<Schema, Status>) => FastifyReply;
22
+ };
23
+ };
24
+ type Handler<Schema extends RouteSchema = {}> = (request: FastifyRequest<{
25
+ Params: Schema["params"] extends TSchema ? Static<Schema["params"]> : {};
26
+ Body: Schema["body"] extends TSchema ? Static<Schema["body"]> : {};
27
+ Querystring: Schema["querystring"] extends TSchema ? Static<Schema["querystring"]> : {};
28
+ Headers: Schema["headers"] extends TSchema ? Static<Schema["headers"]> : {};
29
+ }>, reply: TypedReply<Schema>) => void | Promise<void>;
30
+
31
+ type EnsureSchema<S> = S extends TSchema ? S : never;
32
+ type MiddlewareFunction<Schema extends RouteSchema = RouteSchema> = (request: FastifyRequest<{
33
+ Params: Schema["params"] extends TSchema ? Static<EnsureSchema<Schema["params"]>> : {};
34
+ Body: Schema["body"] extends TSchema ? Static<EnsureSchema<Schema["body"]>> : {};
35
+ Querystring: Schema["querystring"] extends TSchema ? Static<EnsureSchema<Schema["querystring"]>> : {};
36
+ Headers: Schema["headers"] extends TSchema ? Static<EnsureSchema<Schema["headers"]>> : {};
37
+ }>, reply: TypedReply<Schema>, done: () => void) => void | Promise<void>;
38
+ type Middleware<Schema extends RouteSchema = RouteSchema> = MiddlewareFunction<Schema> | MiddlewareFunction<Schema>[];
39
+
40
+ export { type Handler, type Middleware, type MiddlewareFunction, sparkzen as default };
package/dist/index.js CHANGED
@@ -1,30 +1,85 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ // src/core/sparkzen.ts
2
+ import fastify from "fastify";
3
+
4
+ // src/core/routing/isValidRoute.ts
5
+ var isValidRoute = (routeModule) => {
6
+ return routeModule && typeof routeModule === "object" && typeof routeModule.default === "function";
7
+ };
8
+
9
+ // src/core/routing/getRouteURL.ts
10
+ import path from "path";
11
+ var getRouteUrl = (filePath) => {
12
+ const production = process.env.NODE_ENV === "production";
13
+ const basePath = production ? process.cwd() : path.join(process.cwd(), "src", "routes");
14
+ let routePath = filePath.replace(basePath, "").replace(/\\/g, "/").replace(/\.(js|ts)$/, "");
15
+ const segments = routePath.split("/");
16
+ segments.pop();
17
+ routePath = segments.join("/");
18
+ routePath = routePath.replace(/\[(\w+)\]/g, ":$1");
19
+ return `/api${routePath}`.replace(/\/+/g, "/");
9
20
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+
22
+ // src/core/routing/registerRoute.ts
23
+ var registerRoute = (app, routeModule, method, finalPath) => {
24
+ const routeURL = getRouteUrl(finalPath);
25
+ console.log(`Registering route: [${method.toUpperCase()}] ${routeURL}`);
26
+ const routeOptions = {
27
+ ...routeModule,
28
+ method,
29
+ url: routeURL,
30
+ handler: routeModule.default,
31
+ preHandler: routeModule.middlewares
32
+ };
33
+ app.route(routeOptions);
34
+ };
35
+
36
+ // src/core/loadRoutes.ts
37
+ import { pathToFileURL } from "url";
38
+ import fs from "fs/promises";
39
+ import path2 from "path";
40
+
41
+ // src/core/routing/dynamicImport.ts
42
+ var dynamicImport = async (modulePath) => {
43
+ return await import(modulePath);
44
+ };
45
+
46
+ // src/core/loadRoutes.ts
47
+ var loadRoutes = async (app, directory) => {
48
+ const production = process.env.NODE_ENV === "production";
49
+ const ext = production ? ".js" : ".ts";
50
+ const currentDir = process.cwd();
51
+ const routesPath = directory || (production ? path2.join(currentDir) : path2.join(currentDir, "src", "routes"));
52
+ const items = await fs.readdir(routesPath, { withFileTypes: true });
53
+ for (const item of items) {
54
+ const itemPath = path2.join(routesPath, item.name);
55
+ if (item.isDirectory()) {
56
+ await loadRoutes(app, itemPath);
57
+ } else if (item.isFile() && item.name.endsWith(production ? ".js" : ".ts")) {
58
+ const finalPath = production ? itemPath.replace(/\.ts$/, ".js") : itemPath;
59
+ const modulePath = pathToFileURL(finalPath).href;
60
+ const modulePathWithQuery = production ? modulePath : `${modulePath}?t=${Date.now()}`;
61
+ const routeModule = await dynamicImport(modulePathWithQuery);
62
+ if (isValidRoute(routeModule)) {
63
+ const method = item.name.replace(new RegExp(`${ext}$`), "").toLowerCase();
64
+ registerRoute(app, routeModule, method, finalPath);
65
+ } else {
66
+ console.warn(`Invalid route module: ${modulePath}`);
67
+ }
68
+ }
15
69
  }
16
- return to;
17
70
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
71
+
72
+ // src/core/sparkzen.ts
73
+ async function sparkzen() {
74
+ const app = fastify().withTypeProvider();
75
+ await loadRoutes(app);
76
+ return app;
77
+ }
19
78
 
20
79
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- add: () => add
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var add = (a, b) => a + b;
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- add
30
- });
80
+ import { Type } from "@sinclair/typebox";
81
+ var index_default = sparkzen;
82
+ export {
83
+ Type as T,
84
+ index_default as default
85
+ };
package/package.json CHANGED
@@ -1,22 +1,42 @@
1
1
  {
2
2
  "name": "sparkzen",
3
+ "version": "1.0.0",
3
4
  "license": "MIT",
4
- "version": "0.0.3",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
5
+ "author": "Matheus dos Santos Paixão",
6
+ "type": "module",
8
7
  "private": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "bin": "./dist/cli/index.js",
11
+ "files": [
12
+ "dist"
13
+ ],
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
17
+ "dependencies": {
18
+ "@fastify/type-provider-typebox": "^6.1.0",
19
+ "@sinclair/typebox": "^0.34.41",
20
+ "commander": "^14.0.2",
21
+ "degit": "^2.8.4",
22
+ "enquirer": "^2.4.1",
23
+ "fastify": "^5.6.1",
24
+ "fs-extra": "^11.3.2"
25
+ },
12
26
  "devDependencies": {
13
27
  "@changesets/cli": "^2.29.7",
28
+ "@types/degit": "^2.8.6",
29
+ "@types/fs-extra": "^11.0.4",
30
+ "@types/node": "^24.9.2",
14
31
  "tsup": "^8.5.0",
15
- "typescript": "^5.9.3"
32
+ "typescript": "^5.6.3",
33
+ "vitest": "^4.0.6"
16
34
  },
17
35
  "scripts": {
18
- "build": "tsup src/index.ts --format cjs,esm --dts",
19
- "release": "pnpm run build && changeset publish",
20
- "lint": "tsc"
36
+ "build": "tsup src/index.ts src/cli/index.ts --format esm --dts --out-dir dist",
37
+ "dev": "tsup src/index.ts src/cli/index.ts --format esm --dts --watch --out-dir dist",
38
+ "lint": "tsc --noEmit",
39
+ "test": "vitest",
40
+ "release": "pnpm run build && changeset publish"
21
41
  }
22
42
  }
@@ -1,8 +0,0 @@
1
- # Changesets
2
-
3
- Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
- with multi-package repos, or single-package repos to help you version and publish your code. You can
5
- find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
-
7
- We have a quick list of common questions to get you started engaging with this project in
8
- [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3
- "changelog": "@changesets/cli/changelog",
4
- "commit": false,
5
- "fixed": [],
6
- "linked": [],
7
- "access": "restricted",
8
- "baseBranch": "main",
9
- "updateInternalDependencies": "patch",
10
- "ignore": []
11
- }
@@ -1,35 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- push:
5
- branches:
6
- - "**"
7
- pull_request:
8
-
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
-
13
- steps:
14
- - name: Checkout code
15
- uses: actions/checkout@v4
16
-
17
- - name: Setup pnpm
18
- uses: pnpm/action-setup@v4
19
- with:
20
- version: 9
21
-
22
- - name: Setup Node.js
23
- uses: actions/setup-node@v4
24
- with:
25
- node-version: 20
26
- cache: pnpm
27
-
28
- - name: Install dependencies
29
- run: pnpm install --frozen-lockfile
30
-
31
- - name: Lint
32
- run: pnpm run lint
33
-
34
- - name: Build
35
- run: pnpm run build
@@ -1,45 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- workflow_run:
5
- workflows: ["CI"]
6
- branches: [main]
7
- types: [completed]
8
-
9
- concurrency: ${{ github.workflow }}-${{ github.ref }}
10
-
11
- permissions:
12
- contents: write
13
- pull-requests: write
14
-
15
- jobs:
16
- publish:
17
- if: ${{ github.event.workflow_run.conclusion == 'success' }}
18
- runs-on: ubuntu-latest
19
-
20
- steps:
21
- - name: Checkout code
22
- uses: actions/checkout@v4
23
-
24
- - name: Setup pnpm
25
- uses: pnpm/action-setup@v4
26
- with:
27
- version: 9
28
-
29
- - name: Setup Node.js
30
- uses: actions/setup-node@v4
31
- with:
32
- node-version: 20
33
- cache: pnpm
34
-
35
- - name: Install dependencies
36
- run: pnpm install --frozen-lockfile
37
-
38
- - name: Create Release Pull Request or Publish
39
- id: changesets
40
- uses: changesets/action@v1
41
- with:
42
- publish: pnpm run release
43
- env:
44
- GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
45
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- # my-package
2
-
3
- ## 0.0.3
4
-
5
- ### Patch Changes
6
-
7
- - ec69145: Publish!
8
-
9
- ## 0.0.2
10
-
11
- ### Patch Changes
12
-
13
- - 59c2b5e: Added the add function.
package/dist/index.d.mts DELETED
@@ -1,3 +0,0 @@
1
- declare const add: (a: number, b: number) => number;
2
-
3
- export { add };
package/dist/index.mjs DELETED
@@ -1,5 +0,0 @@
1
- // src/index.ts
2
- var add = (a, b) => a + b;
3
- export {
4
- add
5
- };
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export const add = (a: number, b: number) => a + b; // Publish!!
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "skipLibCheck": true,
5
- "target": "es2022",
6
- "verbatimModuleSyntax": true,
7
- "allowJs": true,
8
- "resolveJsonModule": true,
9
- "moduleDetection": "force",
10
- "strict": true,
11
- "noUncheckedIndexedAccess": true,
12
- "moduleResolution": "Bundler",
13
- "module": "ESNext",
14
- "noEmit": true
15
- }
16
- }