forked from marko-js/marko
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VFS support with check for "generated" to allow native lookups
- Loading branch information
Showing
7 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var compiler = require("./compiler"); | ||
var { fs, vol } = require("memfs"); | ||
|
||
var componentCode = | ||
"<div> \ | ||
<p>Hello ${input.name}!</p> \ | ||
<button if(input.renderBody)> \ | ||
<include(input.renderBody)/> \ | ||
</button> \ | ||
</div>"; | ||
|
||
var sourceCode = `class { | ||
onCreate() { | ||
this.state = { | ||
mounted: false | ||
}; | ||
} | ||
onMount() { | ||
this.state.mounted = true; | ||
} | ||
} | ||
<div> | ||
<p if(state.mounted)> | ||
UI component successfully mounted! | ||
<ContentBox name='Frank'> Shop Now </ContentBox> | ||
</p> | ||
</div>`; | ||
|
||
/* Configure the VFS */ | ||
compiler.configureVFS(fs); | ||
|
||
var cwd = process.cwd(); | ||
vol.mkdirpSync(cwd + "/src/generated/components/ContentBox/"); | ||
fs.writeFileSync( | ||
cwd + "/src/generated/components/ContentBox/index.marko", | ||
componentCode, | ||
"utf8" | ||
); | ||
|
||
var tab_json = { | ||
"tags-dir": [cwd + "/src/generated/components"] | ||
}; | ||
|
||
// var tab_json = { | ||
// "<ContentBox>": { "template": cwd + "/src/generated/components/ContentBox/index.marko"} | ||
// } | ||
|
||
fs.writeFileSync(cwd + "/src/generated/marko.json", JSON.stringify(tab_json)); | ||
compiler.registerTaglib(cwd + "/src/generated/marko.json"); | ||
|
||
vol.mkdirpSync(cwd + "/src/generated/templates/example01/"); | ||
var filePath = cwd + "/src/generated/templates/example01/index.marko"; | ||
fs.writeFileSync(filePath, sourceCode); | ||
|
||
var compiled = compiler.compileFile(filePath, { | ||
output: "vdom", | ||
browser: true, | ||
writeVersionComment: false, | ||
sourceOnly: false, | ||
meta: false | ||
}); | ||
|
||
var compiledSrc = compiled.code; | ||
fs.writeFileSync( | ||
cwd + "/src/generated/templates/example01/index.marko.js", | ||
compiledSrc | ||
); |