nanka iroiro

This commit is contained in:
syuilo 2017-03-18 00:02:41 +09:00
parent 6927ffa979
commit 5ad77e8a3a
10 changed files with 155 additions and 93 deletions

View File

@ -19,13 +19,16 @@ import * as chalk from 'chalk';
import imagemin = require('gulp-imagemin'); import imagemin = require('gulp-imagemin');
import * as rename from 'gulp-rename'; import * as rename from 'gulp-rename';
import * as mocha from 'gulp-mocha'; import * as mocha from 'gulp-mocha';
import * as replace from 'gulp-replace';
import getVersion from './src/version';
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const isProduction = env === 'production'; const isProduction = env === 'production';
const isDebug = !isProduction; const isDebug = !isProduction;
if (isDebug) { if (isDebug) {
console.log(chalk.yellow.bold('WARNING NODE_ENV is not "production". (built script compessing will not be performed.)')); console.warn(chalk.yellow.bold('WARNING! NODE_ENV is not "production".'));
console.warn(chalk.yellow.bold(' built script compessing will not be performed.'));
} }
const constants = require('./src/const.json'); const constants = require('./src/const.json');
@ -126,15 +129,21 @@ gulp.task('build:client', [
'copy:client' 'copy:client'
]); ]);
gulp.task('build:client:scripts', () => gulp.task('build:client:scripts', done => {
es.merge( getVersion.then(version => {
webpack(require('./webpack.config'), require('webpack')) require('./webpack.config').then(webpackOptions => {
.pipe(gulp.dest('./built/web/resources/')) as any, es.merge(
gulp.src('./src/web/app/client/script.js') webpack(webpackOptions, require('webpack'))
//.pipe(isProduction ? uglify() : gutil.noop()) .pipe(gulp.dest('./built/web/resources/')) as any,
.pipe(gulp.dest('./built/web/resources/client/')) as any gulp.src('./src/web/app/client/script.js')
) .pipe(replace('VERSION', JSON.stringify(version)))
); //.pipe(isProduction ? uglify() : gutil.noop())
.pipe(gulp.dest('./built/web/resources/client/')) as any
);
done();
});
});
});
gulp.task('build:client:styles', () => gulp.task('build:client:styles', () =>
gulp.src('./src/web/app/init.css') gulp.src('./src/web/app/init.css')
@ -163,12 +172,16 @@ gulp.task('build:client:pug', [
'copy:client', 'copy:client',
'build:client:scripts', 'build:client:scripts',
'build:client:styles' 'build:client:styles'
], () => ], done => {
getVersion.then(version => {
gulp.src('./src/web/app/*/view.pug') gulp.src('./src/web/app/*/view.pug')
.pipe(pug({ .pipe(pug({
locals: { locals: {
version: version,
themeColor: constants.themeColor themeColor: constants.themeColor
} }
})) }))
.pipe(gulp.dest('./built/web/app/')) .pipe(gulp.dest('./built/web/app/'));
); done();
});
});

View File

@ -36,13 +36,14 @@
"@types/express": "4.0.35", "@types/express": "4.0.35",
"@types/glob": "5.0.30", "@types/glob": "5.0.30",
"@types/gm": "1.17.30", "@types/gm": "1.17.30",
"@types/gulp-tslint": "3.6.31",
"@types/gulp-rename": "0.0.32",
"@types/gulp-mocha": "0.0.30",
"@types/gulp": "4.0.2", "@types/gulp": "4.0.2",
"@types/gulp-mocha": "0.0.30",
"@types/gulp-rename": "0.0.32",
"@types/gulp-replace": "0.0.30",
"@types/gulp-tslint": "3.6.31",
"@types/gulp-typescript": "0.0.32", "@types/gulp-typescript": "0.0.32",
"@types/gulp-util": "3.0.31",
"@types/gulp-uglify": "0.0.30", "@types/gulp-uglify": "0.0.30",
"@types/gulp-util": "3.0.31",
"@types/inquirer": "0.0.32", "@types/inquirer": "0.0.32",
"@types/is-root": "1.0.0", "@types/is-root": "1.0.0",
"@types/is-url": "1.2.28", "@types/is-url": "1.2.28",
@ -65,8 +66,8 @@
"@types/websocket": "0.0.33", "@types/websocket": "0.0.33",
"autwh": "0.0.1", "autwh": "0.0.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"cafy": "2.3.0",
"body-parser": "1.17.1", "body-parser": "1.17.1",
"cafy": "2.3.0",
"chai": "3.5.0", "chai": "3.5.0",
"chai-http": "3.0.0", "chai-http": "3.0.0",
"chalk": "1.1.3", "chalk": "1.1.3",
@ -95,6 +96,7 @@
"gulp-mocha": "4.1.0", "gulp-mocha": "4.1.0",
"gulp-pug": "3.3.0", "gulp-pug": "3.3.0",
"gulp-rename": "1.2.2", "gulp-rename": "1.2.2",
"gulp-replace": "0.5.4",
"gulp-tslint": "7.1.0", "gulp-tslint": "7.1.0",
"gulp-typescript": "3.1.6", "gulp-typescript": "3.1.6",
"gulp-uglify": "2.1.0", "gulp-uglify": "2.1.0",

View File

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import prominence from 'prominence'; import prominence from 'prominence';
import git from 'git-last-commit'; import getVersion from '../../version';
import config from '../../conf'; import config from '../../conf';
/** /**
@ -39,11 +39,11 @@ import config from '../../conf';
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
const commit = await prominence(git).getLastCommit(); const version = await getVersion.then();
res({ res({
maintainer: config.maintainer, maintainer: config.maintainer,
commit: commit.shortHash, version: version,
secure: config.https.enable secure: config.https.enable
}); });
}); });

12
src/version.ts Normal file
View File

@ -0,0 +1,12 @@
import prominence = require('prominence');
import git = require('git-last-commit');
const getVersion = new Promise<string>(async resolve => {
const commit = await prominence(git).getLastCommit();
const version = commit.shortHash;
resolve(version);
});
export default getVersion;

View File

@ -1,6 +1,5 @@
extends ../base extends ../base
block head block head
meta(name='viewport', content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no') meta(name='viewport' content='width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no')
link(rel='stylesheet', href='/resources/auth/style.css') script(src=`/resources/auth/script.${version}.js` async defer)
script(src='/resources/auth/script.js', async, defer)

View File

@ -2,17 +2,17 @@ doctype html
!= '\r\n<!-- Thank you for using Misskey! @syuilo -->\r\n' != '\r\n<!-- Thank you for using Misskey! @syuilo -->\r\n'
html(lang='ja', dir='ltr') html(lang='ja' dir='ltr')
head head
meta(charset='utf-8') meta(charset='utf-8')
meta(name='application-name', content='Misskey') meta(name='application-name' content='Misskey')
meta(name='theme-color', content= themeColor) meta(name='theme-color' content=themeColor)
meta(name='referrer', content='origin') meta(name='referrer' content='origin')
title Misskey title Misskey
style style
include ./../../../built/web/resources/init.css include ./../../../built/web/resources/init.css
script(src='https://use.fontawesome.com/22aba0df4f.js', async) script(src='https://use.fontawesome.com/22aba0df4f.js' async)
block head block head
body body

View File

@ -49,6 +49,26 @@ try {
Storage.prototype.setItem = () => { }; // noop Storage.prototype.setItem = () => { }; // noop
} }
// クライアントを更新すべきならする
if (localStorage.getItem('should-refresh') == 'true') {
localStorage.removeItem('should-refresh');
location.reload(true);
}
// 更新チェック
setTimeout(() => {
fetch(CONFIG.apiUrl + '/meta', {
method: 'POST'
}).then(res => {
res.json().then(meta => {
if (meta.version != VERSION) {
localStorage.setItem('should-refresh', 'true');
alert('Misskeyの新しいバージョンがあります。ページを再度読み込みすると更新が適用されます。');
}
});
});
}, 3000);
// ユーザーをフェッチしてコールバックする // ユーザーをフェッチしてコールバックする
module.exports = callback => { module.exports = callback => {
// Get cached account data // Get cached account data

View File

@ -1,18 +1,29 @@
/**
* MISSKEY ENTRY POINT
*/
(() => { (() => {
const head = document.getElementsByTagName('head')[0]; const head = document.getElementsByTagName('head')[0];
// Detect user agent
const ua = navigator.userAgent.toLowerCase(); const ua = navigator.userAgent.toLowerCase();
const isMobile = /mobile|iphone|ipad|android/.test(ua); const isMobile = /mobile|iphone|ipad|android/.test(ua);
isMobile ? mountMobile() : mountDesktop(); isMobile ? mountMobile() : mountDesktop();
/**
* Mount the desktop app
*/
function mountDesktop() { function mountDesktop() {
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('src', '/resources/desktop/script.js'); script.setAttribute('src', `/resources/desktop/script.${VERSION}.js`);
script.setAttribute('async', 'true'); script.setAttribute('async', 'true');
script.setAttribute('defer', 'true'); script.setAttribute('defer', 'true');
head.appendChild(script); head.appendChild(script);
} }
/**
* Mount the mobile app
*/
function mountMobile() { function mountMobile() {
const meta = document.createElement('meta'); const meta = document.createElement('meta');
meta.setAttribute('name', 'viewport'); meta.setAttribute('name', 'viewport');
@ -20,7 +31,7 @@
head.appendChild(meta); head.appendChild(meta);
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('src', '/resources/mobile/script.js'); script.setAttribute('src', `/resources/mobile/script.${VERSION}.js`);
script.setAttribute('async', 'true'); script.setAttribute('async', 'true');
script.setAttribute('defer', 'true'); script.setAttribute('defer', 'true');
head.appendChild(script); head.appendChild(script);

View File

@ -1,5 +1,4 @@
extends ../base extends ../base
block head block head
link(rel='stylesheet', href='/resources/dev/style.css') script(src=`/resources/dev/script.${version}.js` async defer)
script(src='/resources/dev/script.js', async, defer)

View File

@ -4,73 +4,79 @@
import * as webpack from 'webpack'; import * as webpack from 'webpack';
const StringReplacePlugin = require('string-replace-webpack-plugin'); const StringReplacePlugin = require('string-replace-webpack-plugin');
import getVersion from './src/version';
const constants = require('./src/const.json'); const constants = require('./src/const.json');
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const isProduction = env === 'production'; const isProduction = env === 'production';
const pack: webpack.Configuration = { module.exports = new Promise(async resolve => {
entry: { const version = await getVersion.then();
'desktop': './src/web/app/desktop/script.js',
'mobile': './src/web/app/mobile/script.js', const pack: webpack.Configuration = {
'dev': './src/web/app/dev/script.js', entry: {
'auth': './src/web/app/auth/script.js' 'desktop': './src/web/app/desktop/script.js',
}, 'mobile': './src/web/app/mobile/script.js',
module: { 'dev': './src/web/app/dev/script.js',
rules: [ 'auth': './src/web/app/auth/script.js'
{ },
enforce: 'pre', module: {
test: /\.tag$/, rules: [
exclude: /node_modules/, {
loader: StringReplacePlugin.replace({ enforce: 'pre',
replacements: [ test: /\.tag$/,
{ pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground }, exclude: /node_modules/,
{ pattern: /\$theme\-color/g, replacement: () => constants.themeColor }, loader: StringReplacePlugin.replace({
] replacements: [
}) { pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground },
}, { pattern: /\$theme\-color/g, replacement: () => constants.themeColor },
{ ]
test: /\.tag$/, })
exclude: /node_modules/, },
loader: 'riot-tag-loader', {
query: { test: /\.tag$/,
hot: false, exclude: /node_modules/,
style: 'stylus', loader: 'riot-tag-loader',
expr: false, query: {
compact: true, hot: false,
parserOptions: { style: 'stylus',
style: { expr: false,
compress: true compact: true,
parserOptions: {
style: {
compress: true
}
} }
} }
},
{
test: /\.styl$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'stylus-loader' }
]
} }
}, ]
{ },
test: /\.styl$/, plugins: [
exclude: /node_modules/, new webpack.DefinePlugin({
use: [ VERSION: JSON.stringify(version),
{ loader: 'style-loader' }, CONFIG: {
{ loader: 'css-loader' }, themeColor: JSON.stringify(constants.themeColor)
{ loader: 'stylus-loader' } }
] }),
} new StringReplacePlugin()
] ],
}, output: {
plugins: [ filename: `[name]/script.${version}.js`
new webpack.DefinePlugin({ }
CONFIG: { };
themeColor: JSON.stringify(constants.themeColor)
} if (isProduction) {
}), //pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
new StringReplacePlugin()
],
output: {
filename: '[name]/script.js'
} }
};
if (isProduction) { resolve(pack);
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin()); });
}
module.exports = pack;