This commit is contained in:
masnn committed 2020-04-08 21:43:41 +08:00
1 parent 9c45527522
commit 7dc31d02fa
15 files changed
+10521 -3

No files matched your search

+2 -3
View File
@@ -31,8 +31,7 @@ const includedPages = pageLoader.getAutoloadPages();
function buildSequence(pages, type) {
if (process.env.NODE_ENV !== 'production') {
if (['before', 'after'].indexOf(type) === -1) {
// eslint-disable-next-line quotes
throw new Error(`'type' should be one of 'before' or 'after'`);
throw new Error(`'type' should be one of 'before' or 'after'`); // eslint-disable-line quotes
}
}
return pages
@@ -51,7 +50,7 @@ async function load() {
...buildSequence(includedPages, 'after'),
...buildSequence([currentPage], 'after'),
];
// eslint-disable-next-line no-restricted-syntax
// eslint-disable-next-line no-restricted-syntax
for (const { page, func, type } of loadSequence) {
if (typeof func !== 'function') {
if (process.env.NODE_ENV !== 'production') {
+90
View File
@@ -0,0 +1,90 @@
/* eslint-disable */
import _ from 'lodash';
import moment from 'moment';
import gulp from 'gulp';
import log from 'fancy-log';
import chalk from 'chalk';
import svgmin from 'gulp-svgmin';
import vinylBuffer from 'vinyl-buffer';
import iconfont from 'gulp-iconfont';
import nunjucks from 'gulp-nunjucks';
import plumber from 'gulp-plumber';
import gulpif from 'gulp-if';
import vjGenerateLocales from '../plugins/gulpGenerateLocales';
import vjTouch from '../plugins/gulpTouch';
let isInWatchMode = false;
export let tasks = {};
const iconTimestamp = moment.utc([2017, 0, 1, 0, 0, 0, 0]).unix();
function handleWatchChange(name, r = 300) {
return _.debounce((ev) => {
log('File %s: %s', chalk.yellow(ev.type), ev.path);
tasks[name]();
}, r);
}
function offsetMtimeAtFirstBuild() {
// Offset the mtime at first build to
// workaround webpack/watchpack issue #25.
return gulpif(!isInWatchMode, vjTouch(~~((Date.now() - 30 * 1000) / 1000)));
}
export default function ({ watch, production, errorHandler }) {
let iconfontTemplateArgs = null;
tasks['iconfont:template'] = () => gulp
.src('misc/icons/template/*.styl')
.pipe(nunjucks.compile(iconfontTemplateArgs))
.pipe(gulp.dest('misc/.iconfont'))
.pipe(offsetMtimeAtFirstBuild());
tasks.iconfont = () => gulp
.src('misc/icons/*.svg')
.pipe(plumber({ errorHandler }))
.pipe(svgmin())
.pipe(gulp.dest('misc/icons'))
.pipe(offsetMtimeAtFirstBuild())
.pipe(iconfont({
fontHeight: 1000,
prependUnicode: false,
descent: 6.25 / 100 * 1000,
fontName: 'vj4icon',
formats: ['svg', 'ttf', 'eot', 'woff', 'woff2'],
timestamp: iconTimestamp,
}))
.on('glyphs', (glyphs, options) => {
iconfontTemplateArgs = { glyphs, options };
tasks['iconfont:template']();
})
.pipe(gulp.dest('misc/.iconfont'))
.pipe(vinylBuffer())
.pipe(offsetMtimeAtFirstBuild());
tasks.locale = () => gulp
.src('../locales/*.yaml')
.pipe(plumber({ errorHandler }))
.pipe(vjGenerateLocales())
.pipe(gulp.dest('static/locale'))
.pipe(offsetMtimeAtFirstBuild());
tasks.watch = () => {
isInWatchMode = true;
gulp.watch('misc/icons/*.svg', handleWatchChange('iconfont'));
gulp.watch('../locales/*.yaml', handleWatchChange('locale'));
};
for (const key in tasks) {
// gulp4 uses function name directly as task name
Object.defineProperty(tasks[key], 'name', {
value: key,
configurable: true,
});
tasks[key] = gulp.series(tasks[key]);
}
tasks.default = gulp.series(gulp.parallel(tasks.iconfont, tasks.locale));
return tasks;
}
+291
View File
@@ -0,0 +1,291 @@
/* eslint-disable */
import _ from 'lodash';
import webpack from 'webpack';
import fs from 'fs-extra';
import FriendlyErrorsPlugin from 'friendly-errors-webpack-plugin';
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import StaticManifestPlugin from '../plugins/webpackStaticManifestPlugin.js';
import DummyOutputPlugin from '../plugins/webpackDummyOutputPlugin.js';
import mapWebpackUrlPrefix from '../utils/mapWebpackUrlPrefix.js';
import root from '../utils/root.js';
const extractProjectCSS = new ExtractTextPlugin({ filename: 'vj4.css?[sha1:contenthash:hex:10]', allChunks: true });
const extractVendorCSS = new ExtractTextPlugin({ filename: 'vendors.css?[sha1:contenthash:hex:10]', allChunks: true });
const beautifyOutputUrl = mapWebpackUrlPrefix([
{ prefix: 'node_modules/katex/dist/', replace: 'katex/' },
{ prefix: 'misc/.iconfont', replace: 'ui/iconfont' },
]);
export default function (env = {}) {
function eslintLoader() {
return {
loader: 'eslint-loader',
options: {
configFile: root('.eslintrc.js'),
},
};
}
function babelLoader() {
let cacheDirectory = root('.cache/babel');
try {
fs.ensureDirSync(cacheDirectory);
} catch (ignored) {
cacheDirectory = false;
}
return {
loader: 'babel-loader',
options: {
...require(root('package.json')).babelForProject,
cacheDirectory,
},
};
}
function jsonLoader() {
return 'json-loader';
}
function postcssLoader() {
return {
loader: 'postcss-loader',
options: {
sourceMap: env.production,
},
};
}
function styleLoader() {
return 'style-loader';
}
function cssLoader() {
return 'css-loader?importLoaders=1';
}
function stylusLoader() {
return 'stylus-loader';
}
function fileLoader() {
return {
loader: 'file-loader',
options: {
name: '[path][name].[ext]?[sha1:hash:hex:10]',
},
};
}
const config = {
bail: true,
profile: true,
context: root(),
devtool: env.production ? 'source-map' : false,
entry: {
vj4: './Entry.js',
},
output: {
path: root('../.uibuild'),
publicPath: '/', // overwrite in entry.js
hashFunction: 'sha1',
hashDigest: 'hex',
hashDigestLength: 10,
filename: '[name].js?[chunkhash]',
chunkFilename: '[name].chunk.js?[chunkhash]',
},
resolve: {
modules: [
root('node_modules'),
],
alias: {
vj: root(),
},
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules[\/\\]/,
enforce: 'pre',
use: [eslintLoader()],
},
{
// fonts and images
test: /\.(svg|ttf|eot|woff|woff2|png|jpg|jpeg|gif)$/,
use: [fileLoader()],
},
{
// ES2015 scripts
test: /\.js$/,
exclude: /node_modules[\/\\]/,
use: [babelLoader()],
},
{
test: /\.json$/,
use: [jsonLoader()],
},
{
// fix pickadate loading
test: /pickadate/,
use: [
{
loader: 'imports-loader',
options: { define: '>false' },
},
],
},
{
// project stylus stylesheets
test: /\.styl$/,
use: env.watch
? [styleLoader(), cssLoader(), postcssLoader(), stylusLoader()]
: extractProjectCSS.extract([cssLoader(), postcssLoader(), stylusLoader()])
,
},
{
// vendors stylesheets
test: /\.css$/,
include: /node_modules[\/\\]/,
use: env.watch
? [styleLoader(), cssLoader()]
: extractVendorCSS.extract([cssLoader()])
,
},
{
// project stylesheets
test: /\.css$/,
exclude: /node_modules[\/\\]/,
use: env.watch
? [styleLoader(), cssLoader(), postcssLoader()]
: extractProjectCSS.extract([cssLoader(), postcssLoader()])
,
},
],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
katex: 'katex/dist/katex.js',
React: 'react',
}),
new FriendlyErrorsPlugin(),
// don't include momentjs locale files
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// don't include timeago.js locale files
// no use. FIXME.
// new webpack.IgnorePlugin(/locales\//, /timeago/),
// extract stylesheets into a standalone file
env.watch
? new DummyOutputPlugin('vendors.css')
: extractVendorCSS,
env.watch
? new DummyOutputPlugin('vj4.css')
: extractProjectCSS,
// extract 3rd-party JavaScript libraries into a standalone file
env.watch
? new DummyOutputPlugin('vendors.js')
: new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
minChunks: (module, count) => (
module.resource
&& module.resource.indexOf(root()) === -1
&& module.resource.match(/\.jsx?$/)
),
}),
// extract manifest into a standalone file
env.watch
? new DummyOutputPlugin('manifest.js')
: new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
}),
new webpack.optimize.CommonsChunkPlugin({
children: true,
async: true,
minChunks: 2,
}),
// copy static assets
new CopyWebpackPlugin([{ from: root('static') }]),
// copy emoji images
new CopyWebpackPlugin([{ from: root('node_modules/emojify.js/dist/images/basic'), to: 'img/emoji/' }]),
// Options are provided by LoaderOptionsPlugin until webpack#3136 is fixed
new webpack.LoaderOptionsPlugin({
test: /\.styl$/,
stylus: {
default: {
preferPathResolver: 'webpack',
use: [
require('rupture')(),
],
import: [
'~vj/common/common.inc.styl',
],
},
},
}),
// Make sure process.env.NODE_ENV === 'production' in production mode
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: env.production ? '"production"' : '"debug"',
},
}),
env.production
? new UglifyJsPlugin({ sourceMap: true })
: function () { },
env.production
? new OptimizeCssAssetsPlugin()
: function () { },
env.production
? new webpack.optimize.ModuleConcatenationPlugin()
: function () { },
env.production
? new webpack.LoaderOptionsPlugin({ minimize: true })
: function () { },
// Replace Module Id with hash or name
env.production
? new webpack.HashedModuleIdsPlugin()
: new webpack.NamedModulesPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
context: root(),
// Beautify the output path of assets
customInterpolateName: (url, name, options) => beautifyOutputUrl(url),
},
}),
// Finally, output asset hashes
new StaticManifestPlugin({
fileName: 'static-manifest.json',
ignore: [
'img/emoji/',
'katex/',
],
}),
],
};
return config;
}
+3
View File
@@ -0,0 +1,3 @@
/* eslint-disable */
require('@babel/register');
require('./main.js');
+13
View File
@@ -0,0 +1,13 @@
/* eslint-disable */
import { argv } from 'yargs';
import root from './utils/root';
import runGulp from './runGulp';
import runWebpack from './runWebpack';
async function main() {
await runGulp(argv);
runWebpack(argv);
}
process.chdir(root());
main();
+32
View File
@@ -0,0 +1,32 @@
/* eslint-disable */
import yaml from 'js-yaml';
import PluginError from 'plugin-error';
import through from 'through2';
import path from 'path';
export default function generateLocales() {
function bufferContents(file, encoding, callback) {
if (file.isNull()) {
callback();
return;
}
if (file.isStream()) {
this.emit('error', new PluginError('gulpGenerateLocales', 'Stream not supported'));
callback();
return;
}
const doc = yaml.safeLoad(file.contents);
file.contents = Buffer.from(`window.LOCALES = ${JSON.stringify(doc, null, 2)}`);
file.path = path.join(
path.dirname(file.path),
`${path.basename(file.path, path.extname(file.path))}.js`
);
this.push(file);
callback();
}
return through.obj(bufferContents);
}
+35
View File
@@ -0,0 +1,35 @@
/* eslint-disable */
import PluginError from 'plugin-error';
import through from 'through2';
import fs from 'fs-extra';
export default function touch(mtime) {
async function touchFile(file) {
const fd = await fs.open(file.path, 'a');
try {
await fs.futimes(fd, mtime, mtime);
} finally {
await fs.close(fd);
}
}
function processStream(file, encoding, callback) {
if (file.isNull()) {
callback();
return;
}
if (file.isStream()) {
this.emit('error', new PluginError('gulpTouch', 'Stream not supported'));
callback();
return;
}
touchFile(file)
.catch(err => this.emit('error', err))
.then(() => {
this.push(file);
callback();
});
}
return through.obj(processStream);
}
@@ -0,0 +1,16 @@
/* eslint-disable */
export default class DummyOutputPlugin {
constructor(file) {
this.file = file;
}
apply(compiler) {
compiler.plugin('emit', (compilation, callback) => {
compilation.assets[this.file] = {
source: () => '',
size: () => 0,
};
callback();
});
}
}
@@ -0,0 +1,50 @@
/* eslint-disable */
const _ = require('lodash');
const crypto = require('crypto');
export default class StaticManifestPlugin {
constructor({ fileName, ignore }) {
this.fileName = fileName;
this.ignore = ignore;
}
apply(compiler) {
compiler.plugin('emit', (compilation, callback) => {
const stats = compilation.getStats().toJson();
const manifest = _(stats.assets)
.map((asset) => {
const { name } = asset;
// Skip files listed in ignore
if (_.some(this.ignore, ignorePattern => name.indexOf(ignorePattern) > -1)) {
return null;
}
// Skip calculating hash for names like ?xxxx
if (name.indexOf('?') > -1) {
return [
name.replace(/\?[\s\S]*/, ''), // origin name
name, // name with hash
];
}
// We need to calculate hash for the remaining files.
const source = compilation.assets[asset.name].source();
const shasum = crypto.createHash('sha1');
shasum.update(source);
const hash = shasum.digest('hex').substr(0, 10);
return [
name, // origin name
`${name}?${hash}`, // name with hash
];
})
.filter()
.orderBy(['0'])
.fromPairs()
.value();
const json = JSON.stringify(manifest, null, 2);
compilation.assets[this.fileName] = {
source: () => json,
size: () => json.length,
};
callback();
});
}
}
+34
View File
@@ -0,0 +1,34 @@
/* eslint-disable */
import _ from 'lodash';
import gulp from 'gulp';
import log from 'fancy-log';
import chalk from 'chalk';
import gulpConfig from './config/gulp.js';
export default async function ({ watch, production }) {
function handleError(err) {
log(chalk.red('Error: %s'), chalk.reset(err.toString()));
if (err && !watch) { process.exit(1); }
}
const gulpTasks = gulpConfig({ watch, production, errorHandler: handleError });
return new Promise((resolve) => {
const taskList = {};
gulp.on('start', ({ uid, name }) => {
log(chalk.blue('Starting task: %s'), chalk.reset(name));
taskList[uid] = true;
});
gulp.on('stop', ({ uid, name }) => {
log(chalk.green('Finished: %s'), chalk.reset(name));
taskList[uid] = false;
if (Object.values(taskList).filter(b => b).length === 0) {
if (watch) {
gulpTasks.watch();
}
resolve();
}
});
gulpTasks.default();
});
}
+32
View File
@@ -0,0 +1,32 @@
/* eslint-disable */
import fs from 'fs';
import webpack from 'webpack';
import root from './utils/root';
import webpackConfig from './config/webpack';
export default function ({ watch, production }) {
const compiler = webpack(webpackConfig({ watch, production }));
compiler.apply(new webpack.ProgressPlugin());
const outputOptions = {
colors: true,
errorDetails: true,
optimizationBailout: production,
};
function compilerCallback(err, stats) {
if (err) {
// config errors
console.error(err.stack || err);
if (err.details) console.error(err.details);
process.exit(1);
return;
}
console.log(stats.toString(outputOptions));
fs.writeFileSync(root('./.webpackStats.json'), JSON.stringify(stats.toJson(), null, 2));
if (!watch && stats.hasErrors()) process.exitCode = 1;
}
if (watch) compiler.watch({}, compilerCallback);
else compiler.run(compilerCallback);
}
+18
View File
@@ -0,0 +1,18 @@
/* eslint-disable */
import _ from 'lodash';
export default function mapWebpackUrlPrefix(mapList) {
const rules = mapList.map((mappingRule) => {
const regex = mappingRule.prefix.split('/').map(s => _.escapeRegExp(s)).join('[\\/\\\\]');
return {
from: new RegExp(`^${regex}`, mappingRule.flag),
to: mappingRule.replace,
};
});
return function mapUrl(url) {
rules.forEach((rule) => {
url = url.replace(rule.from, rule.to);
});
return url;
};
}
+6
View File
@@ -0,0 +1,6 @@
/* eslint-disable */
import path from 'path';
export default function root(fn = '.') {
return path.resolve(__dirname, '../../', fn);
}
+208
View File
@@ -0,0 +1,208 @@
{
"name": "vj4",
"version": "4.0.0",
"author": "Breezewish",
"private": true,
"license": "AGPL-1.0",
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.4.4",
"autoprefixer": "^9.5.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.6",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-prismjs": "^1.0.2",
"chalk": "^2.4.2",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^0.28.11",
"del": "^4.1.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-import-resolver-webpack": "^0.11.1",
"eslint-loader": "^2.1.2",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.13.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^2.0.0",
"friendly-errors-webpack-plugin": "^1.7.0",
"fs-extra": "^8.0.1",
"gulp": "^4.0.2",
"gulp-cli": "^2.2.0",
"gulp-iconfont": "^10.0.2",
"gulp-if": "^2.0.2",
"gulp-nunjucks": "^4.0.0",
"gulp-plumber": "^1.2.1",
"gulp-svgmin": "^2.2.0",
"imports-loader": "^0.8.0",
"js-yaml": "^3.13.1",
"json-loader": "^0.5.7",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"postcss-loader": "^3.0.0",
"rupture": "^0.7.1",
"style-loader": "^0.23.1",
"stylus": "^0.54.5",
"stylus-loader": "^3.0.2",
"through2": "^3.0.1",
"uglifyjs-webpack-plugin": "^1.3.0",
"vinyl-buffer": "^1.0.1",
"webpack": "^3.12.0",
"yargs": "^13.2.4"
},
"dependencies": {
"@babel/runtime-corejs2": "^7.0.0",
"base-64": "^0.1.0",
"classnames": "^2.2.6",
"clipboard": "^2.0.4",
"codemirror": "^5.46.0",
"diff-dom": "^4.1.3",
"emojify.js": "^1.1.0",
"fancy-log": "^1.3.3",
"jquery": "^3.2.1",
"jquery-scroll-lock": "^3.1.3",
"jquery.easing": "^1.4.1",
"jquery.transit": "^0.9.12",
"katex": "^0.10.2",
"lodash": "^4.17.13",
"moment": "^2.24.0",
"normalize.css": "^8.0.1",
"nprogress": "^0.2.0",
"pickadate": "^3.6.3",
"plugin-error": "^1.0.1",
"prismjs": "^1.16.0",
"prop-types": "^15.7.2",
"rc-tabs": "^9.6.3",
"react": "^15.6.1",
"react-codemirror": "^1.0.0",
"react-dom": "^15.6.1",
"react-redux": "^5.0.6",
"react-split-pane": "^0.1.65",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-promise-middleware": "^4.3.0",
"redux-thunk": "^2.2.0",
"slideout": "^1.0.1",
"sockjs-client": "^1.3.0",
"sticky-kit": "^1.1.3",
"tether": "^1.4.6",
"tether-drop": "^1.4.2",
"timeago-react": "^1.2.2",
"timeago.js": "^3.0.2",
"uuid": "^3.3.2",
"vj-simplemde": "0.0.8"
},
"scripts": {
"build": "node build",
"build:production": "node build --production",
"build:watch": "node build --watch",
"lint": "eslint --fix ."
},
"babel": {
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
],
"@babel/plugin-proposal-json-strings",
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions"
],
"presets": [
[
"@babel/preset-env",
{
"loose": true
}
]
]
},
"babelForProject": {
"plugins": [
"lodash",
"@babel/plugin-transform-runtime",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
[
"prismjs",
{
"languages": [
"clike",
"c",
"cpp",
"pascal",
"java",
"python",
"java",
"python",
"php",
"rust",
"haskell",
"javascript",
"go",
"ruby",
"csharp"
],
"plugins": [
"toolbar",
"line-numbers"
],
"css": true
}
]
],
"presets": [
[
"@babel/preset-env",
{
"loose": true,
"modules": false
}
],
"@babel/preset-react"
]
}
}
+9691
View File
File diff suppressed because it is too large. Load diff