mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 11:15:14 +00:00
update Rollup, remove some superfluous deps
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import minify_html from './utils/minify_html';
|
||||
import { create_compilers, create_main_manifests, create_manifest_data, create_serviceworker_manifest } from '../core';
|
||||
import { copy_shimport } from './utils/copy_shimport';
|
||||
@@ -10,6 +8,7 @@ import { CompileResult } from '../core/create_compilers/interfaces';
|
||||
import { noop } from './utils/noop';
|
||||
import validate_bundler from './utils/validate_bundler';
|
||||
import { copy_runtime } from './utils/copy_runtime';
|
||||
import { rimraf, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
cwd?: string;
|
||||
@@ -48,12 +47,12 @@ export async function build({
|
||||
throw new Error(`Legacy builds are not supported for projects using webpack`);
|
||||
}
|
||||
|
||||
rimraf.sync(path.join(output, '**/*'));
|
||||
mkdirp.sync(output);
|
||||
rimraf(output);
|
||||
mkdirp(output);
|
||||
copy_runtime(output);
|
||||
|
||||
rimraf.sync(path.join(dest, '**/*'));
|
||||
mkdirp.sync(`${dest}/client`);
|
||||
rimraf(dest);
|
||||
mkdirp(`${dest}/client`);
|
||||
copy_shimport(dest);
|
||||
|
||||
// minify src/template.html
|
||||
|
||||
@@ -3,8 +3,6 @@ import * as fs from 'fs';
|
||||
import * as http from 'http';
|
||||
import * as child_process from 'child_process';
|
||||
import * as ports from 'port-authority';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import { EventEmitter } from 'events';
|
||||
import { create_manifest_data, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core';
|
||||
import { Compiler, Compilers } from '../core/create_compilers';
|
||||
@@ -16,6 +14,7 @@ import { ManifestData, FatalEvent, ErrorEvent, ReadyEvent, InvalidEvent } from '
|
||||
import read_template from '../core/read_template';
|
||||
import { noop } from './utils/noop';
|
||||
import { copy_runtime } from './utils/copy_runtime';
|
||||
import { rimraf, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
cwd?: string,
|
||||
@@ -146,12 +145,12 @@ class Watcher extends EventEmitter {
|
||||
|
||||
const { cwd, src, dest, routes, output, static: static_files } = this.dirs;
|
||||
|
||||
rimraf.sync(path.join(output, '**/*'));
|
||||
mkdirp.sync(output);
|
||||
rimraf(output);
|
||||
mkdirp(output);
|
||||
copy_runtime(output);
|
||||
|
||||
rimraf.sync(dest);
|
||||
mkdirp.sync(`${dest}/client`);
|
||||
rimraf(dest);
|
||||
mkdirp(`${dest}/client`);
|
||||
if (this.bundler === 'rollup') copy_shimport(dest);
|
||||
|
||||
if (!this.dev_port) this.dev_port = await ports.find(10000);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as child_process from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as sander from 'sander';
|
||||
import * as url from 'url';
|
||||
import fetch from 'node-fetch';
|
||||
import * as yootils from 'yootils';
|
||||
@@ -9,6 +9,7 @@ import clean_html from './utils/clean_html';
|
||||
import minify_html from './utils/minify_html';
|
||||
import Deferred from './utils/Deferred';
|
||||
import { noop } from './utils/noop';
|
||||
import { rimraf, copy, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
build_dir?: string,
|
||||
@@ -47,18 +48,12 @@ async function _export({
|
||||
export_dir = path.resolve(cwd, export_dir, basepath);
|
||||
|
||||
// Prep output directory
|
||||
sander.rimrafSync(export_dir);
|
||||
rimraf(export_dir);
|
||||
|
||||
sander.copydirSync(static_files).to(export_dir);
|
||||
sander.copydirSync(build_dir, 'client').to(export_dir, 'client');
|
||||
|
||||
if (sander.existsSync(build_dir, 'service-worker.js')) {
|
||||
sander.copyFileSync(build_dir, 'service-worker.js').to(export_dir, 'service-worker.js');
|
||||
}
|
||||
|
||||
if (sander.existsSync(build_dir, 'service-worker.js.map')) {
|
||||
sander.copyFileSync(build_dir, 'service-worker.js.map').to(export_dir, 'service-worker.js.map');
|
||||
}
|
||||
copy(static_files, export_dir);
|
||||
copy(path.join(build_dir, 'client'), path.join(export_dir, 'client'));
|
||||
copy(path.join(build_dir, 'service-worker.js'), path.join(export_dir, 'service-worker.js'));
|
||||
copy(path.join(build_dir, 'service-worker.js.map'), path.join(export_dir, 'service-worker.js.map'));
|
||||
|
||||
const port = await ports.find(3000);
|
||||
|
||||
@@ -85,8 +80,8 @@ async function _export({
|
||||
const seen = new Set();
|
||||
const saved = new Set();
|
||||
|
||||
function save(path: string, status: number, type: string, body: string) {
|
||||
const { pathname } = resolve(origin, path);
|
||||
function save(url: string, status: number, type: string, body: string) {
|
||||
const { pathname } = resolve(origin, url);
|
||||
let file = decodeURIComponent(pathname.slice(1));
|
||||
|
||||
if (saved.has(file)) return;
|
||||
@@ -107,7 +102,9 @@ async function _export({
|
||||
status
|
||||
});
|
||||
|
||||
sander.writeFileSync(export_dir, file, body);
|
||||
const export_file = path.join(export_dir, file);
|
||||
mkdirp(path.dirname(export_file));
|
||||
fs.writeFileSync(export_file, body);
|
||||
}
|
||||
|
||||
proc.on('message', message => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import { mkdirp } from './fs_utils';
|
||||
|
||||
const runtime = [
|
||||
'app.mjs',
|
||||
@@ -16,7 +16,7 @@ const runtime = [
|
||||
|
||||
export function copy_runtime(output: string) {
|
||||
runtime.forEach(({ file, source }) => {
|
||||
mkdirp.sync(path.dirname(`${output}/${file}`));
|
||||
mkdirp(path.dirname(`${output}/${file}`));
|
||||
fs.writeFileSync(`${output}/${file}`, source);
|
||||
});
|
||||
}
|
||||
46
src/api/utils/fs_utils.ts
Normal file
46
src/api/utils/fs_utils.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function mkdirp(dir: string) {
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) return;
|
||||
|
||||
mkdirp(parent);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
export function rimraf(thing: string) {
|
||||
if (!fs.existsSync(thing)) return;
|
||||
|
||||
const stats = fs.statSync(thing);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(thing).forEach(file => {
|
||||
rimraf(path.join(thing, file));
|
||||
});
|
||||
|
||||
fs.rmdirSync(thing);
|
||||
} else {
|
||||
fs.unlinkSync(thing);
|
||||
}
|
||||
}
|
||||
|
||||
export function copy(from: string, to: string) {
|
||||
if (!fs.existsSync(from)) return;
|
||||
|
||||
const stats = fs.statSync(from);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(from).forEach(file => {
|
||||
copy(path.join(from, file), path.join(to, file));
|
||||
});
|
||||
} else {
|
||||
mkdirp(path.dirname(to));
|
||||
fs.writeFileSync(to, fs.readFileSync(from));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user