add SAPPER_BASE and SAPPER_APP environment variables

This commit is contained in:
Rich Harris
2018-03-11 13:29:39 -04:00
parent 819ec0b776
commit be63ea7c96
7 changed files with 22 additions and 17 deletions

View File

@@ -4,10 +4,10 @@ import * as clorox from 'clorox';
import mkdirp from 'mkdirp';
import rimraf from 'rimraf';
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core'
import { dest } from '../config';
import { locations } from '../config';
export async function build() {
const output = dest();
const output = locations.dest();
mkdirp.sync(output);
rimraf.sync(path.join(output, '**/*'));

View File

@@ -9,7 +9,7 @@ import rimraf from 'rimraf';
import format_messages from 'webpack-format-messages';
import prettyMs from 'pretty-ms';
import * as ports from 'port-authority';
import { dest } from '../config';
import { locations } from '../config';
import { create_compilers, create_main_manifests, create_routes, create_serviceworker_manifest } from '../core';
type Deferred = {
@@ -84,7 +84,7 @@ export async function dev(opts: { port: number }) {
port = await ports.find(3000);
}
const dir = dest();
const dir = locations.dest();
rimraf.sync(dir);
mkdirp.sync(dir);

View File

@@ -5,10 +5,10 @@ import cheerio from 'cheerio';
import URL from 'url-parse';
import fetch from 'node-fetch';
import * as ports from 'port-authority';
import { dest } from '../config';
import { locations } from '../config';
export async function exporter(export_dir: string) {
const build_dir = dest();
const build_dir = locations.dest();
// Prep output directory
sander.rimrafSync(export_dir);

View File

@@ -1,5 +1,10 @@
import * as path from 'path';
export const dev = () => process.env.NODE_ENV !== 'production';
export const src = () => path.resolve(process.env.SAPPER_ROUTES || 'routes');
export const dest = () => path.resolve(process.env.SAPPER_DEST || '.sapper');
export const locations = {
base: () => path.resolve(process.env.SAPPER_BASE || ''),
app: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_APP || 'app'),
routes: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_ROUTES || 'routes'),
dest: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_DEST || '.sapper')
};

View File

@@ -1,9 +1,9 @@
import * as path from 'path';
import glob from 'glob';
import { src } from '../config';
import { locations } from '../config';
import { Route } from '../interfaces';
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: src(), nodir: true }) }) {
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), nodir: true }) }) {
const routes: Route[] = files
.map((file: string) => {
if (/(^|\/|\\)_/.test(file)) return;

View File

@@ -7,7 +7,7 @@ import devalue from 'devalue';
import { lookup } from './middleware/mime';
import { minify_html } from './middleware/minify_html';
import { create_routes, create_compilers } from './core';
import { dest, dev } from './config';
import { locations, dev } from './config';
import { Route, Template } from './interfaces';
import sourceMapSupport from 'source-map-support';
@@ -41,7 +41,7 @@ interface Req extends ClientRequest {
export default function middleware({ routes }: {
routes: RouteObject[]
}) {
const output = dest();
const output = locations.dest();
const client_info = JSON.parse(fs.readFileSync(path.join(output, 'client_info.json'), 'utf-8'));
@@ -81,7 +81,7 @@ function serve({ prefix, pathname, cache_control }: {
? (req: Req) => req.pathname === pathname
: (req: Req) => req.pathname.startsWith(prefix);
const output = dest();
const output = locations.dest();
const cache: Map<string, Buffer> = new Map();

View File

@@ -1,4 +1,4 @@
import { dest, dev } from './config';
import { locations, dev } from './config';
export default {
dev: dev(),
@@ -12,7 +12,7 @@ export default {
output: () => {
return {
path: `${dest()}/client`,
path: `${locations.dest()}/client`,
filename: '[hash]/[name].js',
chunkFilename: '[hash]/[name].[id].js',
publicPath: '/client/'
@@ -29,7 +29,7 @@ export default {
output: () => {
return {
path: dest(),
path: locations.dest(),
filename: '[name].js',
chunkFilename: '[hash]/[name].[id].js',
libraryTarget: 'commonjs2'
@@ -46,7 +46,7 @@ export default {
output: () => {
return {
path: dest(),
path: locations.dest(),
filename: '[name].js',
chunkFilename: '[name].[id].[hash].js'
}