Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 8f064fe

Browse files
committed
update folder structure (#432)
1 parent f29e7ef commit 8f064fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+680
-27
lines changed

src/api/build.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ async function execute(emitter: EventEmitter, opts: Opts, dirs: Dirs) {
3939
mkdirp.sync(`${dirs.dest}/client`);
4040
copy_shimport(dirs.dest);
4141

42-
// minify app/template.html
42+
// minify src/template.html
4343
// TODO compile this to a function? could be quicker than str.replace(...).replace(...).replace(...)
44-
const template = fs.readFileSync(`${dirs.app}/template.html`, 'utf-8');
44+
const template = fs.readFileSync(`${dirs.src}/template.html`, 'utf-8');
4545

4646
// remove this in a future version
4747
if (template.indexOf('%sapper.base%') === -1) {
@@ -54,7 +54,7 @@ async function execute(emitter: EventEmitter, opts: Opts, dirs: Dirs) {
5454

5555
const manifest_data = create_manifest_data();
5656

57-
// create app/manifest/client.js and app/manifest/server.js
57+
// create src/manifest/client.js and src/manifest/server.js
5858
create_main_manifests({ bundler: opts.bundler, manifest_data });
5959

6060
const { client, server, serviceworker } = create_compilers(opts.bundler, dirs);
@@ -79,7 +79,7 @@ async function execute(emitter: EventEmitter, opts: Opts, dirs: Dirs) {
7979
// TODO duration/warnings
8080
result: client_result
8181
});
82-
82+
8383
client_result.to_json(manifest_data, dirs);
8484
build_info.legacy_assets = client_result.assets;
8585
delete process.env.SAPPER_LEGACY_BUILD;

src/api/dev.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function dev(opts) {
2323
class Watcher extends EventEmitter {
2424
bundler: string;
2525
dirs: {
26-
app: string;
26+
src: string;
2727
dest: string;
2828
routes: string;
2929
rollup: string;
@@ -53,7 +53,7 @@ class Watcher extends EventEmitter {
5353
}
5454

5555
constructor({
56-
app = locations.app(),
56+
src = locations.src(),
5757
dest = locations.dest(),
5858
routes = locations.routes(),
5959
'dev-port': dev_port,
@@ -65,7 +65,7 @@ class Watcher extends EventEmitter {
6565
rollup = 'rollup',
6666
port = +process.env.PORT
6767
}: {
68-
app: string,
68+
src: string,
6969
dest: string,
7070
routes: string,
7171
'dev-port': number,
@@ -80,7 +80,7 @@ class Watcher extends EventEmitter {
8080
super();
8181

8282
this.bundler = validate_bundler(bundler);
83-
this.dirs = { app, dest, routes, webpack, rollup };
83+
this.dirs = { src, dest, routes, webpack, rollup };
8484
this.port = port;
8585
this.closed = false;
8686

@@ -100,7 +100,7 @@ class Watcher extends EventEmitter {
100100
};
101101

102102
// remove this in a future version
103-
const template = fs.readFileSync(path.join(app, 'template.html'), 'utf-8');
103+
const template = fs.readFileSync(path.join(src, 'template.html'), 'utf-8');
104104
if (template.indexOf('%sapper.base%') === -1) {
105105
const error = new Error(`As of Sapper v0.10, your template.html file must include %sapper.base% in the <head>`);
106106
error.code = `missing-sapper-base`;
@@ -175,7 +175,7 @@ class Watcher extends EventEmitter {
175175
}
176176
),
177177

178-
fs.watch(`${locations.app()}/template.html`, () => {
178+
fs.watch(`${locations.src()}/template.html`, () => {
179179
this.dev_server.send({
180180
action: 'reload'
181181
});

src/api/export.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as events from './interfaces';
1313
type Opts = {
1414
build: string,
1515
dest: string,
16+
static: string,
1617
basepath?: string,
1718
timeout: number | false
1819
};
@@ -46,7 +47,7 @@ async function execute(emitter: EventEmitter, opts: Opts) {
4647
// Prep output directory
4748
sander.rimrafSync(export_dir);
4849

49-
sander.copydirSync('assets').to(export_dir);
50+
sander.copydirSync(opts.static).to(export_dir);
5051
sander.copydirSync(opts.build, 'client').to(export_dir, 'client');
5152

5253
if (sander.existsSync(opts.build, 'service-worker.js')) {

src/cli/build.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function build(opts: { bundler?: string, legacy?: boolean }) {
1818
bundler
1919
}, {
2020
dest: locations.dest(),
21-
app: locations.app(),
21+
src: locations.src(),
2222
routes: locations.routes(),
2323
webpack: 'webpack',
2424
rollup: 'rollup'

src/cli/export.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function exporter(export_dir: string, {
1515
try {
1616
const emitter = _exporter({
1717
build: locations.dest(),
18+
static: locations.static(),
1819
dest: export_dir,
1920
basepath,
2021
timeout

src/config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export const dev = () => process.env.NODE_ENV !== 'production';
44

55
export const locations = {
66
base: () => path.resolve(process.env.SAPPER_BASE || ''),
7-
app: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_APP || 'app'),
8-
routes: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_ROUTES || 'routes'),
7+
src: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_SRC || 'src'),
8+
static: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_STATIC || 'static'),
9+
routes: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_ROUTES || 'src/routes'),
910
dest: () => path.resolve(process.env.SAPPER_BASE || '', process.env.SAPPER_DEST || `.sapper/${dev() ? 'dev' : 'prod'}`)
1011
};

src/core/create_manifests.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function create_main_manifests({ bundler, manifest_data, dev_port }: {
1010
manifest_data: ManifestData;
1111
dev_port?: number;
1212
}) {
13-
const manifest_dir = path.join(locations.app(), 'manifest');
13+
const manifest_dir = path.join(locations.src(), 'manifest');
1414
if (!fs.existsSync(manifest_dir)) fs.mkdirSync(manifest_dir);
1515

1616
const path_to_routes = path.relative(manifest_dir, locations.routes());
@@ -30,20 +30,21 @@ export function create_serviceworker_manifest({ manifest_data, client_files }: {
3030
manifest_data: ManifestData;
3131
client_files: string[];
3232
}) {
33-
const assets = glob('**', { cwd: 'assets', filesOnly: true });
33+
const files = glob('**', { cwd: locations.static(), filesOnly: true });
3434

3535
let code = `
3636
// This file is generated by Sapper — do not edit it!
3737
export const timestamp = ${Date.now()};
3838
39-
export const assets = [\n\t${assets.map((x: string) => `"${x}"`).join(',\n\t')}\n];
39+
export const files = [\n\t${files.map((x: string) => `"${x}"`).join(',\n\t')}\n];
40+
export { files as assets }; // legacy
4041
4142
export const shell = [\n\t${client_files.map((x: string) => `"${x}"`).join(',\n\t')}\n];
4243
4344
export const routes = [\n\t${manifest_data.pages.map((r: Page) => `{ pattern: ${r.pattern} }`).join(',\n\t')}\n];
4445
`.replace(/^\t\t/gm, '').trim();
4546

46-
write_if_changed(`${locations.app()}/manifest/service-worker.js`, code);
47+
write_if_changed(`${locations.src()}/manifest/service-worker.js`, code);
4748
}
4849

4950
function generate_client(

src/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export type ServerRoute = {
4343

4444
export type Dirs = {
4545
dest: string,
46-
app: string,
46+
src: string,
4747
routes: string,
4848
webpack: string,
4949
rollup: string

src/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function get_page_handler(
288288
: (assets => () => assets)(JSON.parse(fs.readFileSync(path.join(output, 'build.json'), 'utf-8')));
289289

290290
const template = dev()
291-
? () => fs.readFileSync(`${locations.app()}/template.html`, 'utf-8')
291+
? () => fs.readFileSync(`${locations.src()}/template.html`, 'utf-8')
292292
: (str => () => str)(fs.readFileSync(`${locations.dest()}/template.html`, 'utf-8'));
293293

294294
const { server_routes, pages } = manifest;

src/rollup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55

66
client: {
77
input: () => {
8-
return `${locations.app()}/client.js`
8+
return `${locations.src()}/client.js`
99
},
1010

1111
output: () => {
@@ -24,7 +24,7 @@ export default {
2424

2525
server: {
2626
input: () => {
27-
return `${locations.app()}/server.js`
27+
return `${locations.src()}/server.js`
2828
},
2929

3030
output: () => {
@@ -38,7 +38,7 @@ export default {
3838

3939
serviceworker: {
4040
input: () => {
41-
return `${locations.app()}/service-worker.js`;
41+
return `${locations.src()}/service-worker.js`;
4242
},
4343

4444
output: () => {

src/webpack.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
client: {
77
entry: () => {
88
return {
9-
main: `${locations.app()}/client`
9+
main: `${locations.src()}/client`
1010
};
1111
},
1212

@@ -23,7 +23,7 @@ export default {
2323
server: {
2424
entry: () => {
2525
return {
26-
server: `${locations.app()}/server`
26+
server: `${locations.src()}/server`
2727
};
2828
},
2929

@@ -40,7 +40,7 @@ export default {
4040
serviceworker: {
4141
entry: () => {
4242
return {
43-
'service-worker': `${locations.app()}/service-worker`
43+
'service-worker': `${locations.src()}/service-worker`
4444
};
4545
},
4646

File renamed without changes.

0 commit comments

Comments
 (0)