Skip to content

Commit

Permalink
feat: support custom template (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinweiOS authored Jan 4, 2024
1 parent 7ae1061 commit 8038b49
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 8038b49

Please sign in to comment.