From a05b252c91c6279f767ff0abd8f02b287cdfac55 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 26 Oct 2022 11:03:24 +0200 Subject: [PATCH 01/17] initial schema commit --- schema/.gitignore | 1 + schema/build.config.ts | 66 + schema/package.json | 42 + schema/src/config.ts | 12 + schema/src/config/app.ts | 272 +++ schema/src/config/build.ts | 549 ++++++ schema/src/config/cli.ts | 16 + schema/src/config/common.ts | 260 +++ schema/src/config/generate.ts | 113 ++ schema/src/config/index.ts | 40 + schema/src/config/messages.ts | 22 + schema/src/config/render.ts | 297 ++++ schema/src/config/router.ts | 146 ++ schema/src/config/server.ts | 43 + schema/src/hooks.ts | 126 ++ schema/src/index.ts | 4 + schema/yarn.lock | 2981 +++++++++++++++++++++++++++++++++ 17 files changed, 4990 insertions(+) create mode 100644 schema/.gitignore create mode 100644 schema/build.config.ts create mode 100644 schema/package.json create mode 100644 schema/src/config.ts create mode 100644 schema/src/config/app.ts create mode 100644 schema/src/config/build.ts create mode 100644 schema/src/config/cli.ts create mode 100644 schema/src/config/common.ts create mode 100644 schema/src/config/generate.ts create mode 100644 schema/src/config/index.ts create mode 100644 schema/src/config/messages.ts create mode 100644 schema/src/config/render.ts create mode 100644 schema/src/config/router.ts create mode 100644 schema/src/config/server.ts create mode 100644 schema/src/hooks.ts create mode 100644 schema/src/index.ts create mode 100644 schema/yarn.lock diff --git a/schema/.gitignore b/schema/.gitignore new file mode 100644 index 00000000..1c12cf9b --- /dev/null +++ b/schema/.gitignore @@ -0,0 +1 @@ +schema diff --git a/schema/build.config.ts b/schema/build.config.ts new file mode 100644 index 00000000..1d523916 --- /dev/null +++ b/schema/build.config.ts @@ -0,0 +1,66 @@ +import { defineBuildConfig } from 'unbuild' + +export default defineBuildConfig({ + declaration: true, + entries: [ + { + input: 'src/config/index', + outDir: 'schema', + name: 'config', + builder: 'untyped', + defaults: { + dev: false, + ssr: true, + buildAssetsDir: '_nuxt', + srcDir: '', + buildDir: '.nuxt', + dir: { + store: 'store' + }, + loading: {}, + sourcemap: {}, + vue: {}, + manifest: {}, + messages: {}, + postcss: {}, + build: {}, + generate: {}, + app: {}, + _nuxtConfigFiles: [], + rootDir: '//', + vite: { + base: '/' + } + } + }, + 'src/index', + ], + externals: [ + // Type imports + 'vue-meta', + 'vue-router', + 'vue-bundle-renderer', + '@vueuse/head', + 'vue', + 'hookable', + 'nitropack', + 'webpack', + 'webpack-bundle-analyzer', + 'rollup-plugin-visualizer', + 'vite', + '@vitejs/plugin-vue', + 'mini-css-extract-plugin', + 'terser-webpack-plugin', + 'css-minimizer-webpack-plugin', + 'webpack-dev-middleware', + 'h3', + 'webpack-hot-middleware', + 'postcss', + 'consola', + 'ignore', + // Implicit + '@vue/compiler-core', + '@vue/shared', + 'untyped' + ] +}) diff --git a/schema/package.json b/schema/package.json new file mode 100644 index 00000000..e98f44bc --- /dev/null +++ b/schema/package.json @@ -0,0 +1,42 @@ +{ + "name": "@nuxt/bridge-schema", + "version": "3.0.0-rc.12", + "repository": "nuxt/framework", + "license": "MIT", + "type": "module", + "main": "./dist/index.mjs", + "types": "./dist/index.d.ts", + "files": [ + "dist", + "schema" + ], + "scripts": { + "build": "unbuild" + }, + "devDependencies": { + "@types/lodash.template": "^4", + "@types/semver": "^7", + "@vitejs/plugin-vue": "^3.1.2", + "@vueuse/head": "~1.0.0-rc.9", + "nitropack": "^0.6.0", + "unbuild": "latest", + "vite": "~3.1.8" + }, + "dependencies": { + "c12": "^0.2.13", + "create-require": "^1.1.1", + "defu": "^6.1.0", + "jiti": "^1.16.0", + "pathe": "^0.3.9", + "pkg-types": "^0.3.5", + "postcss-import-resolver": "^2.0.0", + "scule": "^0.3.2", + "std-env": "^3.3.0", + "ufo": "^0.8.6", + "unimport": "^0.6.8", + "untyped": "^0.5.0" + }, + "engines": { + "node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } +} diff --git a/schema/src/config.ts b/schema/src/config.ts new file mode 100644 index 00000000..a65ce0dc --- /dev/null +++ b/schema/src/config.ts @@ -0,0 +1,12 @@ +import { ConfigSchema } from '../schema/config' + +type DeepPartial = T extends Function ? T : T extends Record ? { [P in keyof T]?: DeepPartial } : T + +/** User configuration in `nuxt.config` file */ +export interface Nuxt2Config extends DeepPartial> { + [key: string]: any +} + +/** Normalized Nuxt options available as `nuxt.options.*` */ +export interface Nuxt2Options extends ConfigSchema { +} diff --git a/schema/src/config/app.ts b/schema/src/config/app.ts new file mode 100644 index 00000000..d1cd57ef --- /dev/null +++ b/schema/src/config/app.ts @@ -0,0 +1,272 @@ +import { defineUntypedSchema } from 'untyped' +import { resolve, join } from 'pathe' +import { existsSync, readdirSync } from 'node:fs' +import defu from 'defu' + +export default defineUntypedSchema({ + vue: { + /** + * Properties that will be set directly on `Vue.config` for vue@2. + * + * @see [vue@2 Documentation](https://v2.vuejs.org/v2/api/#Global-Config) + * @type {typeof import('vue/types/vue').VueConfiguration} + */ + config: { + silent: { + $resolve: async (val, get) => val ?? !(await get('dev')) + }, + performance: { + $resolve: async (val, get) => val ?? await get('dev') + }, + }, + }, + + app: { + /** + * The folder name for the built site assets, relative to `baseURL` (or `cdnURL` if set). + * @deprecated - use `buildAssetsDir` instead + */ + assetsPath: { + $resolve: async (val, get) => val ?? (await get('buildAssetsDir')) + }, + }, + + /** + * The path to an HTML template file for rendering Nuxt responses. + * Uses `/app.html` if it exists, or the Nuxt's default template if not. + * + * @example + * ```html + * + * + * + * {{ HEAD }} + * + * + * {{ APP }} + * + * + * ``` + */ + appTemplatePath: { + $resolve: async (val, get) => { + if (val) { + return resolve(await get('srcDir'), val) + } + if (existsSync(join(await get('srcDir'), 'app.html'))) { + return join(await get('srcDir'), 'app.html') + } + return resolve(await get('buildDir'), 'views/app.template.html') + } + }, + + /** + * Enable or disable Vuex store. + * + * By default, it is enabled if there is a `store/` directory. + */ + store: { + $resolve: async (val, get) => val !== false && + existsSync(join(await get('srcDir'), await get('dir.store'))) && + readdirSync(join(await get('srcDir'), await get('dir.store'))) + .find(filename => filename !== 'README.md' && filename[0] !== '.') + }, + + /** + * Options to pass directly to `vue-meta`. + * + * @see [documentation](https://vue-meta.nuxtjs.org/api/#plugin-options). + * @type {typeof import('vue-meta').VueMetaOptions} + */ + vueMeta: null, + + /** + * Set default configuration for `` on every page. + * + * @see [documentation](https://vue-meta.nuxtjs.org/api/#metainfo-properties) for specifics. + * @type {typeof import('vue-meta').MetaInfo} + */ + head: { + /** Each item in the array maps to a newly-created `` element, where object properties map to attributes. */ + meta: [], + /** Each item in the array maps to a newly-created `` element, where object properties map to attributes. */ + link: [], + /** Each item in the array maps to a newly-created `