mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
feat(plugin-infra): add package.json schema (#3456)
This commit is contained in:
@@ -3,10 +3,14 @@ import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { parseArgs } from 'node:util';
|
||||
|
||||
import {
|
||||
packageJsonInputSchema,
|
||||
packageJsonOutputSchema,
|
||||
} from '@toeverything/plugin-infra/type';
|
||||
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
|
||||
import react from '@vitejs/plugin-react-swc';
|
||||
import { build } from 'vite';
|
||||
import { z } from 'zod';
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { projectRoot } from '../config/index.js';
|
||||
|
||||
@@ -34,17 +38,6 @@ if (typeof plugin !== 'string') {
|
||||
const isWatch = result.values.watch;
|
||||
ok(typeof isWatch === 'boolean');
|
||||
|
||||
const packageJsonSchema = z.object({
|
||||
name: z.string(),
|
||||
affinePlugin: z.object({
|
||||
release: z.boolean(),
|
||||
entry: z.object({
|
||||
core: z.string(),
|
||||
server: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
const external = [
|
||||
// built-in packages
|
||||
/^@affine/,
|
||||
@@ -71,7 +64,7 @@ const getPluginDir = (plugin: string) => path.resolve(allPluginDir, plugin);
|
||||
const pluginDir = getPluginDir(plugin);
|
||||
const packageJsonFile = path.resolve(pluginDir, 'package.json');
|
||||
|
||||
const json: z.infer<typeof packageJsonSchema> = await readFile(
|
||||
const json: z.infer<typeof packageJsonInputSchema> = await readFile(
|
||||
packageJsonFile,
|
||||
{
|
||||
encoding: 'utf-8',
|
||||
@@ -79,7 +72,7 @@ const json: z.infer<typeof packageJsonSchema> = await readFile(
|
||||
)
|
||||
.then(text => JSON.parse(text))
|
||||
.then(async json => {
|
||||
const { success } = await packageJsonSchema.safeParseAsync(json);
|
||||
const { success } = await packageJsonInputSchema.safeParseAsync(json);
|
||||
if (success) {
|
||||
return json;
|
||||
} else {
|
||||
@@ -163,6 +156,8 @@ await build({
|
||||
async generateBundle() {
|
||||
const packageJson = {
|
||||
name: json.name,
|
||||
version: json.version,
|
||||
description: json.description,
|
||||
affinePlugin: {
|
||||
release: json.affinePlugin.release,
|
||||
entry: {
|
||||
@@ -171,6 +166,7 @@ await build({
|
||||
assets: [...metadata.assets],
|
||||
},
|
||||
};
|
||||
packageJsonOutputSchema.parse(packageJson);
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: 'package.json',
|
||||
|
||||
Reference in New Issue
Block a user