next: esbuild loader

This commit is contained in:
undefined committed 2021-07-29 02:59:50 +08:00
1 parent cca54dc92a
commit 5eaec48002
28 files changed
+171 -113

No files matched your search

+10 -5
View File
@@ -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);
+37
View File
@@ -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 = [];
}
+8 -47
View File
@@ -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);
+1
View File
@@ -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] === '@') {