From 92af4401e22749e726bce69c3bd02c627e7af7e6 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 1 Nov 2019 22:34:26 +0900 Subject: [PATCH] =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E6=99=82=E3=81=ABpackage.jso?= =?UTF-8?q?n=E3=82=92=E5=8F=82=E7=85=A7=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20(#5418)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 実行時にpackage.jsonを参照しないように * nodeinfo * move meta.json * add dummy * lowercase --- gulpfile.ts | 2 +- src/argv.ts | 4 +- src/boot/master.ts | 11 +++-- src/config/load.ts | 5 ++- src/config/types.ts | 1 + src/meta.json | 3 ++ src/server/api/endpoints/meta.ts | 5 +-- src/server/nodeinfo.ts | 69 +++++++++++--------------------- src/server/web/index.ts | 3 +- webpack.config.ts | 2 +- 10 files changed, 43 insertions(+), 62 deletions(-) create mode 100644 src/meta.json diff --git a/gulpfile.ts b/gulpfile.ts index 8b9820c0ce..00bd905566 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -96,7 +96,7 @@ gulp.task('cleanall', gulp.parallel('clean', cb => )); gulp.task('build:client:script', () => { - const client = require('./built/client/meta.json'); + const client = require('./built/meta.json'); return gulp.src(['./src/client/app/boot.js', './src/client/app/safe.js']) .pipe(replace('VERSION', JSON.stringify(client.version))) .pipe(replace('ENV', JSON.stringify(env))) diff --git a/src/argv.ts b/src/argv.ts index 562852d17b..a92338f867 100644 --- a/src/argv.ts +++ b/src/argv.ts @@ -1,8 +1,8 @@ import * as program from 'commander'; -import * as pkg from '../package.json'; +import config from './config'; program - .version(pkg.version) + .version(config.version) .option('--no-daemons', 'Disable daemon processes (for debbuging)') .option('--disable-clustering', 'Disable clustering') .option('--only-server', 'Run server only (without job queue processing)') diff --git a/src/boot/master.ts b/src/boot/master.ts index 381c4bc4ca..1517de1586 100644 --- a/src/boot/master.ts +++ b/src/boot/master.ts @@ -8,7 +8,6 @@ import Logger from '../services/logger'; import loadConfig from '../config/load'; import { Config } from '../config/types'; import { lessThan } from '../prelude/array'; -import * as pkg from '../../package.json'; import { program } from '../argv'; import { showMachineInfo } from '../misc/show-machine-info'; import { initDb } from '../db/postgre'; @@ -16,10 +15,10 @@ import { initDb } from '../db/postgre'; const logger = new Logger('core', 'cyan'); const bootLogger = logger.createSubLogger('boot', 'magenta', false); -function greet() { +function greet(config: Config) { if (!program.quiet) { //#region Misskey logo - const v = `v${pkg.version}`; + const v = `v${config.version}`; console.log(' _____ _ _ '); console.log(' | |_|___ ___| |_ ___ _ _ '); console.log(' | | | | |_ -|_ -| \'_| -_| | |'); @@ -35,21 +34,21 @@ function greet() { } bootLogger.info('Welcome to Misskey!'); - bootLogger.info(`Misskey v${pkg.version}`, null, true); + bootLogger.info(`Misskey v${config.version}`, null, true); } /** * Init master process */ export async function masterMain() { - greet(); - let config!: Config; try { // initialize app config = await init(); + greet(config); + if (config.port == null || Number.isNaN(config.port)) { bootLogger.error('The port is not configured. Please configure port.', null, true); process.exit(1); diff --git a/src/config/load.ts b/src/config/load.ts index aeed54d74e..efebb8bd03 100644 --- a/src/config/load.ts +++ b/src/config/load.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as yaml from 'js-yaml'; import { Source, Mixin } from './types'; -import * as pkg from '../../package.json'; +import * as meta from '../meta.json'; /** * Path of configuration directory @@ -30,6 +30,7 @@ export default function load() { config.port = config.port || parseInt(process.env.PORT || '', 10); + mixin.version = meta.version; mixin.host = url.host; mixin.hostname = url.hostname; mixin.scheme = url.protocol.replace(/:$/, ''); @@ -38,7 +39,7 @@ export default function load() { mixin.apiUrl = `${mixin.scheme}://${mixin.host}/api`; mixin.authUrl = `${mixin.scheme}://${mixin.host}/auth`; mixin.driveUrl = `${mixin.scheme}://${mixin.host}/files`; - mixin.userAgent = `Misskey/${pkg.version} (${config.url})`; + mixin.userAgent = `Misskey/${meta.version} (${config.url})`; if (config.autoAdmin == null) config.autoAdmin = false; diff --git a/src/config/types.ts b/src/config/types.ts index b96e727506..e766d1f14a 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -58,6 +58,7 @@ export type Source = { * Misskeyが自動的に(ユーザーが設定した情報から推論して)設定する情報 */ export type Mixin = { + version: string; host: string; hostname: string; scheme: string; diff --git a/src/meta.json b/src/meta.json new file mode 100644 index 0000000000..9afdfcf1e1 --- /dev/null +++ b/src/meta.json @@ -0,0 +1,3 @@ +{ + "version": "unknown" +} diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 153780e3fa..6df6362a6f 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -3,7 +3,6 @@ import * as os from 'os'; import config from '../../../config'; import define from '../define'; import { fetchMeta } from '../../../misc/fetch-meta'; -import * as pkg from '../../../../package.json'; import { Emojis } from '../../../models'; import { getConnection } from 'typeorm'; import redis from '../../../db/redis'; @@ -36,7 +35,7 @@ export const meta = { type: 'string' as const, optional: false as const, nullable: false as const, description: 'The version of Misskey of this instance.', - example: pkg.version + example: config.version }, name: { type: 'string' as const, @@ -114,7 +113,7 @@ export default define(meta, async (ps, me) => { maintainerName: instance.maintainerName, maintainerEmail: instance.maintainerEmail, - version: pkg.version, + version: config.version, name: instance.name, uri: config.url, diff --git a/src/server/nodeinfo.ts b/src/server/nodeinfo.ts index d35ced0e42..75a8fa87a4 100644 --- a/src/server/nodeinfo.ts +++ b/src/server/nodeinfo.ts @@ -2,7 +2,6 @@ import * as Router from '@koa/router'; import config from '../config'; import { fetchMeta } from '../misc/fetch-meta'; // import User from '../models/user'; -import { name as softwareName, version, repository } from '../../package.json'; // import Note from '../models/note'; const router = new Router(); @@ -20,27 +19,7 @@ export const links = [/* (awaiting release) { const nodeinfo2 = async () => { const [ - { - name, - description, - maintainerName, - maintainerEmail, - langs, - ToSUrl, - repositoryUrl, - feedbackUrl, - announcements, - disableRegistration, - disableLocalTimeline, - disableGlobalTimeline, - enableRecaptcha, - maxNoteTextLength, - enableTwitterIntegration, - enableGithubIntegration, - enableDiscordIntegration, - enableEmail, - enableServiceWorker - }, + meta, // total, // activeHalfyear, // activeMonth, @@ -57,43 +36,43 @@ const nodeinfo2 = async () => { return { software: { - name: softwareName, - version, - repository: repository.url + name: 'misskey', + version: config.version, + repository: meta.repositoryUrl, }, protocols: ['activitypub'], services: { inbound: [] as string[], outbound: ['atom1.0', 'rss2.0'] }, - openRegistrations: !disableRegistration, + openRegistrations: !meta.disableRegistration, usage: { users: {} // { total, activeHalfyear, activeMonth }, // localPosts, // localComments }, metadata: { - name, - description, + name: meta.name, + description: meta.description, maintainer: { - name: maintainerName, - email: maintainerEmail + name: meta.maintainerName, + email: meta.maintainerEmail }, - langs, - ToSUrl, - repositoryUrl, - feedbackUrl, - announcements, - disableRegistration, - disableLocalTimeline, - disableGlobalTimeline, - enableRecaptcha, - maxNoteTextLength, - enableTwitterIntegration, - enableGithubIntegration, - enableDiscordIntegration, - enableEmail, - enableServiceWorker + langs: meta.langs, + ToSUrl: meta.ToSUrl, + repositoryUrl: meta.repositoryUrl, + feedbackUrl: meta.feedbackUrl, + announcements: meta.announcements, + disableRegistration: meta.disableRegistration, + disableLocalTimeline: meta.disableLocalTimeline, + disableGlobalTimeline: meta.disableGlobalTimeline, + enableRecaptcha: meta.enableRecaptcha, + maxNoteTextLength: meta.maxNoteTextLength, + enableTwitterIntegration: meta.enableTwitterIntegration, + enableGithubIntegration: meta.enableGithubIntegration, + enableDiscordIntegration: meta.enableDiscordIntegration, + enableEmail: meta.enableEmail, + enableServiceWorker: meta.enableServiceWorker } }; }; diff --git a/src/server/web/index.ts b/src/server/web/index.ts index 36f9788d79..dff6e139c8 100644 --- a/src/server/web/index.ts +++ b/src/server/web/index.ts @@ -13,7 +13,6 @@ import * as views from 'koa-views'; import docs from './docs'; import packFeed from './feed'; import { fetchMeta } from '../../misc/fetch-meta'; -import * as pkg from '../../../package.json'; import { genOpenapiSpec } from '../api/openapi/gen-spec'; import config from '../../config'; import { Users, Notes, Emojis, UserProfiles, Pages } from '../../models'; @@ -257,7 +256,7 @@ router.get('/info', async ctx => { where: { host: null } }); await ctx.render('info', { - version: pkg.version, + version: config.version, machine: os.hostname(), os: os.platform(), node: process.version, diff --git a/webpack.config.ts b/webpack.config.ts index ba0e09dde5..77b340ce3d 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -130,7 +130,7 @@ module.exports = { 'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development') }), new WebpackOnBuildPlugin((stats: any) => { - fs.writeFileSync('./built/client/meta.json', JSON.stringify({ version: meta.version }), 'utf-8'); + fs.writeFileSync('./built/meta.json', JSON.stringify({ version: meta.version }), 'utf-8'); fs.mkdirSync('./built/client/assets/locales', { recursive: true });