Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom template #196

Merged
merged 4 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export interface StoreOptions {
defaultVueRuntimeProdURL?: string
defaultVueServerRendererURL?: string
customElement?: boolean | string | RegExp | (string | RegExp)[]
welcomeFileTemplate?: string
newSFCTemplate?: string
}

export class ReplStore implements Store {
Expand All @@ -134,6 +136,8 @@ export class ReplStore implements Store {
private defaultVueRuntimeProdURL: string
private defaultVueServerRendererURL: string
private pendingCompiler: Promise<any> | null = null
private welcomeFileTemplate?: string
private newSFCTemplate?: string

constructor({
serializedState = '',
Expand All @@ -144,16 +148,20 @@ export class ReplStore implements Store {
outputMode = 'preview',
productionMode = false,
customElement = /\.ce\.vue$/,
welcomeFileTemplate = welcomeCode,
newSFCTemplate = newSFCCode,
}: StoreOptions = {}) {
const files: StoreState['files'] = {}
this.welcomeFileTemplate = welcomeFileTemplate
this.newSFCTemplate = newSFCTemplate

if (serializedState) {
const saved = JSON.parse(atou(serializedState))
for (const filename in saved) {
setFile(files, filename, saved[filename])
}
} else {
setFile(files, defaultMainFile, welcomeCode)
setFile(files, defaultMainFile, this.welcomeFileTemplate)
}

this.productionMode = productionMode
Expand Down Expand Up @@ -250,7 +258,7 @@ export class ReplStore implements Store {
if (typeof fileOrFilename === 'string') {
file = new File(
fileOrFilename,
fileOrFilename.endsWith('.vue') ? newSFCCode : ''
fileOrFilename.endsWith('.vue') ? this.newSFCTemplate : ''
)
} else {
file = fileOrFilename
Expand Down