From 7c6436a99c8d8d273774c2188af6d709da99fda1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 13 Feb 2018 18:46:53 -0500 Subject: [PATCH] implement sapper upgrade --- src/cli/index.ts | 9 ++++++-- src/cli/upgrade.ts | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/cli/upgrade.ts diff --git a/src/cli/index.ts b/src/cli/index.ts index 09ef7b1..93a5290 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,8 +1,9 @@ import mri from 'mri'; import chalk from 'chalk'; import help from './help.md'; -import build from './build.js'; -import exporter from './export.js'; +import build from './build'; +import exporter from './export'; +import upgrade from './upgrade'; import { dest, entry, src } from '../config'; import * as pkg from '../../package.json'; @@ -46,4 +47,8 @@ if (cmd === 'build') { .catch(err => { console.error(err ? err.details || err.stack || err.message || err : 'Unknown error'); }); +} else if (cmd === 'upgrade') { + upgrade(); +} else { + console.log(`unrecognized command ${cmd} — try \`sapper --help\` for more information`); } diff --git a/src/cli/upgrade.ts b/src/cli/upgrade.ts new file mode 100644 index 0000000..ed8a83e --- /dev/null +++ b/src/cli/upgrade.ts @@ -0,0 +1,53 @@ +import * as fs from 'fs'; +import chalk from 'chalk'; + +export default async function upgrade() { + const upgraded = [ + + ].filter(Boolean); + await upgrade_sapper_main() + if (upgraded.length === 0) { + console.log(`No changes!`); + } +} + +async function upgrade_sapper_main() { + const _2xx = read('templates/2xx.html'); + const _4xx = read('templates/4xx.html'); + const _5xx = read('templates/5xx.html'); + + const pattern = /