mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-17 13:14:54 +00:00
use fs.existsSync
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
import sade from 'sade';
|
import sade from 'sade';
|
||||||
@@ -10,7 +11,6 @@ import exporter from './export';
|
|||||||
import dev from './dev';
|
import dev from './dev';
|
||||||
import upgrade from './upgrade';
|
import upgrade from './upgrade';
|
||||||
import * as ports from 'port-authority';
|
import * as ports from 'port-authority';
|
||||||
import { exists } from '../utils';
|
|
||||||
import * as pkg from '../../package.json';
|
import * as pkg from '../../package.json';
|
||||||
|
|
||||||
const prog = sade('sapper');
|
const prog = sade('sapper');
|
||||||
@@ -60,7 +60,7 @@ prog.command('start [dir]')
|
|||||||
const resolved = path.resolve(dir);
|
const resolved = path.resolve(dir);
|
||||||
const server = path.resolve(dir, 'server.js');
|
const server = path.resolve(dir, 'server.js');
|
||||||
|
|
||||||
if (!exists(server)) {
|
if (!fs.existsSync(server)) {
|
||||||
console.log(chalk.bold.red(`> ${dir}/server.js does not exist — type ${chalk.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`));
|
console.log(chalk.bold.red(`> ${dir}/server.js does not exist — type ${chalk.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import serialize from 'serialize-javascript';
|
|||||||
import escape_html from 'escape-html';
|
import escape_html from 'escape-html';
|
||||||
import { lookup } from './mime';
|
import { lookup } from './mime';
|
||||||
import { create_routes, templates, create_compilers } from 'sapper/core.js';
|
import { create_routes, templates, create_compilers } from 'sapper/core.js';
|
||||||
import { exists } from '../utils';
|
|
||||||
import { dest, dev } from '../config';
|
import { dest, dev } from '../config';
|
||||||
import { Route, Template } from '../interfaces';
|
import { Route, Template } from '../interfaces';
|
||||||
import sourceMapSupport from 'source-map-support';
|
import sourceMapSupport from 'source-map-support';
|
||||||
@@ -52,12 +51,12 @@ export default function middleware({ routes }: {
|
|||||||
next();
|
next();
|
||||||
},
|
},
|
||||||
|
|
||||||
exists(path.join(output, 'index.html')) && serve({
|
fs.existsSync(path.join(output, 'index.html')) && serve({
|
||||||
pathname: '/index.html',
|
pathname: '/index.html',
|
||||||
cache_control: 'max-age=600'
|
cache_control: 'max-age=600'
|
||||||
}),
|
}),
|
||||||
|
|
||||||
exists(path.join(output, 'service-worker.js')) && serve({
|
fs.existsSync(path.join(output, 'service-worker.js')) && serve({
|
||||||
pathname: '/service-worker.js',
|
pathname: '/service-worker.js',
|
||||||
cache_control: 'max-age=600'
|
cache_control: 'max-age=600'
|
||||||
}),
|
}),
|
||||||
|
|||||||
10
src/utils.ts
10
src/utils.ts
@@ -1,10 +0,0 @@
|
|||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
export function exists(file: string) {
|
|
||||||
try {
|
|
||||||
fs.statSync(file);
|
|
||||||
return true;
|
|
||||||
} catch (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user