1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-01-17 20:38:15 +01:00

fix release process

This commit is contained in:
Kushagra Gour 2018-06-16 19:18:24 +05:30
parent febf821f87
commit bbd1a95f35
5 changed files with 226 additions and 128 deletions

View File

@ -2,9 +2,13 @@
const fs = require('fs');
const gulp = require('gulp');
const runSequence = require('run-sequence');
const useref = require('gulp-useref');
const cleanCSS = require('gulp-clean-css');
const rename = require("gulp-rename");
const babelMinify = require('babel-minify');
const child_process = require('child_process');
const merge = require('merge-stream');
function minifyJs(fileName) {
const content = fs.readFileSync(fileName, 'utf8');
@ -14,47 +18,65 @@ function minifyJs(fileName) {
`[${fileName}]: ${content.length}kb -> ${minifiedContent.length}kb`
);
}
gulp.task('copyFiles', [], function() {
gulp
gulp.task('runWebpack', function () {
return child_process.execSync('yarn run build');
});
gulp.task('copyFiles', function () {
return merge(
gulp
.src('src/lib/codemirror/theme/*')
.pipe(gulp.dest('app/lib/codemirror/theme'));
gulp
.pipe(gulp.dest('app/lib/codemirror/theme')),
gulp
.src('src/lib/codemirror/mode/**/*')
.pipe(gulp.dest('app/lib/codemirror/mode'));
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers'));
gulp.src('src/partials/*').pipe(gulp.dest('app/partials'));
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib'));
gulp.src('src/preview.html').pipe(gulp.dest('app'));
gulp.src('src/detached-window.js').pipe(gulp.dest('app'));
gulp.src('src/icon-48.png').pipe(gulp.dest('app'));
gulp.src('src/icon-128.png').pipe(gulp.dest('app'));
gulp.src('src/patreon.png').pipe(gulp.dest('app'));
gulp
.pipe(gulp.dest('app/lib/codemirror/mode')),
gulp.src('src/lib/transpilers/*').pipe(gulp.dest('app/lib/transpilers')),
gulp.src('src/lib/screenlog.js').pipe(gulp.dest('app/lib')),
gulp.src('src/preview.html').pipe(gulp.dest('app')),
gulp.src('src/detached-window.js').pipe(gulp.dest('app')),
gulp.src('src/icon-48.png').pipe(gulp.dest('app')),
gulp.src('src/icon-128.png').pipe(gulp.dest('app')),
gulp.src('src/patreon.png').pipe(gulp.dest('app')),
gulp.src('build/bundle.*.js').pipe(rename("script.js")).pipe(gulp.dest('app')),
gulp.src('build/vendor.*.js').pipe(rename("vendor.js")).pipe(gulp.dest('app')),
gulp.src('src/lib/codemirror/lib/codemirror.css').pipe(gulp.dest('build/lib/codemirror/lib')),
gulp.src('src/lib/codemirror/addon/hint/show-hint.css').pipe(gulp.dest('build/lib/codemirror/addon/hint')),
gulp.src('src/lib/codemirror/addon/fold/foldgutter.css').pipe(gulp.dest('build/lib/codemirror/addon/fold')),
gulp.src('src/lib/codemirror/addon/dialog/dialog.css').pipe(gulp.dest('build/lib/codemirror/addon/dialog')),
gulp.src('src/lib/hint.min.css').pipe(gulp.dest('build/lib')),
gulp.src('src/lib/inlet.css').pipe(gulp.dest('build/lib')),
gulp.src('src/style.css').pipe(gulp.dest('build')),
gulp
.src([
'src/FiraCode.ttf',
'src/FixedSys.ttf',
'src/Inconsolata.ttf',
'src/Monoid.ttf'
])
.pipe(gulp.dest('app'));
.pipe(gulp.dest('app'))
);
});
gulp.task('useRef', ['copyFiles'], function() {
gulp.task('useRef', function () {
return gulp
.src('src/index.html')
.src('build/index.html')
.pipe(useref())
.pipe(gulp.dest('app'));
});
gulp.task('minify', ['useRef'], function() {
minifyJs('app/script.js');
minifyJs('app/vendor.js');
gulp.task('minify', function () {
// minifyJs('app/script.js');
// minifyJs('app/vendor.js');
minifyJs('app/lib/screenlog.js');
gulp
.src('app/*.css')
.pipe(
cleanCSS({ debug: true }, details => {
cleanCSS({
debug: true
}, details => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
})
@ -62,13 +84,18 @@ gulp.task('minify', ['useRef'], function() {
.pipe(gulp.dest('app'));
});
gulp.task('generate-service-worker', ['minify'], function(callback) {
gulp.task('fixIndex', function () {
var contents = fs.readFileSync('build/index.html', 'utf8');
contents = contents.replace(/\<\!\-\- SCRIPT-TAGS \-\-\>[\S\s]*?\<\!\-\- END-SCRIPT-TAGS \-\-\>/, '<script defer src="vendor.js"></script><script defer src="script.js"></script>');
fs.writeFileSync('build/index.html', contents, 'utf8');
});
gulp.task('generate-service-worker', function (callback) {
var swPrecache = require('sw-precache');
var rootDir = 'app';
swPrecache.write(
`${rootDir}/service-worker.js`,
{
`${rootDir}/service-worker.js`, {
staticFileGlobs: [
rootDir + '/**/*.{js,html,css,png,jpg,gif,svg,eot,ttf,woff}'
],
@ -81,4 +108,28 @@ gulp.task('generate-service-worker', ['minify'], function(callback) {
);
});
gulp.task('default', ['generate-service-worker']);
gulp.task('cleanup', function () {
return child_process.execSync('rm -rf build');
});
gulp.task('release', function (callback) {
runSequence(
'runWebpack',
'copyFiles',
'fixIndex',
'useRef',
'minify',
'generate-service-worker',
'cleanup',
function (error) {
if (error) {
console.log(error.message);
} else {
console.log('RELEASE FINISHED SUCCESSFULLY');
}
callback(error);
});
});
// gulp.task('default', ['generate-service-worker']);

View File

@ -9,7 +9,6 @@
"dev": "preact watch --template src/index.html --https --no-prerender",
"lint": "eslint src",
"test": "jest ./tests"
},
"eslintConfig": {
"extends": "eslint-config-synacor"
@ -18,21 +17,24 @@
"build/*"
],
"devDependencies": {
"babel-eslint": "^7.2.3",
"babel-minify": "^0.2.0",
"eslint": "^4.9.0",
"eslint-config-prettier": "^2.3.0",
"eslint-config-synacor": "^2.0.2",
"gulp": "^3.9.1",
"gulp-clean-css": "^3.9.2",
"gulp-rename": "^1.3.0",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.3",
"identity-obj-proxy": "^3.0.0",
"if-env": "^1.0.0",
"jest": "^21.2.1",
"merge-stream": "^1.0.1",
"preact-cli": "^2.1.0",
"preact-render-spy": "^1.2.1",
"babel-eslint": "^7.2.3",
"babel-minify": "^0.2.0",
"eslint-config-prettier": "^2.3.0",
"gulp": "^3.9.1",
"gulp-clean-css": "^3.9.2",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.3",
"prettier": "^1.10.2",
"run-sequence": "^2.2.1",
"sw-precache": "^5.2.0"
},
"dependencies": {
@ -78,7 +80,12 @@
"type": "git",
"url": "git+https://github.com/chinchang/web-maker.git"
},
"keywords": ["frontend", "playground", "web", "editor"],
"keywords": [
"frontend",
"playground",
"web",
"editor"
],
"author": "Kushagra Gour",
"license": "MIT",
"bugs": {

View File

@ -28,39 +28,36 @@ export default function (config, env, helpers) {
})
);
config.plugins.push(new CopyWebpackPlugin([{
context: `${__dirname}/src/assets`,
from: `*.*`
}, {
from: `${__dirname}/src/lib`,
to: 'lib/'
},
{
from: `${__dirname}/src/detached-window.js`
},
{
from: `${__dirname}/src/*.ttf`
},
{
from: `${__dirname}/src/patreon.png`
},
{
from: `${__dirname}/src/preview.html`
},
{
from: `${__dirname}/src/style.css`
}
]));
// config.plugins.push(new CopyWebpackPlugin([{
// context: `${__dirname}/src/assets`,
// from: `*.*`
// }, {
// from: `${__dirname}/src/lib`,
// to: 'lib/'
// },
// {
// from: `${__dirname}/src/detached-window.js`
// },
// {
// from: `${__dirname}/src/*.ttf`
// },
// {
// from: `${__dirname}/src/patreon.png`
// },
// {
// from: `${__dirname}/src/preview.html`
// },
// {
// from: `${__dirname}/src/style.css`
// }
// ]));
const {
plugin
} = helpers.getPluginsByName(config, 'SWPrecacheWebpackPlugin')[0];
plugin.options.maximumFileSizeToCacheInBytes = 2900000;
const swPlugin = helpers.getPluginsByName(config, 'SWPrecacheWebpackPlugin')[0];
config.plugins.splice(swPlugin.index, 1)
// plugin.options.maximumFileSizeToCacheInBytes = 2900000;
const {
index
} = helpers.getPluginsByName(config, 'UglifyJsPlugin')[0]
config.plugins.splice(index, 1)
const uglifyPlugin = helpers.getPluginsByName(config, 'UglifyJsPlugin')[0]
config.plugins.splice(uglifyPlugin.index, 1)
}
}

View File

@ -12,79 +12,63 @@
<% if (htmlWebpackPlugin.options.manifest.theme_color) { %>
<meta name="theme-color" content="<%= htmlWebpackPlugin.options.manifest.theme_color %>">
<% } %>
<% for (var chunk of webpack.chunks) { %>
<% if (chunk.names.length === 1 && chunk.names[0] === 'polyfills') continue; %>
<% for (var file of chunk.files) { %>
<% if (htmlWebpackPlugin.options.preload && file.match(/\.(js|css)$/)) { %>
<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>">
<% } else if (file.match(/manifest\.json$/)) { %>
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath + file %>">
<% } %>
<% } %>
<% } %>
<style>
/* Critically acclaimed CSS */
<style>
/* Critically acclaimed CSS */
.saved-items-pane {
position: fixed;
right: 0;
top: 0;
bottom: 0;
width: 450px;
transform: translateX(100%);
}
.saved-items-pane {
position: fixed;
right: 0;
top: 0;
bottom: 0;
width: 450px;
transform: translateX(100%);
}
.modal {
visibility: hidden;
}
.modal {
visibility: hidden;
}
</style>
</style>
<!-- build:css vendor.css -->
<link rel="stylesheet" href="lib/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="lib/codemirror/addon/hint/show-hint.css">
<link rel="stylesheet" href="lib/codemirror/addon/fold/foldgutter.css">
<link rel="stylesheet" href="lib/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="lib/hint.min.css">
<link rel="stylesheet" href="lib/inlet.css">
<!-- endbuild -->
<!-- build:css vendor.css -->
<link rel="stylesheet" href="lib/codemirror/lib/codemirror.css">
<link rel="stylesheet" href="lib/codemirror/addon/hint/show-hint.css">
<link rel="stylesheet" href="lib/codemirror/addon/fold/foldgutter.css">
<link rel="stylesheet" href="lib/codemirror/addon/dialog/dialog.css">
<link rel="stylesheet" href="lib/hint.min.css">
<link rel="stylesheet" href="lib/inlet.css">
<!-- endbuild -->
<link rel="stylesheet" id="editorThemeLinkTag" href="lib/codemirror/theme/monokai.css"></link>
<link rel="stylesheet" id="editorThemeLinkTag" href="lib/codemirror/theme/monokai.css"></link>
<!-- build:css style.css -->
<link rel="stylesheet" href="style.css">
<!-- endbuild -->
<!-- build:css style.css -->
<link rel="stylesheet" href="style.css">
<!-- endbuild -->
<style id="fontStyleTemplate" type="template">
@font-face { font-family: 'fontname'; font-style: normal; font-weight: 400; src: url(fontname.ttf) format('truetype'); unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD,
U+F000; } .CodeMirror pre { font-family: 'fontname', monospace; }
</style>
<style type="text/css" id="fontStyleTag">
@font-face {
font-family: 'FiraCode';
font-style: normal;
font-weight: 400;
src: url(FiraCode.ttf) format('truetype');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
<style id="fontStyleTemplate" type="template">
@font-face { font-family: 'fontname'; font-style: normal; font-weight: 400; src: url(fontname.ttf) format('truetype'); unicode-range:
U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF,
U+EFFD, U+F000; } .CodeMirror pre { font-family: 'fontname', monospace; }
</style>
<style type="text/css" id="fontStyleTag">
@font-face {
font-family: 'FiraCode';
font-style: normal;
font-weight: 400;
src: url(FiraCode.ttf) format('truetype');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
.CodeMirror pre {
font-family: 'FiraCode', monospace;
}
.CodeMirror pre {
font-family: 'FiraCode', monospace;
}
</style>
</style>
</head>
<body>
<!-- SCRIPT-TAGS -->
<%= htmlWebpackPlugin.options.ssr({
url: '/'
}) %>
@ -93,7 +77,7 @@
window.fetch || document.write('<script src="<%= htmlWebpackPlugin.files.chunks["polyfills"].entry %>"><\/script>')
</script>
<!-- END-SCRIPT-TAGS -->
</body>
</html>

View File

@ -477,6 +477,12 @@ ansi-colors@^1.0.1:
dependencies:
ansi-wrap "^0.1.0"
ansi-cyan@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-cyan/-/ansi-cyan-0.1.1.tgz#538ae528af8982f28ae30d86f2f17456d2609873"
dependencies:
ansi-wrap "0.1.0"
ansi-escapes@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30"
@ -491,6 +497,12 @@ ansi-html@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.7.tgz#813584021962a9e9e6fd039f940d12f56ca7859e"
ansi-red@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-red/-/ansi-red-0.1.1.tgz#8c638f9d1080800a353c9c28c8a81ca4705d946c"
dependencies:
ansi-wrap "0.1.0"
ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@ -559,6 +571,13 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"
arr-diff@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-1.1.0.tgz#687c32758163588fef7de7b36fabe495eb1a399a"
dependencies:
arr-flatten "^1.0.1"
array-slice "^0.2.3"
arr-diff@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
@ -573,6 +592,10 @@ arr-flatten@^1.0.1, arr-flatten@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1"
arr-union@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-2.1.0.tgz#20f9eab5ec70f5c7d215b1077b1c39161d292c7d"
arr-union@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4"
@ -620,6 +643,10 @@ array-reduce@~0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/array-reduce/-/array-reduce-0.0.0.tgz#173899d3ffd1c7d9383e4479525dbe278cab5f2b"
array-slice@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-0.2.3.tgz#dd3cfb80ed7973a75117cdac69b0b99ec86186f5"
array-slice@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/array-slice/-/array-slice-1.1.0.tgz#e368ea15f89bc7069f7ffb89aec3a6c7d4ac22d4"
@ -3518,6 +3545,12 @@ express@^4.16.2:
utils-merge "1.0.1"
vary "~1.1.2"
extend-shallow@^1.1.2:
version "1.1.4"
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-1.1.4.tgz#19d6bf94dfc09d76ba711f39b872d21ff4dd9071"
dependencies:
kind-of "^1.1.0"
extend-shallow@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/extend-shallow/-/extend-shallow-2.0.1.tgz#51af7d614ad9a9f610ea1bafbb989d6b1c56890f"
@ -3579,7 +3612,7 @@ extsprintf@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
fancy-log@^1.1.0:
fancy-log@^1.1.0, fancy-log@^1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/fancy-log/-/fancy-log-1.3.2.tgz#f41125e3d84f2e7d89a43d06d958c8f78be16be1"
dependencies:
@ -4311,6 +4344,10 @@ gulp-rename@^1.2.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-1.2.3.tgz#37b75298e9d3e6c0fe9ac4eac13ce3be5434646b"
gulp-rename@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-1.3.0.tgz#2e789d8f563ab0c924eeb62967576f37ff4cb826"
gulp-sourcemaps@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/gulp-sourcemaps/-/gulp-sourcemaps-1.6.0.tgz#b86ff349d801ceb56e1d9e7dc7bbcb4b7dee600c"
@ -5624,6 +5661,10 @@ killable@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz#da8b84bd47de5395878f95d64d02f2449fe05e6b"
kind-of@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-1.1.0.tgz#140a3d2d41a36d2efcfa9377b62c24f8495a5c44"
kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
version "3.2.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
@ -6056,7 +6097,7 @@ merge-descriptors@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
merge-stream@^1.0.0:
merge-stream@^1.0.0, merge-stream@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-1.0.1.tgz#4041202d508a342ba00174008df0c251b8c135e1"
dependencies:
@ -6944,6 +6985,16 @@ plugin-error@1.0.1, plugin-error@^1.0.1:
arr-union "^3.1.0"
extend-shallow "^3.0.2"
plugin-error@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/plugin-error/-/plugin-error-0.1.2.tgz#3b9bb3335ccf00f425e07437e19276967da47ace"
dependencies:
ansi-cyan "^0.1.1"
ansi-red "^0.1.1"
arr-diff "^1.0.1"
arr-union "^2.0.1"
extend-shallow "^1.1.2"
pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
@ -7983,6 +8034,14 @@ run-queue@^1.0.0, run-queue@^1.0.3:
dependencies:
aproba "^1.1.1"
run-sequence@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/run-sequence/-/run-sequence-2.2.1.tgz#1ce643da36fd8c7ea7e1a9329da33fc2b8898495"
dependencies:
chalk "^1.1.3"
fancy-log "^1.3.2"
plugin-error "^0.1.2"
rx-lite-aggregates@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz#753b87a89a11c95467c4ac1626c4efc4e05c67be"