Skip to content

Commit 6ee6a9b

Browse files
committed
build: Split sub-store.min.js for better performance on iOS devices
1 parent 1c29771 commit 6ee6a9b

17 files changed

+673
-513
lines changed

backend/dist/cron-sync-artifacts.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/dist/sub-store-0.min.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/dist/sub-store-1.min.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/dist/sub-store-parser.loon.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/gulpfile.babel.js

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import tap from 'gulp-tap';
1111
import pkg from './package.json';
1212

1313
export function peggy() {
14-
return gulp.src('src/**/*.peg')
15-
.pipe(tap(function (file) {
16-
const filename = path.basename(file.path).split(".")[0] + ".js";
14+
return gulp.src('src/**/*.peg').pipe(
15+
tap(function (file) {
16+
const filename = path.basename(file.path).split('.')[0] + '.js';
1717
const raw = fs.readFileSync(file.path, 'utf8');
18-
const contents =
19-
`import * as peggy from 'peggy';
18+
const contents = `import * as peggy from 'peggy';
2019
const grammars = String.raw\`\n${raw}\n\`;
2120
let parser;
2221
export default function getParser() {
@@ -25,15 +24,17 @@ export default function getParser() {
2524
}
2625
return parser;
2726
}\n`;
28-
return newFile(filename, contents)
29-
.pipe(gulp.dest(path.dirname(file.path)))
30-
}));
27+
return newFile(filename, contents).pipe(
28+
gulp.dest(path.dirname(file.path)),
29+
);
30+
}),
31+
);
3132
}
3233

3334
export function lint() {
3435
return gulp
3536
.src('src/**/*.js')
36-
.pipe(eslint({fix: true}))
37+
.pipe(eslint({ fix: true }))
3738
.pipe(eslint.fix())
3839
.pipe(eslint.format())
3940
.pipe(eslint.failAfterError());
@@ -42,9 +43,14 @@ export function lint() {
4243
export function styles() {
4344
return gulp
4445
.src('src/**/*.js')
45-
.pipe(prettier({
46-
singleQuote: true, trailingComma: 'all', tabWidth: 4, bracketSpacing: true
47-
}))
46+
.pipe(
47+
prettier({
48+
singleQuote: true,
49+
trailingComma: 'all',
50+
tabWidth: 4,
51+
bracketSpacing: true,
52+
}),
53+
)
4854
.pipe(gulp.dest((file) => file.base));
4955
}
5056

@@ -59,13 +65,13 @@ function scripts(src, dest) {
5965
{
6066
paths: [
6167
{
62-
'rootPathPrefix': '@',
63-
'rootPathSuffix': 'src',
64-
}
65-
]
66-
}
67-
]
68-
]
68+
rootPathPrefix: '@',
69+
rootPathSuffix: 'src',
70+
},
71+
],
72+
},
73+
],
74+
],
6975
})
7076
.plugin('tinyify')
7177
.bundle()
@@ -74,20 +80,39 @@ function scripts(src, dest) {
7480
}
7581

7682
function banner(dest) {
77-
return () => gulp
78-
.src(dest)
79-
.pipe(header(fs.readFileSync('./banner', 'utf-8'), {pkg, updated: new Date().toLocaleString('zh-CN')}))
80-
.pipe(gulp.dest((file) => file.base));
83+
return () =>
84+
gulp
85+
.src(dest)
86+
.pipe(
87+
header(fs.readFileSync('./banner', 'utf-8'), {
88+
pkg,
89+
updated: new Date().toLocaleString('zh-CN'),
90+
}),
91+
)
92+
.pipe(gulp.dest((file) => file.base));
8193
}
8294

8395
const artifacts = [
84-
{src: 'src/main.js', dest: 'sub-store.min.js'},
85-
{src: 'src/products/resource-parser.loon.js', dest: 'dist/sub-store-parser.loon.min.js'},
86-
{src: 'src/products/cron-sync-artifacts.js', dest: 'dist/cron-sync-artifacts.min.js'}
96+
{ src: 'src/main.js', dest: 'sub-store.min.js' },
97+
{
98+
src: 'src/products/resource-parser.loon.js',
99+
dest: 'dist/sub-store-parser.loon.min.js',
100+
},
101+
{
102+
src: 'src/products/cron-sync-artifacts.js',
103+
dest: 'dist/cron-sync-artifacts.min.js',
104+
},
105+
{ src: 'src/products/sub-store-0.js', dest: 'dist/sub-store-0.min.js' },
106+
{ src: 'src/products/sub-store-1.js', dest: 'dist/sub-store-1.min.js' },
87107
];
88108

89-
export const build = gulp.series(gulp.parallel(artifacts.map(artifact => scripts(artifact.src, artifact.dest))), gulp.parallel(artifacts.map(artifact => banner(artifact.dest))));
109+
export const build = gulp.series(
110+
gulp.parallel(
111+
artifacts.map((artifact) => scripts(artifact.src, artifact.dest)),
112+
),
113+
gulp.parallel(artifacts.map((artifact) => banner(artifact.dest))),
114+
);
90115

91-
const all = gulp.series(peggy, lint, styles, build)
116+
const all = gulp.series(peggy, lint, styles, build);
92117

93118
export default all;

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.12.9",
3+
"version": "2.13.0",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/products/cron-sync-artifacts.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { syncToGist, produceArtifact } from '@/restful/artifacts';
21
import { version } from '../../package.json';
32
import { SETTINGS_KEY, ARTIFACTS_KEY } from '@/constants';
43
import $ from '@/core/app';
4+
import { produceArtifact } from '@/restful/sync';
5+
import { syncToGist } from '@/restful/artifacts';
56

67
!(async function () {
78
const settings = $.read(SETTINGS_KEY);

backend/src/products/sub-store-0.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 路由拆分 - 本文件只包含不涉及到解析器的 RESTFul API
3+
*/
4+
5+
import { version } from '../../package.json';
6+
console.log(
7+
`
8+
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
9+
Sub-Store -- v${version}
10+
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
11+
`,
12+
);
13+
14+
import migrate from '@/utils/migration';
15+
import express from '@/vendor/express';
16+
import $ from '@/core/app';
17+
import registerCollectionRoutes from '@/restful/collections';
18+
import registerSubscriptionRoutes from '@/restful/subscriptions';
19+
import registerArtifactRoutes from '@/restful/artifacts';
20+
import registerSettingRoutes from '@/restful/settings';
21+
import registerMiscRoutes from '@/restful/miscs';
22+
import registerSortRoutes from '@/restful/sort';
23+
24+
migrate();
25+
serve();
26+
27+
function serve() {
28+
const $app = express({ substore: $ });
29+
30+
// register routes
31+
registerCollectionRoutes($app);
32+
registerSubscriptionRoutes($app);
33+
registerArtifactRoutes($app);
34+
registerSettingRoutes($app);
35+
registerSortRoutes($app);
36+
registerMiscRoutes($app);
37+
38+
$app.start();
39+
}

backend/src/products/sub-store-1.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* 路由拆分 - 本文件仅包含使用到解析器的 RESTFul API
3+
*/
4+
5+
import { version } from '../../package.json';
6+
import migrate from '@/utils/migration';
7+
import express from '@/vendor/express';
8+
import $ from '@/core/app';
9+
import registerDownloadRoutes from '@/restful/download';
10+
import registerPreviewRoutes from '@/restful/preview';
11+
import registerSyncRoutes from '@/restful/sync';
12+
import registerNodeInfoRoutes from '@/restful/node-info';
13+
14+
console.log(
15+
`
16+
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
17+
Sub-Store -- v${version}
18+
┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
19+
`,
20+
);
21+
22+
migrate();
23+
serve();
24+
25+
function serve() {
26+
const $app = express({ substore: $ });
27+
28+
// register routes
29+
registerDownloadRoutes($app);
30+
registerPreviewRoutes($app);
31+
registerSyncRoutes($app);
32+
registerNodeInfoRoutes($app);
33+
34+
$app.options('/', (req, res) => {
35+
res.status(200).end();
36+
});
37+
38+
$app.start();
39+
}

0 commit comments

Comments
 (0)