Skip to content

Commit

Permalink
build: Split sub-store.min.js for better performance on iOS devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng-YM committed Sep 9, 2022
1 parent 1c29771 commit 6ee6a9b
Show file tree
Hide file tree
Showing 17 changed files with 673 additions and 513 deletions.
6 changes: 3 additions & 3 deletions backend/dist/cron-sync-artifacts.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions backend/dist/sub-store-0.min.js

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions backend/dist/sub-store-1.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions backend/dist/sub-store-parser.loon.min.js

Large diffs are not rendered by default.

81 changes: 53 additions & 28 deletions backend/gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import tap from 'gulp-tap';
import pkg from './package.json';

export function peggy() {
return gulp.src('src/**/*.peg')
.pipe(tap(function (file) {
const filename = path.basename(file.path).split(".")[0] + ".js";
return gulp.src('src/**/*.peg').pipe(
tap(function (file) {
const filename = path.basename(file.path).split('.')[0] + '.js';
const raw = fs.readFileSync(file.path, 'utf8');
const contents =
`import * as peggy from 'peggy';
const contents = `import * as peggy from 'peggy';
const grammars = String.raw\`\n${raw}\n\`;
let parser;
export default function getParser() {
Expand All @@ -25,15 +24,17 @@ export default function getParser() {
}
return parser;
}\n`;
return newFile(filename, contents)
.pipe(gulp.dest(path.dirname(file.path)))
}));
return newFile(filename, contents).pipe(
gulp.dest(path.dirname(file.path)),
);
}),
);
}

export function lint() {
return gulp
.src('src/**/*.js')
.pipe(eslint({fix: true}))
.pipe(eslint({ fix: true }))
.pipe(eslint.fix())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
Expand All @@ -42,9 +43,14 @@ export function lint() {
export function styles() {
return gulp
.src('src/**/*.js')
.pipe(prettier({
singleQuote: true, trailingComma: 'all', tabWidth: 4, bracketSpacing: true
}))
.pipe(
prettier({
singleQuote: true,
trailingComma: 'all',
tabWidth: 4,
bracketSpacing: true,
}),
)
.pipe(gulp.dest((file) => file.base));
}

Expand All @@ -59,13 +65,13 @@ function scripts(src, dest) {
{
paths: [
{
'rootPathPrefix': '@',
'rootPathSuffix': 'src',
}
]
}
]
]
rootPathPrefix: '@',
rootPathSuffix: 'src',
},
],
},
],
],
})
.plugin('tinyify')
.bundle()
Expand All @@ -74,20 +80,39 @@ function scripts(src, dest) {
}

function banner(dest) {
return () => gulp
.src(dest)
.pipe(header(fs.readFileSync('./banner', 'utf-8'), {pkg, updated: new Date().toLocaleString('zh-CN')}))
.pipe(gulp.dest((file) => file.base));
return () =>
gulp
.src(dest)
.pipe(
header(fs.readFileSync('./banner', 'utf-8'), {
pkg,
updated: new Date().toLocaleString('zh-CN'),
}),
)
.pipe(gulp.dest((file) => file.base));
}

const artifacts = [
{src: 'src/main.js', dest: 'sub-store.min.js'},
{src: 'src/products/resource-parser.loon.js', dest: 'dist/sub-store-parser.loon.min.js'},
{src: 'src/products/cron-sync-artifacts.js', dest: 'dist/cron-sync-artifacts.min.js'}
{ src: 'src/main.js', dest: 'sub-store.min.js' },
{
src: 'src/products/resource-parser.loon.js',
dest: 'dist/sub-store-parser.loon.min.js',
},
{
src: 'src/products/cron-sync-artifacts.js',
dest: 'dist/cron-sync-artifacts.min.js',
},
{ src: 'src/products/sub-store-0.js', dest: 'dist/sub-store-0.min.js' },
{ src: 'src/products/sub-store-1.js', dest: 'dist/sub-store-1.min.js' },
];

export const build = gulp.series(gulp.parallel(artifacts.map(artifact => scripts(artifact.src, artifact.dest))), gulp.parallel(artifacts.map(artifact => banner(artifact.dest))));
export const build = gulp.series(
gulp.parallel(
artifacts.map((artifact) => scripts(artifact.src, artifact.dest)),
),
gulp.parallel(artifacts.map((artifact) => banner(artifact.dest))),
);

const all = gulp.series(peggy, lint, styles, build)
const all = gulp.series(peggy, lint, styles, build);

export default all;
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.12.9",
"version": "2.13.0",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/products/cron-sync-artifacts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { syncToGist, produceArtifact } from '@/restful/artifacts';
import { version } from '../../package.json';
import { SETTINGS_KEY, ARTIFACTS_KEY } from '@/constants';
import $ from '@/core/app';
import { produceArtifact } from '@/restful/sync';
import { syncToGist } from '@/restful/artifacts';

!(async function () {
const settings = $.read(SETTINGS_KEY);
Expand Down
39 changes: 39 additions & 0 deletions backend/src/products/sub-store-0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 路由拆分 - 本文件只包含不涉及到解析器的 RESTFul API
*/

import { version } from '../../package.json';
console.log(
`
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
Sub-Store -- v${version}
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
`,
);

import migrate from '@/utils/migration';
import express from '@/vendor/express';
import $ from '@/core/app';
import registerCollectionRoutes from '@/restful/collections';
import registerSubscriptionRoutes from '@/restful/subscriptions';
import registerArtifactRoutes from '@/restful/artifacts';
import registerSettingRoutes from '@/restful/settings';
import registerMiscRoutes from '@/restful/miscs';
import registerSortRoutes from '@/restful/sort';

migrate();
serve();

function serve() {
const $app = express({ substore: $ });

// register routes
registerCollectionRoutes($app);
registerSubscriptionRoutes($app);
registerArtifactRoutes($app);
registerSettingRoutes($app);
registerSortRoutes($app);
registerMiscRoutes($app);

$app.start();
}
39 changes: 39 additions & 0 deletions backend/src/products/sub-store-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 路由拆分 - 本文件仅包含使用到解析器的 RESTFul API
*/

import { version } from '../../package.json';
import migrate from '@/utils/migration';
import express from '@/vendor/express';
import $ from '@/core/app';
import registerDownloadRoutes from '@/restful/download';
import registerPreviewRoutes from '@/restful/preview';
import registerSyncRoutes from '@/restful/sync';
import registerNodeInfoRoutes from '@/restful/node-info';

console.log(
`
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
Sub-Store -- v${version}
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
`,
);

migrate();
serve();

function serve() {
const $app = express({ substore: $ });

// register routes
registerDownloadRoutes($app);
registerPreviewRoutes($app);
registerSyncRoutes($app);
registerNodeInfoRoutes($app);

$app.options('/', (req, res) => {
res.status(200).end();
});

$app.start();
}
Loading

0 comments on commit 6ee6a9b

Please sign in to comment.