逐步完成前后端服务器

This commit is contained in:
2025-09-09 15:00:30 +08:00
parent fcb09432e9
commit c7dfa1e9fc
2937 changed files with 1477567 additions and 0 deletions

118
frontend/node_modules/zrender/build/build.js generated vendored Normal file
View File

@ -0,0 +1,118 @@
// const typescript = require('@rollup/plugin-typescript');
const typescript = require('rollup-plugin-typescript2');
const replace = require('@rollup/plugin-replace');
const rollup = require('rollup');
const path = require('path');
const processs = require('process');
const chalk = require('chalk');
const progress = require('./progress');
const UglifyJS = require('uglify-js');
const fs = require('fs');
function current() {
return (new Date()).toLocaleString();
}
function createInputOption(env, isWatch) {
return {
input: path.resolve(__dirname, '../index.ts'),
plugins: [
typescript({
clean: !isWatch,
tsconfigOverride: {
compilerOptions: {
// Rollup don't use CommonJS by default.
module: 'ES2015',
sourceMap: true,
// Use the esm d.ts
declaration: false
}
}
}),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify(env)
}),
progress({
scope: {
total: 0
}
})
]
};
}
const outputOption = {
format: 'umd',
file: path.resolve(__dirname, '../dist/zrender.js'),
sourcemap: true,
name: 'zrender'
};
function minify(outPath) {
const code = fs.readFileSync(outPath, 'utf-8');
const uglifyResult = UglifyJS.minify(code);
if (uglifyResult.error) {
throw new Error(uglifyResult.error);
}
fs.writeFileSync(outPath, uglifyResult.code, 'utf-8');
}
if (processs.argv.includes('--watch')) {
const watcher = rollup.watch({
...createInputOption('development', true),
output: [outputOption],
watch: {
clearScreen: true
}
});
watcher.on('event', event => {
switch(event.code) {
// case 'START':
// console.log(chalk.green('Begin to watch'));
// break;
case 'BUNDLE_START':
console.log(
chalk.gray(current()),
chalk.blue('File changed. Begin to bundle')
);
break;
case 'BUNDLE_END':
console.log(
chalk.gray(current()),
chalk.green('Finished bundle')
);
break;
case 'ERROR':
console.log(
chalk.gray(current()),
chalk.red(event.error)
);
break;
}
});
}
else {
// Unminified
rollup.rollup({
...createInputOption('development', false)
}).then(bundle => {
bundle.write(outputOption)
.then(() => {
// Minified
if (process.argv.indexOf('--minify') >= 0) {
rollup.rollup({
...createInputOption('production', false)
}).then(bundle => {
const file = outputOption.file.replace(/.js$/, '.min.js');
bundle.write(Object.assign(outputOption, {
file,
sourcemap: false
})).then(function () {
minify(file);
});
});
}
});
});
}

3
frontend/node_modules/zrender/build/package.json generated vendored Normal file
View File

@ -0,0 +1,3 @@
{
"type": "commonjs"
}

48
frontend/node_modules/zrender/build/prepareNightly.js generated vendored Normal file
View File

@ -0,0 +1,48 @@
const fs = require('fs');
const { execSync } = require('child_process');
const packageJsonPath = __dirname + '/../package.json';
const nightlyPackageName = 'zrender-nightly';
function updateVersion(version) {
const isNext = process.argv.includes('--next');
const parts = /(\d+)\.(\d+)\.(\d+)($|\-)/.exec(version);
if (!parts) {
throw new Error(`Invalid version number ${version}`);
}
// Add date to version.
const major = +parts[1];
let minor = +parts[2];
let patch = +parts[3];
const isStable = !parts[4];
if (isStable) {
// It's previous stable version. Dev version should be higher.
if (isNext) {
// Increase minor version for next branch.
minor++;
patch = 0;
}
else {
// Increase main version for master branch.
patch++;
}
}
const date = new Date().toISOString().replace(/:|T|\.|-/g, '').slice(0, 8);
return `${major}.${minor}.${patch}-dev.${date}`;
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
packageJson.name = nightlyPackageName;
const version = updateVersion(packageJson.version);
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf-8');
// Update version in package.json and package-lock.json
execSync(`npm version ${version} --git-tag-version=false`);
const entryPath = __dirname + '/../src/zrender.ts';
const entryFile = fs.readFileSync(entryPath, 'utf-8')
.replace(/export const version = '\S+'/, `export const version = '${version}'`);
fs.writeFileSync(entryPath, entryFile, 'utf-8');

108
frontend/node_modules/zrender/build/prepublish.js generated vendored Normal file
View File

@ -0,0 +1,108 @@
const fs = require('fs-extra');
const chalk = require('chalk');
const ignore = require('ignore');
const { execSync } = require('node:child_process');
console.log();
console.log(chalk.yellowBright(`⚠️ You should have run ${chalk.bold('`npm run release`')} before running this script!`));
console.log();
// check versions in key dist files
console.log(chalk.yellow('🔎 Checking versions in dist files...'));
const fileVersions = [
'package.json',
'package-lock.json',
'dist/zrender.js',
'dist/zrender.min.js'
].map(filePath => ({
file: filePath,
version: require('../' + filePath).version
}));
['lib/zrender.js', 'src/zrender.ts'].forEach(filePath => {
const version = fs.readFileSync(filePath, 'utf-8').match(/export (?:var|const) version = '(\S+)'/)[1];
fileVersions.push({
file: filePath,
version: version
});
});
const versions = fileVersions.map(({ file, version }) => {
console.log(` ∟ The version in [${chalk.blueBright(file)}] is ${chalk.cyanBright.bold(version)}`);
return version;
});
if (new Set(versions).size !== 1) {
console.log();
console.error(chalk.red('❌ Version does not match! Please check and rerun the release script via:'));
console.log();
console.error(chalk.yellow(' npm run release'));
console.log();
process.exit(-1);
}
console.log();
console.log(chalk.green('✔️ Versions are all the same.'));
console.log();
console.log(chalk.yellow('🔎 Checking unexpected files that probably shouldn\'t be published...\n'));
// check if there are unexpected files that not in .npmignore
const npmignore = fs.readFileSync('.npmignore', 'utf-8');
const npmignorePatterns = npmignore
.split(/\r?\n/)
.filter(item => item && !item.startsWith('#'));
const untrackedFiles = execSync('git ls-files --others --exclude-standard', { encoding: 'utf-8' })
.trim()
.split('\n')
.map(escapeOctal);
if (untrackedFiles.length) {
const maybeUnexpectedFiles = ignore().add(npmignorePatterns).filter(untrackedFiles);
if (maybeUnexpectedFiles.length) {
console.error(chalk.red(`❌ Found ${maybeUnexpectedFiles.length} file(s) that are neither tracked by git nor ignored by .npmignore! Please double-check before publishing them to npm.`));
maybeUnexpectedFiles.forEach(filePath => {
console.log(' ∟ ' + filePath);
});
console.log();
process.exit(-1);
}
}
console.log(chalk.green('✔️ No unexpected files found.'));
console.log();
console.log(chalk.yellow('🔎 Checking registry url of the packages in package-lock.json...\n'));
const NPM_REGISTRY = 'https://registry.npmjs.org/';
const packageLock = require('../package-lock.json');
const unexpectedPkgsFromUnofficialRegistry = Object.entries(packageLock.dependencies)
.concat(Object.entries(packageLock.packages))
.filter(([pkgName, pkgRegistry]) => pkgRegistry.resolved && !pkgRegistry.resolved.startsWith(NPM_REGISTRY));
if (unexpectedPkgsFromUnofficialRegistry.length) {
console.error(chalk.red('❌ Found packages that are not from npm registry in package-lock.json! Please double-check before publishing them to npm.'));
unexpectedPkgsFromUnofficialRegistry.forEach(([pkgName, pkgRegistry]) => {
console.log(`${pkgName} (${pkgRegistry.resolved})`);
});
console.log();
process.exit(-1);
}
console.log(chalk.green('✔️ No unexpected packages with unofficial registry url found.'));
console.log();
function escapeOctal(str) {
const matches = str.match(/(\\\d{3}){3}/g);
if (matches) {
matches.forEach(match => {
let encoded = '';
match.split('\\').forEach(code => !code || (encoded += '%' + parseInt(code, 8).toString(16)));
str = str.replace(match, decodeURI(encoded));
});
}
return str;
}

67
frontend/node_modules/zrender/build/processLib.js generated vendored Normal file
View File

@ -0,0 +1,67 @@
// Porcess generated lib files.
// Like adding js extension in the import statement.
const { transformImport } = require('./transformImport');
const globby = require('globby');
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const rollup = require('rollup');
const nodeResolve = require('@rollup/plugin-node-resolve').default;
function addJsExtension(moduleName) {
// Ignore 'tslib'
if (!(moduleName.startsWith('.'))) {
return moduleName;
}
if (moduleName.endsWith('.ts')) {
// Replace ts with js
return moduleName.replace(/\.ts$/, '.js');
}
else if (moduleName.endsWith('.js')) {
return moduleName;
}
else {
return moduleName + '.js'
}
}
async function transform() {
const libFiles = await globby([
'**/*.js'
], {
cwd: path.join(__dirname, '../lib'),
absolute: true
});
if (libFiles.length === 0) {
throw new Error('No lib files found.')
}
for (let file of libFiles) {
const code = fs.readFileSync(file, 'utf-8');
fs.writeFileSync(file, transformImport(code, addJsExtension), 'utf-8');
}
// Transform index;
const indexFile = path.join(__dirname, '../index.js');
fs.writeFileSync(
indexFile,
transformImport(
fs.readFileSync(indexFile, 'utf-8'),
(mduleName) => addJsExtension(mduleName).replace('./src', './lib')
)
)
}
transform().then(() => {
console.log(chalk.green('Added .js extensions.'));
console.log(chalk.gray('Start testing generated libs...'));
}).then(() => {
return rollup.rollup({
input: path.resolve(__dirname, '../index.js'),
plugins: [nodeResolve()]
});
}).then(() => {
console.log(chalk.green('Libs can be bundled!'));
});

65
frontend/node_modules/zrender/build/progress.js generated vendored Normal file
View File

@ -0,0 +1,65 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const chalk = require('chalk');
const path = require('path');
module.exports = function progress(options = {}) {
const scope = options.scope || {};
scope.finished = scope.finished || 0;
scope.total = scope.total || 0;
return {
name: 'progress',
buildStart() {
scope.finished = 0;
scope.total = 0;
},
load() {
// TODO More accurate total number
scope.total++;
},
transform(code, id) {
scope.finished++;
const filePath = path.relative(process.cwd(), id).split(path.sep).join('/');
const output = `[${scope.finished}/${scope.total}]: ${chalk.grey(filePath)}`;
if (process.stdout.isTTY) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write(output);
}
else {
console.log(output);
}
},
buildEnd() {
if (process.stdout.isTTY) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
}
else {
console.log('');
}
}
};
};

115
frontend/node_modules/zrender/build/transformImport.js generated vendored Normal file
View File

@ -0,0 +1,115 @@
// adding js extension in the import statement.
// Reference:
// https://regexr.com/47jlq
// https://gist.github.com/manekinekko/7e58a17bc62a9be47172
const regexp = /((?:(?:import)|(?:export))\s+?(?:(?:(?:[\w*\s{},\/]*)\s+from\s+?)|))(?:(?:"(.*?)")|(?:'(.*?)'))([\s]*?(?:;|$|))/g;
module.exports.transformImport = function (code, processModuleName) {
return code.replace(regexp, (str, prefix, moduleNameA, moduleNameB, postfix) => {
let moduleName = (moduleNameA === undefined ? moduleNameB : moduleNameA).trim();
const quote = moduleNameA === undefined ? "'" : '"';
return prefix + quote + processModuleName(moduleName) + quote + postfix;
// Not support other extensions.
});
}
const testCases = `import videos from './videos/index.js'
export default (socket, context) => {
// dynamically importing all the socket.io handler (it's dynamic import that happen at run time)
import {
something
} from "./test/okbb"
const f = 2;
import test from 'obb'
import {
Component
} from '@angular2/core';
import defaultMember from "module-0";
import * as name from "module-1 ";
import { member } from " module-2";
import { member as alias } from "module-3";
import { member1 , member2 } from "module-4";
import { member1 , member2 as alias2 , member3 as alias3 } from "module-5";
import defaultMember, { member, member } from "module-6";
import defaultMember, * as name from "module-7";
import "module-8";
import "module-9" // comment no problem
import {
AAAA,
// BBB
} from 'module-10';
import "module-b' // doesn't match -> the opening and closing quation mark are different
importing hya from 'ttt'
import fbsfrom ''
// Export expressions.
export { aaa };
export * from "module-11";
export { aaa } from "module-12";
// Should not be parsed
export default aaa;
export function bbb () {
};
`
module.exports.runTest = function () {
const expected = [
'./videos/index.js',
'./test/okbb',
'obb',
'@angular2/core',
'module-0',
'module-1',
'module-2',
'module-3',
'module-4',
'module-5',
'module-6',
'module-7',
'module-8',
'module-9',
'module-10',
'module-11',
'module-12'
]
let cursor = 0;
module.exports.transformImport(testCases, (moduleName) => {
if (expected[cursor] !== moduleName) {
throw new Error(`Expected ${expected[cursor]}. Actual ${moduleName}`);
}
cursor++;
return moduleName;
})
if (cursor !== expected.length) {
throw new Error('Test failed');
}
console.log('All test passed!')
}
// module.exports.runTest();