├── .gitignore ├── LICENSE ├── README.md ├── bin └── index.js ├── commands ├── build.js └── init.js ├── config └── rollup.config.js ├── lib └── md-to-api.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Garth Mortensen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scant 2 | 3 | This is a static site generator for Svelte. Similar to Gatsby for React. 4 | 5 | NOTE: This is currently in a very alpha state. 6 | 7 | ## Installation 8 | 9 | ```sh 10 | npm i -g scant 11 | ``` 12 | 13 | ## Usage 14 | 15 | See https://github.com/scantjs/scant-example-site for an example. 16 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | require('yargs') 3 | .commandDir('../commands') 4 | .demandCommand(1, 'You need at least one command before moving on') 5 | .help() 6 | .argv; 7 | -------------------------------------------------------------------------------- /commands/build.js: -------------------------------------------------------------------------------- 1 | const rollup = require('rollup'); 2 | const path = require('path'); 3 | const rollupConfig = require('./../config/rollup.config.js'); 4 | 5 | exports.command = 'build'; 6 | 7 | exports.desc = 'Build your site.'; 8 | 9 | exports.builder = {}; 10 | 11 | exports.handler = async () => { 12 | const directory = path.resolve('.'); 13 | const userConfig = require(path.join(directory, 'scant.config.js')); 14 | 15 | // add current directory to config object 16 | userConfig.directory = directory; 17 | 18 | // default directory for site is src 19 | userConfig.sourceDir = (() => { 20 | return userConfig.sourceDir 21 | ? path.join(userConfig.directory, userConfig.sourceDir) 22 | : path.join(userConfig.directory, 'src'); 23 | })(); 24 | 25 | // default directory for compiled site is public 26 | userConfig.buildDir = (() => { 27 | return userConfig.buildDir 28 | ? path.join(userConfig.directory, userConfig.buildDir) 29 | : path.join(userConfig.directory, 'public'); 30 | })(); 31 | 32 | await rollupBuild(); 33 | console.log('done'); 34 | }; 35 | 36 | async function rollupBuild() { 37 | const opts = { 38 | input: { 39 | input: rollupConfig.input, 40 | plugins: rollupConfig.plugins, 41 | }, 42 | output: { 43 | output: rollupConfig.output, 44 | } 45 | }; 46 | 47 | const bundle = await rollup.rollup(opts.input); 48 | await bundle.write(opts.output); 49 | } 50 | -------------------------------------------------------------------------------- /commands/init.js: -------------------------------------------------------------------------------- 1 | exports.command = 'init'; 2 | 3 | exports.desc = 'Create a new Scant site in the current directory.'; 4 | 5 | exports.builder = {}; 6 | 7 | exports.handler = () => { 8 | console.log('init'); 9 | }; 10 | -------------------------------------------------------------------------------- /config/rollup.config.js: -------------------------------------------------------------------------------- 1 | const clear = require('rollup-plugin-clear'); 2 | const svelte = require('rollup-plugin-svelte'); 3 | const copy = require('rollup-plugin-copy'); 4 | const commonjs = require('rollup-plugin-commonjs'); 5 | const { terser } = require('rollup-plugin-terser'); 6 | const resolve = require('rollup-plugin-node-resolve'); 7 | const livereload = require('rollup-plugin-livereload'); 8 | const mdToApi = require('../lib/md-to-api'); 9 | 10 | const production = !process.env.ROLLUP_WATCH; 11 | 12 | module.exports = { 13 | input: 'src/main.js', 14 | output: { 15 | sourcemap: true, 16 | format: 'esm', 17 | name: 'app', 18 | dir: 'public' 19 | }, 20 | plugins: [ 21 | clear({ 22 | targets: ['public'] 23 | }), 24 | mdToApi(), 25 | copy({ 26 | targets: { 27 | 'src/assets': 'public/assets', 28 | 'src/index.html': 'public/index.html', 29 | 'node_modules/shimport/index.js': 'public/assets/shimport.js', 30 | }, 31 | }), 32 | svelte({ 33 | dev: !production, 34 | css: css => { 35 | css.write('public/bundle.css'); 36 | }, 37 | }), 38 | resolve(), 39 | commonjs(), 40 | production && terser() 41 | ] 42 | }; 43 | -------------------------------------------------------------------------------- /lib/md-to-api.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs-extra'); 2 | const path = require('path'); 3 | const marked = require('marked'); 4 | const fm = require('gray-matter'); 5 | 6 | module.exports = function mdToApi(options = { source: 'src/content', target: 'public/content' }) { 7 | const { source, target } = options; 8 | fs.ensureDir(target); 9 | let finalBlob = []; 10 | return { 11 | name: 'md-to-api', 12 | async generateBundle(stuff) { 13 | return new Promise(async (resolve, reject) => { 14 | let files; 15 | try { 16 | files = await fs.readdir(source); 17 | } catch (err) { 18 | reject(err); 19 | } 20 | 21 | files = files.filter(file => /\.md$/.exec(file)); 22 | 23 | let loop = new Promise((resolve, reject) => { 24 | files.forEach(async (file, i) => { 25 | const sourcePath = path.resolve(source, file); 26 | const content = await fs.readFile(sourcePath); 27 | 28 | let parsed = fm(content); 29 | parsed.content = marked(parsed.content); 30 | 31 | let destPath = path.resolve(target, parsed.data.slug + '.json'); 32 | const written = await fs.writeFile(destPath, JSON.stringify(parsed)); 33 | 34 | finalBlob.push(parsed.data); 35 | 36 | if (i === (files.length - 1)) { 37 | resolve(); 38 | } 39 | }); 40 | }); 41 | 42 | loop.then(() => { resolve() }); 43 | }); 44 | }, 45 | async writeBundle() { 46 | return new Promise(async (resolve, reject) => { 47 | finalBlob.sort((a, b) => a.date < b.date ? 1 : -1); 48 | const blobPath = path.resolve(target, '__blog-blob.json'); 49 | const written = await fs.writeFile(blobPath, JSON.stringify(finalBlob)); 50 | resolve(); 51 | }); 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scant", 3 | "version": "0.0.4", 4 | "description": "A static site generator for Svelte.", 5 | "bin": { 6 | "scant": "bin/index.js" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/voldemortensen/scant.git" 11 | }, 12 | "keywords": [ 13 | "svelte", 14 | "static", 15 | "site", 16 | "static", 17 | "generator" 18 | ], 19 | "author": "voldemortensen", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/voldemortensen/scant/issues" 23 | }, 24 | "homepage": "https://github.com/voldemortensen/scant#readme", 25 | "dependencies": { 26 | "del": "^4.1.1", 27 | "fs-extra": "^7.0.1", 28 | "gray-matter": "^4.0.2", 29 | "marked": "^0.6.2", 30 | "rollup": "^1.11.3", 31 | "rollup-plugin-clean": "^1.0.0", 32 | "rollup-plugin-clear": "^2.0.7", 33 | "rollup-plugin-commonjs": "^9.3.4", 34 | "rollup-plugin-copy": "^2.0.1", 35 | "rollup-plugin-livereload": "^1.0.0", 36 | "rollup-plugin-node-resolve": "^4.2.4", 37 | "rollup-plugin-svelte": "^5.0.3", 38 | "rollup-plugin-terser": "^4.0.4", 39 | "svelte": "^3.3.0", 40 | "yargs": "^13.2.2" 41 | } 42 | } 43 | --------------------------------------------------------------------------------