@asterflow/cli 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.
@@ -0,0 +1,8 @@
1
+ import type { AdapterDefinition } from '../registry/adapters';
2
+ import type { PluginDefinition } from '../registry/plugins';
3
+ export interface PackageJsonOptions {
4
+ name: string;
5
+ adapter: AdapterDefinition;
6
+ plugins: PluginDefinition[];
7
+ }
8
+ export declare function generatePackage({ name, adapter, plugins }: PackageJsonOptions): string;
@@ -0,0 +1,9 @@
1
+ export interface RoutesOptions {
2
+ pluginIds: string[];
3
+ templateIds: string[];
4
+ }
5
+ export interface RouteFile {
6
+ fileName: string;
7
+ content: string;
8
+ }
9
+ export declare function generateRoutes({ pluginIds, templateIds }: RoutesOptions): Promise<RouteFile[]>;
@@ -0,0 +1,4 @@
1
+ /** Reads a static file from `packages/cli/templates/<name>`, verbatim. */
2
+ export declare function readTemplate(name: string): Promise<string>;
3
+ /** Copies a static file from `packages/cli/templates/<name>` to `destPath`, verbatim. */
4
+ export declare function copyTemplate(name: string, destPath: string): Promise<void>;
@@ -0,0 +1,2 @@
1
+ /** Initializes a git repo at `root` with an initial commit. No-op (returns false) if git is missing or `root` is already inside a repo. */
2
+ export declare function tryGitInit(root: string): boolean;
@@ -0,0 +1,2 @@
1
+ /** Reports (and prints) whether `root` is safe to scaffold into - empty, or containing only files from `ALLOWED_ENTRIES`. */
2
+ export declare function isFolderEmpty(root: string, name: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function isWriteable(directory: string): Promise<boolean>;
@@ -0,0 +1,7 @@
1
+ export type ValidateProjectNameResult = {
2
+ valid: true;
3
+ } | {
4
+ valid: false;
5
+ problems: string[];
6
+ };
7
+ export declare function validateProjectName(name: string): ValidateProjectNameResult;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,16 @@
1
+ export interface AdapterDefinition {
2
+ id: string;
3
+ label: string;
4
+ /** npm package name, or `null` when the adapter needs no extra dependency (bun/node are built in). */
5
+ dependency: string | null;
6
+ /** Import lines needed at the top of the generated entry file, beyond `adapters` itself. */
7
+ imports: string[];
8
+ /** Expression passed as `driver` to `new AsterFlow({ driver: ... })`. */
9
+ driverExpression: string;
10
+ /** Statement placed before the exported chain, e.g. `const server = express()`. `null` when nothing is needed. */
11
+ preamble: string | null;
12
+ /** Everything after `.listen` - arguments and callback - appended to the exported chain. */
13
+ listenCall: string;
14
+ }
15
+ export declare const ADAPTER_REGISTRY: Record<string, AdapterDefinition>;
16
+ export declare const ADAPTER_IDS: string[];
@@ -0,0 +1,14 @@
1
+ export interface PluginDefinition {
2
+ id: string;
3
+ packageName: string;
4
+ version: string;
5
+ description: string;
6
+ /** Binding name imported from the plugin's package, e.g. `multipartPlugin`. */
7
+ importName: string;
8
+ /** Appended as a `.use(...)` call in the generated `app` chain. */
9
+ useSnippet: string;
10
+ /** Printed by `add`/`init` after wiring - anything the user still has to do by hand. */
11
+ usageNote: string;
12
+ }
13
+ export declare const PLUGIN_REGISTRY: Record<string, PluginDefinition>;
14
+ export declare const PLUGIN_IDS: string[];
@@ -0,0 +1,11 @@
1
+ export interface RouteTemplate {
2
+ id: string;
3
+ path: string;
4
+ source: string;
5
+ plugin?: string;
6
+ summary: string;
7
+ }
8
+ export declare const TEMPLATE_REGISTRY: Record<string, RouteTemplate>;
9
+ export declare const TEMPLATE_IDS: string[];
10
+ export declare function availableTemplates(pluginIds: string[]): RouteTemplate[];
11
+ export declare function templateTarget(template: RouteTemplate): string;
@@ -0,0 +1,7 @@
1
+ export declare const log: {
2
+ info: (message: string) => void;
3
+ success: (message: string) => void;
4
+ warn: (message: string) => void;
5
+ error: (message: string) => void;
6
+ step: (message: string) => void;
7
+ };
@@ -0,0 +1,7 @@
1
+ export type PackageManager = 'bun' | 'pnpm' | 'yarn' | 'npm';
2
+ /** Detects the package manager in use for `cwd`, based on lockfiles present, defaulting to `bun`. */
3
+ export declare function detectPackageManager(cwd: string): PackageManager;
4
+ /** `explicit` (e.g. from `--use-npm`/`--use-pnpm`/`--use-yarn`/`--use-bun`) wins over lockfile detection. */
5
+ export declare function resolvePackageManager(explicit: PackageManager | undefined, cwd: string): PackageManager;
6
+ export declare function installCommand(manager: PackageManager): string;
7
+ export declare function addCommand(manager: PackageManager, packages: string[]): string;
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@asterflow/cli",
3
+ "version": "0.1.0",
4
+ "description": "CLI for scaffolding AsterFlow projects, adding plugins, and generating the static fs-routing manifest.",
5
+ "keywords": [
6
+ "asterflow",
7
+ "cli",
8
+ "scaffolding",
9
+ "generator"
10
+ ],
11
+ "main": "dist/cjs/index.cjs",
12
+ "module": "dist/mjs/index.js",
13
+ "types": "dist/types/index.d.ts",
14
+ "typings": "dist/types/index.d.ts",
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "author": "Ashu11-A",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/AsterFlow/AsterFlow.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/AsterFlow/AsterFlow/issues"
24
+ },
25
+ "homepage": "https://github.com/AsterFlow/AsterFlow",
26
+ "bin": {
27
+ "asterflow": "dist/cjs/index.cjs"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "types": "./dist/types/index.d.ts",
32
+ "import": "./dist/mjs/index.js",
33
+ "require": "./dist/cjs/index.cjs"
34
+ }
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "scripts": {
40
+ "dev": "bun run src/index.ts"
41
+ },
42
+ "dependencies": {
43
+ "@asterflow/fs": "^2.0.0",
44
+ "@clack/prompts": "^0.9.1",
45
+ "chalk": "^4.1.2",
46
+ "ci-info": "^4.1.0",
47
+ "validate-npm-package-name": "^6.0.0",
48
+ "yargs": "^18.0.0"
49
+ },
50
+ "devDependencies": {
51
+ "@types/validate-npm-package-name": "^4.0.2",
52
+ "@types/yargs": "^17.0.33"
53
+ },
54
+ "peerDependencies": {
55
+ "typescript": "^5.8.3"
56
+ }
57
+ }
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ .env
@@ -0,0 +1,7 @@
1
+ // Maintainer-only - not one of the example routes (`generators/routes.ts`
2
+ // never reads this file, so it's never shipped to a scaffolded project). Pulls in
3
+ // @asterflow/multipart's module augmentation (adds `.multipart(...)` to
4
+ // `Method`) so `upload.ts` typechecks standalone here, the same way it does
5
+ // in a real scaffolded project once that project's `src/index.ts` imports
6
+ // the plugin.
7
+ import '@asterflow/multipart'
@@ -0,0 +1,7 @@
1
+ import { Method } from '@asterflow/router'
2
+
3
+ export default new Method(Method.GET, {
4
+ handler({ response }) {
5
+ return response.success({ message: 'Hello from AsterFlow!' })
6
+ }
7
+ })
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "paths": {
5
+ "asterflow": ["../core/src/index.ts"],
6
+ "@asterflow/multipart": ["../plugins/multipart/src/index.ts"],
7
+ "@asterflow/*": ["./*/src/index.ts"]
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,15 @@
1
+ import { Method } from '@asterflow/router'
2
+
3
+ export default Method.create(Method.POST)
4
+ .multipart({
5
+ avatar: { mimeTypes: ['image/png', 'image/jpeg'], maxSize: 5 * 1024 * 1024, required: true }
6
+ })
7
+ .handler(({ request, response }) => {
8
+ const avatar = request.getFile('avatar')
9
+
10
+ return response.success({
11
+ filename: avatar.filename,
12
+ mimeType: avatar.mimeType,
13
+ size: avatar.size
14
+ })
15
+ })
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["ESNext"],
4
+ "target": "ESNext",
5
+ "module": "ESNext",
6
+ "moduleDetection": "force",
7
+ "allowJs": true,
8
+ "moduleResolution": "bundler",
9
+ "allowImportingTsExtensions": true,
10
+ "verbatimModuleSyntax": true,
11
+ "noEmit": true,
12
+ "strict": true,
13
+ "skipLibCheck": true,
14
+ "noFallthroughCasesInSwitch": true,
15
+ "noUncheckedIndexedAccess": true
16
+ }
17
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": [
4
+ "bun-types"
5
+ ]
6
+ },
7
+ "exclude": [
8
+ "templates"
9
+ ],
10
+ "include": [
11
+ "dist"
12
+ ]
13
+ }