Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
feat: update PergelOptions import and function signatures (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
productdevbook authored Dec 10, 2023
1 parent 14f0793 commit 7b4f26d
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/nuxt/client/composables/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ref } from 'vue'
import type { ModuleOptions } from '../../src/core/types'
import type { PergelOptions } from '../../src/core/types'

export const options = ref<ModuleOptions>()
export const options = ref<PergelOptions>()
4 changes: 2 additions & 2 deletions packages/nuxt/src/core/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '@nuxt/devtools-kit'
import type {
ClientFunctions,
ModuleOptions,
PergelOptions,
ServerFunctions,
} from './types'
import { useViteWebSocket } from './utils'
Expand All @@ -23,7 +23,7 @@ import {
} from './constants'

export function setupDevToolsUI(
options: ModuleOptions,
options: PergelOptions,
resolve: Resolver['resolve'],
nuxt: Nuxt,
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/core/types/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { Nuxt } from 'nuxt/schema'
import type { WebSocketServer } from 'vite'
import type { ModuleOptions } from './module'
import type { PergelOptions } from './module'

export interface ServerFunctions {
getOptions(): ModuleOptions
getOptions(): PergelOptions

reset(): void
}
Expand All @@ -13,6 +13,6 @@ export interface ClientFunctions {

export interface DevtoolsServerContext {
nuxt: Nuxt
options: ModuleOptions
options: PergelOptions
wsServer: Promise<WebSocketServer>
}
295 changes: 294 additions & 1 deletion packages/nuxt/src/core/types/module.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,295 @@
export interface ModuleOptions {
/**
* @credit
* https://github.com/nuxt/nuxt/blob/main/packages/schema/src/types/module.ts
*/

import type { Nuxt } from '@nuxt/schema'

export interface Modules {
S3?: true
}

export interface PergelOptions {
/**
* @default {}
* @example
* {
* project1: {
* S3: true,
* },
* project2: {
* S3: true,
* },
* }
*/
projects: {
[project: string]: Modules
}
/**
* The root folder of the pergel folder.
* @default 'pergel'
* @example '/users/productdevbook/nuxt3/pergel'
*/
pergelDir?: string

/**
* The root folder of the application.
* Defaults to the path where `nuxt.options.rootDir` is located.
* @default '/'
* @example '/playground'
*/
rootDir?: string
/**
* @default true
*/
esnext?: boolean
}

export interface ResolvedPergelOptions<T extends ModuleOptions = ModuleOptions> {
/**
* Pergel user defined options.
*/
rootOptions: Required<PergelOptions>

/**
* Root Options resolved from `rootOptions`.
*/
resolvedOptions: {

dir: {
/**
* @example
* 'pergel'
*/
pergel: string

/**
* @example
* './'
*/
root: string

/**
* @example
* 'pergel/README.yml'
*/
readme: string

}

templateDir: {
/**
* @example
* './'
*/
root: string
}

resolveDir: {

/**
* @example
* '/users/productdevbook/nuxt3/pergel/README.yml'
*/
readmeDir: string

/**
* @example
* 'users/productdevbook/nuxt3'
*/
root: string

/**
* @example
* 'users/productdevbook/nuxt3/pergel'
*/
pergelRoot: string
}

/**
* @example
* ['project1', 'project2']
*/
projectNames: string[]

}

resolvedModule: {
/**
* @example
* 'S3' | 'nodecron' | 'graphQL' | 'drizzle'
*/
name: string

/**
* End user defined module options.
* @example
* 'project1'
*/
projectName: string

/**
* @example
* 'users/productdevbook/nuxt3/pergel/${projectName}'
*/
projectDir: string
/**
* @example
* 'users/productdevbook/nuxt3/pergel/${projectName}/${moduleName}'
*/
moduleDir: string

dir: {
/**
* @example
* 'pergel/${activeBranch}/${projectName}'
*/
project: string

/**
* @example
* 'pergel/${activeBranch}/${projectName}/${moduleName}'
*/
module: string
}

templateDir: {
/**
* @example
* 'pergel'
*/
root: string
/**
* @example
* 'pergel/${projectName}/${moduleName}'
*/
module: string

/**
* @example
* 'pergel/${projectName}'
*/
project: string
}
}

_contents: {
projectName: string
moduleName: string
content: string | Promise<string>
resolve: string | Promise<string>
}[]

moduleOptions: T
}

export interface ResolvedProjectOptions {
resolvedPergelOptions: ResolvedPergelOptions
/**
* @example
* 'project1'
*/
currentProject: {
/**
* @example
* 'project1'
*/
name: string

dir: {
/**
* @example
* 'pergel/dev/${projectname}'
*/
project: string

/**
* @example
* 'pergel/project1'
*/
output: string

}
/**
* @example
* ['S3', 'nodecron', 'graphql', 'drizzle']
*/
modules: Modules
}
}

interface ModuleMeta {
/** Module name. */
name?: string
/** Module version. */
version?: string
/**
* The configuration key used within `nuxt.config` for this module's options.
* For example, `@nuxtjs/axios` uses `axios`.
*/
configKey?: string

devDependencies?: Record<string, string>
dependencies?: Record<string, string>

[key: string]: unknown
}

/** The options received. */
export type ModuleOptions = Record<string, any>

/** Optional result for nuxt modules */
export interface ModuleSetupReturn {
/**
* Timing information for the initial setup
*/
timings?: {
/** Total time took for module setup in ms */
setup?: number
[key: string]: number | undefined
}
}

export type Awaitable<T> = T | Promise<T>
type _ModuleSetupReturn = Awaitable<void | false | ModuleSetupReturn>

export interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
meta?: ModuleMeta
defaults?: T | ((nuxt: Nuxt, resolvedOptions: ResolvedPergelOptions) => T)
setup?: (
this: void,
resolvedOptions: ResolvedPergelOptions<T>,
nuxt: Nuxt
) =>
_ModuleSetupReturn
}

export interface PergelModule<T extends ModuleOptions = ModuleOptions> {
(this: void, inlineOptions: ResolvedPergelOptions<T>, nuxt: Nuxt): _ModuleSetupReturn
getOptions?: (inlineOptions?: T, nuxt?: Nuxt) => Promise<T>
getMeta?: () => ModuleMeta
}

export interface ModuleDefaults {
[module: string]: any
}

export interface ModuleIndex {
index: {
name: string
path: string
}[]
}

export type Env = string | number | undefined
export type EnvList = Record<string, Env>

export interface GenerateReadmeYamlOpts {
envs: Record<string, Record<string, EnvList>>
projectNames: string[]
}

export type PartinalKey<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
export type MaybePromise<T> = T | Promise<T>

export { }
Loading

0 comments on commit 7b4f26d

Please sign in to comment.