mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
next: esbuild loader
This commit is contained in:
1 parent
cca54dc92a
commit
5eaec48002
28 files changed
+171
-113
No files matched your search
@@ -46,7 +46,8 @@ function getFiles(folder: string, base = ''): string[] {
|
||||
|
||||
export async function handler(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'handler.js');
|
||||
let p = path.resolve(i, 'handler.ts');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'handler.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
logger.info('Handler init: %s', i);
|
||||
@@ -161,7 +162,8 @@ export async function uistatic(pending: string[], fail: string[]) {
|
||||
|
||||
export async function model(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'model.js');
|
||||
let p = path.resolve(i, 'model.ts');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'model.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
logger.info('Model init: %s', i);
|
||||
@@ -178,7 +180,8 @@ export async function model(pending: string[], fail: string[]) {
|
||||
|
||||
export async function lib(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'lib.js');
|
||||
let p = path.resolve(i, 'lib.ts');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'lib.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
logger.info('Lib init: %s', i);
|
||||
@@ -195,7 +198,8 @@ export async function lib(pending: string[], fail: string[]) {
|
||||
|
||||
export async function service(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'service.js');
|
||||
let p = path.resolve(i, 'service.ts');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'service.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
try {
|
||||
logger.info('Service init: %s', i);
|
||||
@@ -216,7 +220,8 @@ export async function service(pending: string[], fail: string[]) {
|
||||
|
||||
export async function script(pending: string[], fail: string[], active: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'script.js');
|
||||
let p = path.resolve(i, 'script.ts');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'script.js');
|
||||
if (await fs.pathExists(p) && !fail.includes(i)) {
|
||||
try {
|
||||
logger.info('Script init: %s', i);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
|
||||
const versionNum = +process.version.replace(/v/gim, '').split('.')[0];
|
||||
if (versionNum < 14) throw new Error('NodeJS >=v14 required');
|
||||
|
||||
|
||||
if (!global.Hydro) {
|
||||
global.Hydro = {
|
||||
version: {
|
||||
node: process.version,
|
||||
hydrooj: require('hydrooj/package.json').version,
|
||||
},
|
||||
stat: { reqCount: 0 },
|
||||
handler: {},
|
||||
// @ts-ignore
|
||||
service: {},
|
||||
// @ts-ignore
|
||||
model: {},
|
||||
script: {},
|
||||
// @ts-ignore
|
||||
lib: {},
|
||||
// @ts-ignore
|
||||
ui: {
|
||||
manifest: {},
|
||||
nodes: {
|
||||
nav: [],
|
||||
problem_add: [],
|
||||
user_dropdown: [],
|
||||
},
|
||||
template: {},
|
||||
},
|
||||
// @ts-ignore
|
||||
error: {},
|
||||
locales: {},
|
||||
};
|
||||
global.addons = [];
|
||||
}
|
||||
@@ -1,64 +1,25 @@
|
||||
import 'reflect-metadata';
|
||||
/* eslint-disable import/first */
|
||||
/* eslint-disable no-continue */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
|
||||
const versionNum = +process.version.replace(/v/gim, '').split('.')[0];
|
||||
if (versionNum < 14) throw new Error('NodeJS >=v14 required');
|
||||
|
||||
import cac from 'cac';
|
||||
|
||||
const argv = cac().parse();
|
||||
|
||||
if (argv.options.debug) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
process.env.DEV = 'on';
|
||||
} else process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
||||
|
||||
if (!global.Hydro) {
|
||||
global.Hydro = {
|
||||
version: {
|
||||
node: process.version,
|
||||
hydrooj: require('hydrooj/package.json').version,
|
||||
},
|
||||
stat: { reqCount: 0 },
|
||||
handler: {},
|
||||
// @ts-ignore
|
||||
service: {},
|
||||
// @ts-ignore
|
||||
model: {},
|
||||
script: {},
|
||||
// @ts-ignore
|
||||
lib: {},
|
||||
// @ts-ignore
|
||||
ui: {
|
||||
manifest: {},
|
||||
nodes: {
|
||||
nav: [],
|
||||
problem_add: [],
|
||||
user_dropdown: [],
|
||||
},
|
||||
template: {},
|
||||
},
|
||||
// @ts-ignore
|
||||
error: {},
|
||||
locales: {},
|
||||
};
|
||||
global.addons = [];
|
||||
}
|
||||
import 'reflect-metadata';
|
||||
import './init';
|
||||
import './interface';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import cluster from 'cluster';
|
||||
import fs from 'fs-extra';
|
||||
import './utils';
|
||||
import cac from 'cac';
|
||||
import { Logger } from './logger';
|
||||
import './ui';
|
||||
import * as bus from './service/bus';
|
||||
|
||||
export * from './interface';
|
||||
const argv = cac().parse();
|
||||
if (argv.options.debug) {
|
||||
process.env.NODE_ENV = 'development';
|
||||
process.env.DEV = 'on';
|
||||
} else process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
||||
const logger = new Logger('loader');
|
||||
logger.debug('%o', argv);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ if (cluster.isMaster) {
|
||||
});
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
process.stdin.setEncoding('utf-8');
|
||||
process.stdin.setRawMode(false);
|
||||
process.stdin.on('data', (buf) => {
|
||||
const input = buf.toString();
|
||||
if (input[0] === '@') {
|
||||
|
||||
Reference in new issue
Block a user