parent
b1b02d0e32
commit
fab389e624
|
@ -5,6 +5,7 @@
|
||||||
import * as gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
import * as gutil from 'gulp-util';
|
import * as gutil from 'gulp-util';
|
||||||
import * as ts from 'gulp-typescript';
|
import * as ts from 'gulp-typescript';
|
||||||
|
const yaml = require('gulp-yaml');
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
import tslint from 'gulp-tslint';
|
import tslint from 'gulp-tslint';
|
||||||
const cssnano = require('gulp-cssnano');
|
const cssnano = require('gulp-cssnano');
|
||||||
|
@ -39,6 +40,7 @@ gulp.task('build', [
|
||||||
'build:ts',
|
'build:ts',
|
||||||
'build:copy',
|
'build:copy',
|
||||||
'build:client',
|
'build:client',
|
||||||
|
'locales',
|
||||||
'doc'
|
'doc'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -192,6 +194,12 @@ gulp.task('build:client:pug', [
|
||||||
.pipe(gulp.dest('./built/client/app/'))
|
.pipe(gulp.dest('./built/client/app/'))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
gulp.task('locales', () =>
|
||||||
|
gulp.src('./locales/*.yml')
|
||||||
|
.pipe(yaml({ schema: 'DEFAULT_SAFE_SCHEMA' }))
|
||||||
|
.pipe(gulp.dest('./built/client/assets/locales/'))
|
||||||
|
);
|
||||||
|
|
||||||
gulp.task('doc', () =>
|
gulp.task('doc', () =>
|
||||||
gulp.src('./src/docs/**/*.styl')
|
gulp.src('./src/docs/**/*.styl')
|
||||||
.pipe(stylus())
|
.pipe(stylus())
|
||||||
|
|
|
@ -129,6 +129,7 @@
|
||||||
"gulp-typescript": "4.0.2",
|
"gulp-typescript": "4.0.2",
|
||||||
"gulp-uglify": "3.0.1",
|
"gulp-uglify": "3.0.1",
|
||||||
"gulp-util": "3.0.8",
|
"gulp-util": "3.0.8",
|
||||||
|
"gulp-yaml": "2.0.2",
|
||||||
"hard-source-webpack-plugin": "0.12.0",
|
"hard-source-webpack-plugin": "0.12.0",
|
||||||
"html-minifier": "3.5.21",
|
"html-minifier": "3.5.21",
|
||||||
"http-signature": "1.2.0",
|
"http-signature": "1.2.0",
|
||||||
|
|
|
@ -3,15 +3,9 @@
|
||||||
* (ENTRY POINT)
|
* (ENTRY POINT)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* ドメインに基づいて適切なスクリプトを読み込みます。
|
|
||||||
* ユーザーの言語およびモバイル端末か否かも考慮します。
|
|
||||||
* webpackは介さないためrequireやimportは使えません。
|
|
||||||
*/
|
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(function() {
|
(async function() {
|
||||||
// キャッシュ削除要求があれば従う
|
// キャッシュ削除要求があれば従う
|
||||||
if (localStorage.getItem('shouldFlush') == 'true') {
|
if (localStorage.getItem('shouldFlush') == 'true') {
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -67,8 +61,18 @@
|
||||||
langs.includes(settings.device.lang)) {
|
langs.includes(settings.device.lang)) {
|
||||||
lang = settings.device.lang;
|
lang = settings.device.lang;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.lang = lang;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
let locale = localStorage.getItem('locale');
|
||||||
|
if (locale == null) {
|
||||||
|
const locale = await fetch(`/assets/locales/${lang}.json`)
|
||||||
|
.then(response => response.json());
|
||||||
|
|
||||||
|
localStorage.setItem('locale', JSON.stringify(locale));
|
||||||
|
}
|
||||||
|
|
||||||
// Detect the user agent
|
// Detect the 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);
|
||||||
|
@ -106,7 +110,7 @@
|
||||||
// Note: 'async' make it possible to load the script asyncly.
|
// Note: 'async' make it possible to load the script asyncly.
|
||||||
// 'defer' make it possible to run the script when the dom loaded.
|
// 'defer' make it possible to run the script when the dom loaded.
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.setAttribute('src', `/assets/${app}.${ver}.${lang}.js${salt}`);
|
script.setAttribute('src', `/assets/${app}.${ver}.js${salt}`);
|
||||||
script.setAttribute('async', 'true');
|
script.setAttribute('async', 'true');
|
||||||
script.setAttribute('defer', 'true');
|
script.setAttribute('defer', 'true');
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
declare const _LANG_: string;
|
declare const _LANGS_: string[];
|
||||||
declare const _LANGS_: string;
|
|
||||||
declare const _LOCALE_: { [key: string]: any };
|
|
||||||
declare const _THEME_COLOR_: string;
|
declare const _THEME_COLOR_: string;
|
||||||
declare const _COPYRIGHT_: string;
|
declare const _COPYRIGHT_: string;
|
||||||
declare const _VERSION_: string;
|
declare const _VERSION_: string;
|
||||||
|
@ -15,9 +13,9 @@ export const hostname = address.hostname;
|
||||||
export const url = address.origin;
|
export const url = address.origin;
|
||||||
export const apiUrl = url + '/api';
|
export const apiUrl = url + '/api';
|
||||||
export const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://') + '/streaming';
|
export const wsUrl = url.replace('http://', 'ws://').replace('https://', 'wss://') + '/streaming';
|
||||||
export const lang = _LANG_;
|
export const lang = window.lang;
|
||||||
export const langs = _LANGS_;
|
export const langs = _LANGS_;
|
||||||
export const locale = _LOCALE_;
|
export const locale = JSON.parse(localStorage.getItem('locale'));
|
||||||
export const themeColor = _THEME_COLOR_;
|
export const themeColor = _THEME_COLOR_;
|
||||||
export const copyright = _COPYRIGHT_;
|
export const copyright = _COPYRIGHT_;
|
||||||
export const version = _VERSION_;
|
export const version = _VERSION_;
|
||||||
|
|
|
@ -30,7 +30,7 @@ const postcss = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Object.keys(locales).map(lang => ({
|
module.exports = {
|
||||||
entry: {
|
entry: {
|
||||||
desktop: './src/client/app/desktop/script.ts',
|
desktop: './src/client/app/desktop/script.ts',
|
||||||
mobile: './src/client/app/mobile/script.ts',
|
mobile: './src/client/app/mobile/script.ts',
|
||||||
|
@ -116,9 +116,7 @@ module.exports = Object.keys(locales).map(lang => ({
|
||||||
_VERSION_: JSON.stringify(meta.version),
|
_VERSION_: JSON.stringify(meta.version),
|
||||||
_CLIENT_VERSION_: JSON.stringify(version),
|
_CLIENT_VERSION_: JSON.stringify(version),
|
||||||
_CODENAME_: JSON.stringify(codename),
|
_CODENAME_: JSON.stringify(codename),
|
||||||
_LANG_: JSON.stringify(lang),
|
|
||||||
_LANGS_: JSON.stringify(Object.keys(locales).map(l => [l, locales[l].meta.lang])),
|
_LANGS_: JSON.stringify(Object.keys(locales).map(l => [l, locales[l].meta.lang])),
|
||||||
_LOCALE_: JSON.stringify(locales[lang]),
|
|
||||||
_ENV_: JSON.stringify(process.env.NODE_ENV)
|
_ENV_: JSON.stringify(process.env.NODE_ENV)
|
||||||
}),
|
}),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
|
@ -134,7 +132,7 @@ module.exports = Object.keys(locales).map(lang => ({
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
path: __dirname + '/built/client/assets',
|
path: __dirname + '/built/client/assets',
|
||||||
filename: `[name].${version}.${lang}.js`,
|
filename: `[name].${version}.js`,
|
||||||
publicPath: `/assets/`
|
publicPath: `/assets/`
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -151,4 +149,4 @@ module.exports = Object.keys(locales).map(lang => ({
|
||||||
cache: true,
|
cache: true,
|
||||||
devtool: false, //'source-map',
|
devtool: false, //'source-map',
|
||||||
mode: isProduction ? 'production' : 'development'
|
mode: isProduction ? 'production' : 'development'
|
||||||
}));
|
};
|
||||||
|
|
Loading…
Reference in a new issue