Merge pull request #194 from syuilo/no-build-requires-config

No build requires config
This commit is contained in:
syuilo⭐️ 2017-02-22 04:20:44 +09:00 committed by GitHub
commit ea4179a408
15 changed files with 69 additions and 40 deletions

View File

@ -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` 2. `git clone git://github.com/syuilo/misskey.git`
3. `cd misskey` 3. `cd misskey`
4. `npm install` 4. `npm install`
5. `npm run config` 5. `npm run build`
6. `npm run build`
GLHF! 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. Note that `$(pwd)` is the working directory.
## Launch ## Launch
(初回起動時はまず `npm run config` してください)
`sudo npm start` `sudo npm start`
## Debugging :bug: ## Debugging :bug:

View File

@ -33,15 +33,6 @@ if (isDebug) {
console.log(chalk.yellow.bold('!!!注意!!! 開発モードが有効です。(成果物の圧縮などはスキップされます)')); 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'); const tsProject = ts.createProject('tsconfig.json');
gulp.task('build', [ gulp.task('build', [
@ -102,7 +93,9 @@ gulp.task('build:about:docs', () => {
path: page, path: page,
license: licenseHtml, license: licenseHtml,
thirdpartyLicenses: thirdpartyLicensesHtml thirdpartyLicenses: thirdpartyLicensesHtml
}, config) }, {
themeColor: '#f76d6c'
})
})) }))
.pipe(gulp.dest('./built/web/about/pages/' + Path.parse(page).dir)); .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 // Get commit info
const commit = await prominence(git).getLastCommit(); 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 // TODO: remove this block
if (isProduction) { if (isProduction) {
@ -216,7 +209,7 @@ gulp.task('build:client:pug', [
gulp.src('./src/web/app/*/view.pug') gulp.src('./src/web/app/*/view.pug')
.pipe(pug({ .pipe(pug({
locals: { locals: {
themeColor: config.themeColor themeColor: '#f76d6c'
} }
})) }))
.pipe(gulp.dest('./built/web/app/')) .pipe(gulp.dest('./built/web/app/'))

View File

@ -14,11 +14,9 @@ const dir = `${__dirname}/../.config`;
/** /**
* Path of configuration file * Path of configuration file
*/ */
export const path = (global as any).MISSKEY_CONFIG_PATH export const path = process.env.NODE_ENV == 'test'
? (global as any).MISSKEY_CONFIG_PATH ? `${dir}/test.yml`
: process.env.NODE_ENV == 'test' : `${dir}/default.yml`;
? `${dir}/test.yml`
: `${dir}/default.yml`;
/** /**
* *
@ -71,8 +69,6 @@ interface Source {
* Misskeyが自動的に() * Misskeyが自動的に()
*/ */
interface Mixin { interface Mixin {
themeColor: string;
themeColorForeground: string;
host: string; host: string;
scheme: string; scheme: string;
secondary_host: string; secondary_host: string;
@ -98,8 +94,6 @@ export default function load() {
config.url = normalizeUrl(config.url); config.url = normalizeUrl(config.url);
config.secondary_url = normalizeUrl(config.secondary_url); config.secondary_url = normalizeUrl(config.secondary_url);
mixin.themeColor = '#f76d6c';
mixin.themeColorForeground = '#fff';
mixin.host = config.url.substr(config.url.indexOf('://') + 3); mixin.host = config.url.substr(config.url.indexOf('://') + 3);
mixin.scheme = config.url.substr(0, config.url.indexOf('://')); mixin.scheme = config.url.substr(0, config.url.indexOf('://'));
mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3); mixin.secondary_host = config.secondary_url.substr(config.secondary_url.indexOf('://') + 3);

View File

@ -17,11 +17,13 @@ require('./common/tags');
"use strict"; "use strict";
const CONFIG = require('./common/scripts/config');
document.domain = CONFIG.host; document.domain = CONFIG.host;
// Set global configration // Set global configration
riot.mixin({ riot.mixin({
CONFIG: CONFIG CONFIG
}); });
// ↓ iOS待ちPolyfill (SEE: http://caniuse.com/#feat=fetch) // ↓ iOS待ちPolyfill (SEE: http://caniuse.com/#feat=fetch)

View File

@ -2,6 +2,8 @@
* API Request * API Request
*/ */
const CONFIG = require('./config');
let spinner = null; let spinner = null;
let pending = 0; let pending = 0;

View File

@ -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'
};

View File

@ -1,5 +1,6 @@
const ReconnectingWebSocket = require('reconnecting-websocket'); const ReconnectingWebSocket = require('reconnecting-websocket');
const riot = require('riot'); const riot = require('riot');
const CONFIG = require('./config');
class Connection { class Connection {
constructor(me, otherparty) { constructor(me, otherparty) {

View File

@ -1,3 +1,5 @@
const CONFIG = require('./config');
module.exports = () => { module.exports = () => {
localStorage.removeItem('me'); localStorage.removeItem('me');
document.cookie = `i=; domain=.${CONFIG.host}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`; document.cookie = `i=; domain=.${CONFIG.host}; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;

View File

@ -1,5 +1,6 @@
const ReconnectingWebSocket = require('reconnecting-websocket'); const ReconnectingWebSocket = require('reconnecting-websocket');
const riot = require('riot'); const riot = require('riot');
const CONFIG = require('./config');
module.exports = me => { module.exports = me => {
let state = 'initializing'; let state = 'initializing';

View File

@ -1,5 +1,6 @@
const riot = require('riot'); const riot = require('riot');
const nyaize = require('nyaize').default; const nyaize = require('nyaize').default;
const CONFIG = require('./config');
const escape = function(text) { const escape = function(text) {
return text return text

View File

@ -30,7 +30,7 @@
</label> </label>
<label class="recaptcha"> <label class="recaptcha">
<p class="caption"><i class="fa fa-toggle-on" if={ recaptchaed }></i><i class="fa fa-toggle-off" if={ !recaptchaed }></i>認証</p> <p class="caption"><i class="fa fa-toggle-on" if={ recaptchaed }></i><i class="fa fa-toggle-off" if={ !recaptchaed }></i>認証</p>
<div class="g-recaptcha" data-callback="onRecaptchaed" data-expired-callback="onRecaptchaExpired" data-sitekey={ CONFIG.recaptcha.siteKey }></div> <div if={ recaptcha } class="g-recaptcha" data-callback="onRecaptchaed" data-expired-callback="onRecaptchaExpired" data-sitekey={ recaptcha.siteKey }></div>
</label> </label>
<label class="agree-tou"> <label class="agree-tou">
<input name="agree-tou" type="checkbox" autocomplete="off" required="required"/> <input name="agree-tou" type="checkbox" autocomplete="off" required="required"/>
@ -193,10 +193,20 @@
}; };
this.on('mount', () => { this.on('mount', () => {
const head = document.getElementsByTagName('head')[0]; fetch('/config.json').then(res => {
const script = document.createElement('script'); res.json().then(conf => {
script.setAttribute('src', 'https://www.google.com/recaptcha/api.js'); this.update({
head.appendChild(script); recaptcha: {
siteKey: conf.recaptcha.siteKey
}
});
const head = document.getElementsByTagName('head')[0];
const script = document.createElement('script');
script.setAttribute('src', 'https://www.google.com/recaptcha/api.js');
head.appendChild(script);
});
});
}); });
this.onChangeUsername = () => { this.onChangeUsername = () => {

View File

@ -1,4 +1,5 @@
const riot = require('riot'); const riot = require('riot');
const CONFIG = require('../../common/scripts/config');
const dialog = require('./dialog'); const dialog = require('./dialog');
const api = require('../../common/scripts/api'); const api = require('../../common/scripts/api');

View File

@ -1,4 +1,5 @@
const riot = require('riot'); const riot = require('riot');
const CONFIG = require('../../common/scripts/config');
const dialog = require('./dialog'); const dialog = require('./dialog');
const api = require('../../common/scripts/api'); const api = require('../../common/scripts/api');

View File

@ -51,6 +51,17 @@ app.get(/\/api:meta/, require('./meta'));
app.get(/\/api:url/, require('./service/url-preview')); app.get(/\/api:url/, require('./service/url-preview'));
app.post(/\/api:rss/, require('./service/rss-proxy')); app.post(/\/api:rss/, require('./service/rss-proxy'));
/**
* Serve config
*/
app.get('/config.json', (req, res) => {
res.send({
recaptcha: {
siteKey: config.recaptcha.siteKey
}
});
});
/** /**
* Subdomain * Subdomain
*/ */

View File

@ -1,7 +1,7 @@
import * as webpack from 'webpack'; import * as webpack from 'webpack';
const StringReplacePlugin = require('string-replace-webpack-plugin'); const StringReplacePlugin = require('string-replace-webpack-plugin');
module.exports = (config, commit, env) => { module.exports = (commit, env) => {
const isProduction = env === 'production'; const isProduction = env === 'production';
const isDebug = !isProduction; const isDebug = !isProduction;
@ -21,7 +21,7 @@ module.exports = (config, commit, env) => {
loader: StringReplacePlugin.replace({ loader: StringReplacePlugin.replace({
replacements: [ replacements: [
{ pattern: /\$theme\-color\-foreground/g, replacement: () => '#fff' }, { 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({ new webpack.DefinePlugin({
VERSION: JSON.stringify(commit ? commit.hash : null), VERSION: JSON.stringify(commit ? commit.hash : null),
CONFIG: { CONFIG: {
themeColor: JSON.stringify(config.themeColor), themeColor: JSON.stringify('#f76d6c')
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),
}
} }
}), }),
new StringReplacePlugin(), new StringReplacePlugin(),