From 8b341d5fc7f78df3e08a3340ea93c25324dbb552 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 22 Feb 2017 02:27:19 +0900 Subject: [PATCH 1/2] wip --- gulpfile.ts | 17 +++++------------ src/config.ts | 12 +++--------- webpack.config.ts | 14 +++----------- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 30812bead..863ca4477 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -33,15 +33,6 @@ if (isDebug) { console.log(chalk.yellow.bold('!!!注意!!! 開発モードが有効です。(成果物の圧縮などはスキップされます)')); } -if (!fs.existsSync('./.config/default.yml')) { - console.log('npm run configを実行して設定ファイルを作成してください'); - process.exit(); -} - -(global as any).MISSKEY_CONFIG_PATH = '.config/default.yml'; -import { Config } from './src/config'; -const config = eval(require('typescript').transpile(require('fs').readFileSync('./src/config.ts').toString()))() as Config; - const tsProject = ts.createProject('tsconfig.json'); gulp.task('build', [ @@ -102,7 +93,9 @@ gulp.task('build:about:docs', () => { path: page, license: licenseHtml, thirdpartyLicenses: thirdpartyLicensesHtml - }, config) + }, { + themeColor: '#f76d6c' + }) })) .pipe(gulp.dest('./built/web/about/pages/' + Path.parse(page).dir)); }); @@ -154,7 +147,7 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { // Get commit info const commit = await prominence(git).getLastCommit(); - let stream = webpack(require('./webpack.config.js')(config, commit, env), require('webpack')); + let stream = webpack(require('./webpack.config.js')(commit, env), require('webpack')); // TODO: remove this block if (isProduction) { @@ -220,7 +213,7 @@ gulp.task('build:client:pug', [ gulp.src('./src/web/app/*/view.pug') .pipe(pug({ locals: { - themeColor: config.themeColor + themeColor: '#f76d6c' } })) .pipe(gulp.dest('./built/web/app/')) diff --git a/src/config.ts b/src/config.ts index 64a6b7c9b..d2916c39c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,11 +14,9 @@ const dir = `${__dirname}/../.config`; /** * Path of configuration file */ -export const path = (global as any).MISSKEY_CONFIG_PATH - ? (global as any).MISSKEY_CONFIG_PATH - : process.env.NODE_ENV == 'test' - ? `${dir}/test.yml` - : `${dir}/default.yml`; +export const path = process.env.NODE_ENV == 'test' + ? `${dir}/test.yml` + : `${dir}/default.yml`; /** * ユーザーが設定する必要のある情報 @@ -71,8 +69,6 @@ interface Source { * Misskeyが自動的に(ユーザーが設定した情報から推論して)設定する情報 */ interface Mixin { - themeColor: string; - themeColorForeground: string; host: string; scheme: string; secondary_host: string; @@ -98,8 +94,6 @@ export default function load() { config.url = normalizeUrl(config.url); config.secondary_url = normalizeUrl(config.secondary_url); - mixin.themeColor = '#f76d6c'; - mixin.themeColorForeground = '#fff'; mixin.host = config.url.substr(config.url.indexOf('://') + 3); mixin.scheme = config.url.substr(0, config.url.indexOf('://')); mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3); diff --git a/webpack.config.ts b/webpack.config.ts index 66d4eb2e1..00fd3f00a 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -1,7 +1,7 @@ import * as webpack from 'webpack'; const StringReplacePlugin = require('string-replace-webpack-plugin'); -module.exports = (config, commit, env) => { +module.exports = (commit, env) => { const isProduction = env === 'production'; const isDebug = !isProduction; @@ -21,7 +21,7 @@ module.exports = (config, commit, env) => { loader: StringReplacePlugin.replace({ replacements: [ { pattern: /\$theme\-color\-foreground/g, replacement: () => '#fff' }, - { pattern: /\$theme\-color/g, replacement: () => config.themeColor }, + { pattern: /\$theme\-color/g, replacement: () => '#f76d6c' }, ] }) }, @@ -62,15 +62,7 @@ module.exports = (config, commit, env) => { new webpack.DefinePlugin({ VERSION: JSON.stringify(commit ? commit.hash : null), CONFIG: { - themeColor: JSON.stringify(config.themeColor), - apiUrl: JSON.stringify(config.api_url), - aboutUrl: JSON.stringify(config.about_url), - devUrl: JSON.stringify(config.dev_url), - host: JSON.stringify(config.host), - url: JSON.stringify(config.url), - recaptcha: { - siteKey: JSON.stringify(config.recaptcha.siteKey), - } + themeColor: JSON.stringify('#f76d6c') } }), new StringReplacePlugin(), From 9820a691c154e7233b8327cedc7faa1f6c4e55e8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 22 Feb 2017 04:19:53 +0900 Subject: [PATCH 2/2] well done --- README.md | 4 ++-- src/web/app/boot.js | 4 +++- src/web/app/common/scripts/api.js | 2 ++ src/web/app/common/scripts/config.js | 18 +++++++++++++++++ .../app/common/scripts/messaging-stream.js | 1 + src/web/app/common/scripts/signout.js | 2 ++ src/web/app/common/scripts/stream.js | 1 + src/web/app/common/scripts/text-compiler.js | 1 + src/web/app/common/tags/signup.tag | 20 ++++++++++++++----- src/web/app/desktop/scripts/update-avatar.js | 1 + src/web/app/desktop/scripts/update-banner.js | 1 + src/web/server.ts | 11 ++++++++++ 12 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 src/web/app/common/scripts/config.js diff --git a/README.md b/README.md index 52666390e..32b86f8dc 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,7 @@ and more! You can touch with your own eyes at https://misskey.xyz/. 2. `git clone git://github.com/syuilo/misskey.git` 3. `cd misskey` 4. `npm install` -5. `npm run config` -6. `npm run build` +5. `npm run build` GLHF! @@ -92,6 +91,7 @@ If you want to run misskey in production mode, add `--env NODE_ENV=production` l Note that `$(pwd)` is the working directory. ## Launch +(初回起動時はまず `npm run config` してください) `sudo npm start` ## Debugging :bug: diff --git a/src/web/app/boot.js b/src/web/app/boot.js index 5fc752462..d39e46861 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -17,11 +17,13 @@ require('./common/tags'); "use strict"; +const CONFIG = require('./common/scripts/config'); + document.domain = CONFIG.host; // Set global configration riot.mixin({ - CONFIG: CONFIG + CONFIG }); // ↓ iOS待ちPolyfill (SEE: http://caniuse.com/#feat=fetch) diff --git a/src/web/app/common/scripts/api.js b/src/web/app/common/scripts/api.js index b549fe47b..be72f863d 100644 --- a/src/web/app/common/scripts/api.js +++ b/src/web/app/common/scripts/api.js @@ -2,6 +2,8 @@ * API Request */ +const CONFIG = require('./config'); + let spinner = null; let pending = 0; diff --git a/src/web/app/common/scripts/config.js b/src/web/app/common/scripts/config.js new file mode 100644 index 000000000..512340241 --- /dev/null +++ b/src/web/app/common/scripts/config.js @@ -0,0 +1,18 @@ +const url = new URL(location.href); + +const isRoot = url.host.split('.')[0] == 'misskey'; + +const host = isRoot ? url.host : url.host.substring(url.host.indexOf('.') + 1, url.host.length); +const scheme = url.protocol; +const apiUrl = `${scheme}//api.${host}`; +const devUrl = `${scheme}//dev.${host}`; +const aboutUrl = `${scheme}//about.${host}`; + +module.exports = { + host, + scheme, + apiUrl, + devUrl, + aboutUrl, + themeColor: '#f76d6c' +}; diff --git a/src/web/app/common/scripts/messaging-stream.js b/src/web/app/common/scripts/messaging-stream.js index 2c00c2402..0c8ce3c9d 100644 --- a/src/web/app/common/scripts/messaging-stream.js +++ b/src/web/app/common/scripts/messaging-stream.js @@ -1,5 +1,6 @@ const ReconnectingWebSocket = require('reconnecting-websocket'); const riot = require('riot'); +const CONFIG = require('./config'); class Connection { constructor(me, otherparty) { diff --git a/src/web/app/common/scripts/signout.js b/src/web/app/common/scripts/signout.js index cd752423d..7242ebc5b 100644 --- a/src/web/app/common/scripts/signout.js +++ b/src/web/app/common/scripts/signout.js @@ -1,3 +1,5 @@ +const CONFIG = require('./config'); + module.exports = () => { localStorage.removeItem('me'); document.cookie = `i=; domain=.${CONFIG.host}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.js index 34ddc8447..fd7bac7fa 100644 --- a/src/web/app/common/scripts/stream.js +++ b/src/web/app/common/scripts/stream.js @@ -1,5 +1,6 @@ const ReconnectingWebSocket = require('reconnecting-websocket'); const riot = require('riot'); +const CONFIG = require('./config'); module.exports = me => { let state = 'initializing'; diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js index 62e70463a..c9eb73e87 100644 --- a/src/web/app/common/scripts/text-compiler.js +++ b/src/web/app/common/scripts/text-compiler.js @@ -1,5 +1,6 @@ const riot = require('riot'); const nyaize = require('nyaize').default; +const CONFIG = require('./config'); const escape = function(text) { return text diff --git a/src/web/app/common/tags/signup.tag b/src/web/app/common/tags/signup.tag index f0358e232..a70399a87 100644 --- a/src/web/app/common/tags/signup.tag +++ b/src/web/app/common/tags/signup.tag @@ -30,7 +30,7 @@