Skip to content

Commit

Permalink
Define public api for CLI (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitenite committed Sep 18, 2024
1 parent 78a2a6f commit 20abe2d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 81 deletions.
Binary file modified cli/bun.lockb
Binary file not shown.
98 changes: 50 additions & 48 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
{
"name": "onlook",
"description": "The Onlook Command Line Interface",
"version": "0.0.8",
"main": "dist/index.js",
"bin": {
"onlook": "dist/index.cjs"
},
"directories": {
"test": "tests"
},
"scripts": {
"esbuild": "esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs",
"dev": "npm run esbuild -- --watch",
"build": "tsc --noEmit --skipLibCheck src/index.ts && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.cjs --define:PACKAGE_VERSION=\\\"$npm_package_version\\\"",
"build:notype": "npm run esbuild",
"test": "bun test"
},
"keywords": [
"npx",
"onlook",
"setup",
"plugins"
],
"author": {
"name": "Onlook",
"email": "[email protected]"
},
"license": "Apache-2.0",
"homepage": "https://onlook.dev",
"devDependencies": {
"@types/babel__generator": "^7.6.8",
"@types/babel__traverse": "^7.20.6",
"@types/bun": "latest",
"@types/degit": "^2.8.6",
"esbuild": "^0.23.1",
"tslib": "^2.6.3",
"typescript": "^5.0.0"
},
"dependencies": {
"@babel/generator": "^7.14.5",
"@babel/parser": "^7.14.3",
"@babel/traverse": "^7.14.5",
"@babel/types": "^7.14.5",
"commander": "^12.1.0",
"degit": "^2.8.4",
"glob": "^11.0.0",
"ora": "^8.1.0"
}
"name": "onlook",
"description": "The Onlook Command Line Interface",
"version": "0.0.8",
"main": "dist/api/index.mjs",
"module": "dist/api/index.mjs",
"bin": {
"onlook": "dist/cli/index.cjs"
},
"directories": {
"test": "tests"
},
"scripts": {
"dev": "npm run esbuild -- --watch",
"esbuild": "esbuild src/cli/index.ts --bundle --platform=node --format=cjs --outfile=dist/cli/index.cjs",
"build": "tsc --noEmit --skipLibCheck src/cli/index.ts && esbuild src/cli/index.ts --bundle --platform=node --format=cjs --outfile=dist/cli/index.cjs --define:PACKAGE_VERSION=\\\"$npm_package_version\\\"",
"build:notype": "npm run esbuild",
"build:api": "tsc --noEmit --skipLibCheck src/api/index.ts && esbuild src/api/index.ts --bundle --platform=node --format=esm --outfile=dist/api/index.mjs",
"test": "bun test"
},
"keywords": [
"npx",
"onlook",
"setup",
"plugins"
],
"author": {
"name": "Onlook",
"email": "[email protected]"
},
"license": "Apache-2.0",
"homepage": "https://onlook.dev",
"devDependencies": {
"@types/babel__generator": "^7.6.8",
"@types/babel__traverse": "^7.20.6",
"@types/bun": "latest",
"@types/degit": "^2.8.6",
"esbuild": "^0.23.1",
"tslib": "^2.6.3",
"typescript": "^5.0.0"
},
"dependencies": {
"@babel/generator": "^7.14.5",
"@babel/parser": "^7.14.3",
"@babel/traverse": "^7.14.5",
"@babel/types": "^7.14.5",
"commander": "^12.1.0",
"degit": "^2.8.4",
"glob": "^11.0.0",
"ora": "^8.1.0"
}
}
14 changes: 14 additions & 0 deletions cli/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { ApiResponse } from "../models";

export function isOnlookEnabled(folder: string): Promise<ApiResponse<boolean>> {
return Promise.resolve({
status: 'success',
data: true
});
}

export function createProject(folder: string, name: string): Promise<ApiResponse> {
return Promise.resolve({
status: 'success'
});
}
4 changes: 2 additions & 2 deletions cli/src/index.ts → cli/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { Command } from 'commander';
import { create } from './create';
import { setup } from './setup';
import { create } from '../create';
import { setup } from '../setup';

declare let PACKAGE_VERSION: string;

Expand Down
14 changes: 14 additions & 0 deletions cli/src/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type ApiResponse<T = void> = SuccessResponse<T> | ErrorResponse;

export type SuccessResponse<T = void> = {
status: 'success';
data?: T;
};

export type ErrorResponse = {
status: 'error';
error: {
message: string;
code: string;
};
};
2 changes: 1 addition & 1 deletion cli/tests/program.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterAll, expect, jest, mock, test } from "bun:test";
import { createProgram } from "../src";
import { createProgram } from "../src/cli";
import { setup } from "../src/setup";

const originalConsoleLog = console.log;
Expand Down
56 changes: 28 additions & 28 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"include": [
"src",
"tests"
],
"compilerOptions": {
// Enable latest features
"lib": [
"ESNext",
"DOM"
"include": [
"src",
"tests"
],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false,
}
"compilerOptions": {
// Enable latest features
"lib": [
"ESNext",
"DOM"
],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false,
}
}
Binary file modified demos/next/bun.lockb
Binary file not shown.
3 changes: 1 addition & 2 deletions demos/next/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import path from "path";

const nextConfig = {
reactStrictMode: true,
experimental: {
swcPlugins: [["@onlook/nextjs", { root: path.resolve(".") }]],
},
}
};
export default nextConfig;

0 comments on commit 20abe2d

Please sign in to comment.