diff --git a/site/package.json b/site/package.json index 2e633b774c..b9390f3c39 100644 --- a/site/package.json +++ b/site/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "sapper dev", "sapper": "sapper build --legacy", - "update": "sh scripts/update_template.sh && node scripts/get-contributors.js", + "update": "node scripts/update_template.js && node scripts/get-contributors.js", "start": "node __sapper__/build", "cy:run": "cypress run", "cy:open": "cypress open", @@ -29,6 +29,7 @@ "passport-github": "^1.1.0", "prismjs": "^1.15.0", "session-file-store": "^1.2.0", + "shelljs": "^0.8.3", "sirv": "^0.2.0", "yootils": "0.0.14" }, diff --git a/site/scripts/update_template.js b/site/scripts/update_template.js new file mode 100644 index 0000000000..23e2333bab --- /dev/null +++ b/site/scripts/update_template.js @@ -0,0 +1,26 @@ +const sh = require('shelljs'); +const fs = require('fs') + +sh.cd(__dirname+'/../') + +// fetch svelte app +sh.rm('-rf','scripts/svelte-app') +sh.exec('npx degit sveltejs/template scripts/svelte-app') + +// update repl-viewer.css based on template +sh.cp('scripts/svelte-app/public/global.css', 'static/repl-viewer.css') + +// remove src (will be recreated client-side) and node_modules +sh.rm('-rf', 'scripts/svelte-app/src') +sh.rm('-rf', 'scripts/svelte-app/node_modules') + +// build svelte-app.json +const appPath = 'scripts/svelte-app' +let files = [] + +for (const path of sh.find(appPath).filter(p => fs.lstatSync(p).isFile()) ) { + files.push({ path: path.slice(appPath.length + 1), data: fs.readFileSync(path).toString() }); +} + +fs.writeFileSync('static/svelte-app.json', JSON.stringify(files)); +