Skip to content

Commit d1b94f3

Browse files
committed
merge master -> blog-post-css
2 parents 9c32668 + feea18b commit d1b94f3

File tree

124 files changed

+261
-295
lines changed

Some content is hidden

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

124 files changed

+261
-295
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ universal/components/guide-summary.json
1717
universal/routes/Repl/examples.js
1818
server/components
1919
server/routes
20-
server/manifests
20+
manifests
2121
credentials.json
22-
assets
22+
assets
23+
build
24+
server.js

client/rollup.config.codemirror.js

-19
This file was deleted.

client/rollup.config.js

-47
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package.json

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"version": "1.0.0",
44
"description": "Docs and examples for Svelte",
55
"scripts": {
6-
"start": "node server/dist",
7-
"prebuild": "rm -rf client/dist && mkdir -p client/dist && rm -rf service-worker/dist && mkdir -p service-worker/dist",
8-
"dev": "rollup -c -w & node scripts/prep && npm start",
6+
"start": "node server",
7+
"prebuild": "rm -rf build && mkdir -p build",
8+
"dev": "node scripts/prep && rollup -c -w & npm start",
99
"build": "node scripts/prep && rollup -c",
1010
"update_template": "sh ./scripts/update_template.sh",
1111
"zip": "sh ./scripts/zip.sh",
@@ -48,7 +48,7 @@
4848
"rollup-plugin-hash": "^1.2.0",
4949
"rollup-plugin-json": "^2.1.1",
5050
"rollup-plugin-node-resolve": "^3.0.0",
51-
"rollup-plugin-replace": "^1.1.1",
51+
"rollup-plugin-replace": "^2.0.0",
5252
"rollup-plugin-svelte": "^3.0.0",
5353
"rollup-plugin-uglify": "^2.0.1",
5454
"uglify-js": "^3.0.0"
@@ -71,17 +71,12 @@
7171
"now": {
7272
"alias": "svelte.technology",
7373
"files": [
74-
"blog",
75-
"client",
76-
"examples",
77-
"guide",
74+
"content",
75+
"src",
7876
"public",
7977
"rollup.config.js",
8078
"scripts",
81-
"server",
82-
"service-worker",
83-
"templates",
84-
"universal"
79+
"manifests"
8580
]
8681
}
8782
}

public/blog.json

-1
This file was deleted.

rollup.config.js

+161-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,163 @@
1-
import client from './client/rollup.config.js';
2-
import codemirror from './client/rollup.config.codemirror.js';
3-
import serviceWorker from './service-worker/rollup.config.js';
4-
import server from './server/rollup.config.js';
1+
import fs from 'fs';
2+
import glob from 'glob';
3+
import hasha from 'hasha';
4+
import hash from 'rollup-plugin-hash';
5+
import replace from 'rollup-plugin-replace';
6+
import svelte from 'rollup-plugin-svelte';
7+
import resolve from 'rollup-plugin-node-resolve';
8+
import commonjs from 'rollup-plugin-commonjs';
9+
import json from 'rollup-plugin-json';
10+
import uglify from 'rollup-plugin-uglify';
11+
import buble from 'rollup-plugin-buble';
12+
import pkg from './package.json';
13+
14+
const dev = !!process.env.ROLLUP_WATCH;
15+
16+
function readJson(file) {
17+
return JSON.parse(fs.readFileSync(file, 'utf-8'));
18+
}
19+
20+
const hashed = {
21+
blog: readJson('manifests/content.json')['blog.json'],
22+
guide: readJson('manifests/content.json')['guide.json']
23+
};
524

625
export default [
7-
client,
8-
codemirror,
9-
serviceWorker,
10-
server
11-
];
26+
/* bundle.js */
27+
{
28+
input: 'src/client/main.js',
29+
output: {
30+
file: 'build/bundle.js',
31+
format: 'iife',
32+
},
33+
plugins: [
34+
replace({
35+
'blog.[hash].json': () => hashed.blog,
36+
'guide.[hash].json': () => hashed.guide
37+
}),
38+
json(),
39+
resolve(),
40+
commonjs(),
41+
svelte({
42+
cascade: false,
43+
css (css) {
44+
if (dev) {
45+
css.write(`build/main.css`);
46+
hashed.css = 'main.css';
47+
} else {
48+
const hash = hasha(css.code, { algorithm: 'md5' });
49+
hashed.css = `main.${hash}.css`;
50+
51+
css.write(`build/${hashed.css}`);
52+
fs.writeFileSync(`manifests/css.json`, JSON.stringify({ 'main.css': hashed.css }));
53+
}
54+
}
55+
}),
56+
buble(),
57+
!dev && hash({
58+
dest: 'build/bundle.[hash].js',
59+
manifest: 'manifests/bundle.json',
60+
manifestKey: 'bundle.js'
61+
}),
62+
!dev && uglify()
63+
],
64+
sourcemap: true
65+
},
66+
67+
/* codemirror.js */
68+
{
69+
input: 'src/client/codemirror.js',
70+
output: {
71+
file: 'public/codemirror.js',
72+
format: 'amd',
73+
},
74+
plugins: [
75+
resolve(),
76+
commonjs(),
77+
!dev && uglify()
78+
],
79+
sourcemap: true
80+
},
81+
82+
/* sw.js */
83+
{
84+
input: 'src/service-worker/main.js',
85+
output: {
86+
file: 'build/sw.js',
87+
format: 'iife',
88+
},
89+
plugins: [
90+
replace({
91+
__CACHEVERSION__: () => '' + Date.now(),
92+
__MANIFEST__: generateCacheManifest,
93+
delimiters: ['', '']
94+
}),
95+
buble(),
96+
!dev && hash({
97+
dest: 'build/sw.[hash].js',
98+
manifest: 'manifests/sw.json',
99+
manifestKey: 'sw.js'
100+
}),
101+
!dev && uglify()
102+
],
103+
sourcemap: true
104+
},
105+
106+
/* server.js */
107+
{
108+
input: 'src/server/index.js',
109+
output: {
110+
file: 'server.js',
111+
format: 'cjs',
112+
},
113+
external: Object.keys(pkg.dependencies).concat([
114+
'path', 'fs'
115+
]),
116+
plugins: [
117+
replace({
118+
__dev__: !!dev,
119+
'blog.[hash].json': hashed.blog,
120+
'guide.[hash].json': hashed.guide
121+
}),
122+
json(),
123+
svelte({
124+
generate: 'ssr',
125+
cascade: false,
126+
css: false
127+
})
128+
]
129+
}
130+
];
131+
132+
function generateCacheManifest() {
133+
// https://github.com/phamann/rollup-plugin-hash/issues/14
134+
hashed.bundle = readJson('manifests/bundle.json')['bundle.js'].replace('build/', '');
135+
136+
const manifest = [].concat(
137+
// routes
138+
'/',
139+
'/guide',
140+
'/repl',
141+
'/blog',
142+
143+
// js
144+
`/${hashed.bundle}`,
145+
'/curl.js',
146+
'/codemirror.js',
147+
'/magic-string.umd.js',
148+
149+
// css
150+
`/${hashed.css}`,
151+
'/codemirror.css',
152+
153+
// fonts
154+
glob.sync('fonts/**/*.woff?(2)', { cwd: 'public' }).map(x => `/${x}`),
155+
156+
// content
157+
`/${hashed.blog}`, // don't need to include individual posts
158+
`/${hashed.guide}`,
159+
glob.sync('examples/**/*.json', { cwd: 'public' }).map(x => `/${x}`)
160+
);
161+
162+
return JSON.stringify(manifest);
163+
}

scripts/prep/build-blog.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const fs = require( 'fs' );
22
const path = require( 'path' );
33
const hljs = require( 'highlight.js' );
4-
const { mkdirp } = require( './utils.js' );
4+
const hasha = require( 'hasha' );
5+
const { updateManifest, mkdirp } = require( './utils.js' );
56
const marked = require( 'marked' );
67

78
const root = path.resolve( __dirname, '../..' );
89

9-
const posts = fs.readdirSync( `${root}/blog` )
10+
const posts = fs.readdirSync( `${root}/content/blog` )
1011
.map( file => {
1112
if ( file[0] === '.' || path.extname( file ) !== '.md' ) return;
1213

13-
const markdown = fs.readFileSync( `${root}/blog/${file}`, 'utf-8' );
14+
const markdown = fs.readFileSync( `${root}/content/blog/${file}`, 'utf-8' );
1415

1516
const match = /---\n([\s\S]+?)\n---/.exec( markdown );
1617
const frontMatter = match[1];
@@ -48,9 +49,13 @@ const preview = posts.map( post => {
4849
return { slug: post.slug, metadata: post.metadata };
4950
});
5051

51-
fs.writeFileSync( `${root}/public/blog.json`, JSON.stringify( preview ) );
52+
const previewJson = JSON.stringify( preview );
53+
const hash = hasha(previewJson, { algorithm: 'md5' });
54+
fs.writeFileSync( `${root}/build/blog.${hash}.json`, previewJson );
55+
updateManifest({ 'blog.json': `blog.${hash}.json` });
5256

53-
mkdirp( `${root}/public/blog` );
57+
// TODO hash individual posts?
58+
mkdirp(`${root}/public/blog`);
5459
posts.forEach( post => {
5560
fs.writeFileSync( `${root}/public/blog/${post.slug}.json`, JSON.stringify( post ) );
5661
});

scripts/prep/build-examples.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { mkdirp } = require( './utils.js' );
55

66
const root = path.resolve( __dirname, '../..' );
77

8-
const manifest = require( `${root}/examples/manifest.json` );
8+
const manifest = require( `${root}/content/examples/manifest.json` );
99

1010
mkdirp( `${root}/public/examples` );
1111

@@ -15,7 +15,7 @@ manifest.forEach( group => {
1515
const groupSummary = [];
1616

1717
group.examples.forEach( id => {
18-
const example = require( `${root}/examples/${id}/example.json` );
18+
const example = require( `${root}/content/examples/${id}/example.json` );
1919

2020
if ( example.redirect ) {
2121
redirects[ id ] = example.redirect;
@@ -24,7 +24,7 @@ manifest.forEach( group => {
2424

2525
example.data = example.data || {};
2626

27-
example.components = glob.sync( '**/*.+(html|js)', { cwd: `${root}/examples/${id}` })
27+
example.components = glob.sync( '**/*.+(html|js)', { cwd: `${root}/content/examples/${id}` })
2828
.map( file => {
2929
const ext = path.extname(file);
3030
const type = ext.slice(1);
@@ -33,7 +33,7 @@ manifest.forEach( group => {
3333
name: file.replace( ext, '' ),
3434
type,
3535
entry: file === 'App.html' ? true : undefined,
36-
source: fs.readFileSync( `${root}/examples/${id}/${file}`, 'utf-8' )
36+
source: fs.readFileSync( `${root}/content/examples/${id}/${file}`, 'utf-8' )
3737
};
3838
})
3939
.sort( ( a, b ) => {
@@ -61,7 +61,7 @@ manifest.forEach( group => {
6161
});
6262
});
6363

64-
fs.writeFileSync( `${root}/universal/routes/Repl/examples.js`, `
64+
fs.writeFileSync( `${root}/src/universal/routes/Repl/examples.js`, `
6565
// this file is auto-generated, don't edit it
6666
export const exampleGroups = ${JSON.stringify( summary )};
6767
export const redirects = ${JSON.stringify( redirects )};

0 commit comments

Comments
 (0)