| 14 | const ensureFolderEndsInSlash = folder => folder.replace(/\/$/, "") + "/" |
| 15 | |
| 16 | class ScrollCli extends SimpleCLI { |
| 17 | welcomeMessage = `\n📜 WELCOME TO SCROLL (v${packageJson.version})` |
| 18 | async initCommand(cwd) { |
| 19 | // todo: use stamp for this. |
| 20 | const initFolder = { |
| 21 | ".gitignore": `*.html |
| 22 | *.rss |
| 23 | *.txt |
| 24 | .*.js |
| 25 | .*.css |
| 26 | feed.xml`, |
| 27 | "header.scroll": `importOnly |
| 28 | metaTags |
| 29 | buildTxt |
| 30 | buildHtml |
| 31 | theme gazette |
| 32 | homeButton |
| 33 | leftRightButtons |
| 34 | editButton |
| 35 | printTitle`, |
| 36 | "feed.scroll": `buildRss |
| 37 | printFeed All`, |
| 38 | "footer.scroll": `importOnly |
| 39 | center |
| 40 | editButton |
| 41 | scrollVersionLink`, |
| 42 | "helloWorld.scroll": `tags All |
| 43 | header.scroll |
| 44 | thinColumn |
| 45 | This is my first blog post using Scroll. |
| 46 | |
| 47 | **** |
| 48 | |
| 49 | footer.scroll`, |
| 50 | "index.scroll": `title My Blog |
| 51 | header.scroll |
| 52 | printSnippets All |
| 53 | footer.scroll` |
| 54 | } |
| 55 | |
| 56 | this.log(`Initializing scroll in "${cwd}"`) |
| 57 | Disk.writeObjectToDisk(cwd, initFolder) |
| 58 | require("child_process").execSync("git init", { cwd }) |
| 59 | return this.log(`\n✅ Initialized new scroll in '${cwd}'. Build your new site with: scroll build`) |
| 60 | } |
| 61 | |
| 62 | async scrollToHtml(scrollCode) { |
| 63 | const file = this.sfs.newFile(scrollCode) |
| 64 | await file.singlePassFuse() |
| 65 | return file.scrollProgram.asHtml |
| 66 | } |
| 67 | |
| 68 | sfs = new ScrollFileSystem(undefined, path.join(__dirname, "parsers")) |
| 69 | initFs(obj) { |
| 70 | // for testing |
| 71 | this.sfs = new ScrollFileSystem(obj, path.join(__dirname, "parsers")) |
| 72 | return this.sfs |
| 73 | } |