feat(plugin-cli): add cli af (#3465)

This commit is contained in:
Alex Yang
2023-07-30 11:10:45 -07:00
committed by GitHub
parent 568d5e4cdf
commit 18fcaff5ee
27 changed files with 469 additions and 59 deletions
+1 -3
View File
@@ -4,8 +4,7 @@
"private": true,
"bin": {
"build-core": "./src/bin/build-core.mjs",
"dev-core": "./src/bin/dev-core.mjs",
"dev-plugin": "./src/bin/dev-plugin.mjs"
"dev-core": "./src/bin/dev-core.mjs"
},
"exports": {
"./config": "./src/config/index.ts"
@@ -13,7 +12,6 @@
"devDependencies": {
"@clack/core": "^0.3.2",
"@clack/prompts": "^0.6.3",
"@endo/static-module-record": "^0.7.20",
"ts-node": "^10.9.1"
},
"dependencies": {
+21
View File
@@ -0,0 +1,21 @@
{
"name": "@affine/plugin-cli",
"type": "module",
"version": "0.8.0-canary.3",
"bin": {
"af": "./src/af.mjs"
},
"files": [
"src",
"tsconfig.json"
],
"dependencies": {
"@endo/static-module-record": "^0.7.20",
"@swc/core": "^1.3.72",
"@toeverything/plugin-infra": "workspace:^",
"@vanilla-extract/rollup-plugin": "^1.2.2",
"rollup": "^3.27.0",
"rollup-plugin-swc3": "^0.9.1",
"ts-node": "^10.9.1"
}
}
@@ -7,7 +7,7 @@ const child = spawnSync(
[
'--loader',
'ts-node/esm/transpile-only',
fileURLToPath(new URL('./dev-plugin.ts', import.meta.url)),
fileURLToPath(new URL('./af.ts', import.meta.url)),
...process.argv.slice(2),
],
{ stdio: 'inherit' }
@@ -1,7 +1,7 @@
import { ok } from 'node:assert';
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
import { StaticModuleRecord } from '@endo/static-module-record';
@@ -14,31 +14,23 @@ import react from '@vitejs/plugin-react-swc';
import { build, type PluginOption } from 'vite';
import type { z } from 'zod';
import { projectRoot } from '../config/index.js';
const projectRoot = fileURLToPath(new URL('../../..', import.meta.url));
const args = process.argv.splice(2);
const result = parseArgs({
args,
options: {
watch: {
type: 'boolean',
default: false,
},
plugin: {
type: 'string',
},
},
allowPositionals: true,
});
const plugin = result.values.plugin;
if (typeof plugin !== 'string') {
throw new Error('plugin is required');
const plugin = process.cwd().split(path.sep).pop();
if (!plugin) {
throw new Error('plugin name not found');
}
const isWatch = result.values.watch;
ok(typeof isWatch === 'boolean');
const command = result.positionals[0];
const isWatch = command === 'dev';
const external = [
// built-in packages
@@ -119,7 +111,7 @@ const generatePackageJson: PluginOption = {
affinePlugin: {
release: json.affinePlugin.release,
entry: {
core: 'index.mjs',
core: 'index.js',
},
assets: [...metadata.assets],
serverCommand: json.affinePlugin.serverCommand,
+15
View File
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"outDir": "lib"
},
"include": ["src"],
"references": [
{
"path": "../plugin-infra"
}
]
}