Skip to content

Commit

Permalink
Chore: remove fs-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Oct 22, 2023
1 parent afb954e commit 57a306c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
7 changes: 5 additions & 2 deletions Build/build-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const listDir = require('@sukka/listdir');
const path = require('path');
const fs = require('fs');
const fsp = require('fs/promises');
const { copy } = require('fs-extra');
const { task } = require('./lib/trace-runner');

const rootPath = path.resolve(__dirname, '../');
Expand All @@ -19,7 +18,11 @@ const folderAndFilesToBeDeployed = [

const buildPublicHtml = task(__filename, async () => {
await fsp.mkdir(publicPath, { recursive: true });
await Promise.all(folderAndFilesToBeDeployed.map(dir => copy(path.resolve(rootPath, dir), path.resolve(publicPath, dir))));
await Promise.all(folderAndFilesToBeDeployed.map(dir => fsp.cp(
path.resolve(rootPath, dir),
path.resolve(publicPath, dir),
{ force: true, recursive: true }
)));

const list = await listDir(publicPath, {
ignoreHidden: true,
Expand Down
22 changes: 13 additions & 9 deletions Build/build-reject-domainset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
const { copy } = require('fs-extra');
const { resolve: pathResolve } = require('path');
const fsp = require('fs/promises');
const path = require('path');

const { processHosts, processFilterRules } = require('./lib/parse-filter');
const createTrie = require('./lib/trie');
Expand Down Expand Up @@ -97,7 +97,7 @@ const buildRejectDomainSet = task(__filename, async () => {
let previousSize = domainSets.size;
console.log(`Import ${previousSize} rules from Hosts / AdBlock Filter Rules!`);

for await (const line of readFileByLine(pathResolve(__dirname, '../Source/domainset/reject_sukka.conf'))) {
for await (const line of readFileByLine(path.resolve(__dirname, '../Source/domainset/reject_sukka.conf'))) {
const l = processLine(line);
if (l) {
domainSets.add(l);
Expand All @@ -107,7 +107,7 @@ const buildRejectDomainSet = task(__filename, async () => {
previousSize = domainSets.size - previousSize;
console.log(`Import ${previousSize} rules from reject_sukka.conf!`);

for await (const line of readFileByLine(pathResolve(__dirname, '../Source/non_ip/reject.conf'))) {
for await (const line of readFileByLine(path.resolve(__dirname, '../Source/non_ip/reject.conf'))) {
if (line.startsWith('DOMAIN-KEYWORD')) {
const [, ...keywords] = line.split(',');
domainKeywordsSet.add(keywords.join(',').trim());
Expand All @@ -117,7 +117,7 @@ const buildRejectDomainSet = task(__filename, async () => {
}
}

for await (const line of readFileByLine(pathResolve(__dirname, '../List/domainset/reject_phishing.conf'))) {
for await (const line of readFileByLine(path.resolve(__dirname, '../List/domainset/reject_phishing.conf'))) {
const l = processLine(line);
if (l && l[0] === '.') {
domainSuffixSet.add(l.slice(1));
Expand Down Expand Up @@ -217,15 +217,19 @@ const buildRejectDomainSet = task(__filename, async () => {
new Date(),
domainset,
'domainset',
pathResolve(__dirname, '../List/domainset/reject.conf'),
pathResolve(__dirname, '../Clash/domainset/reject.txt')
path.resolve(__dirname, '../List/domainset/reject.conf'),
path.resolve(__dirname, '../Clash/domainset/reject.txt')
),
compareAndWriteFile(
rejectDomainsStats.map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`),
pathResolve(__dirname, '../List/internal/reject-stats.txt')
path.resolve(__dirname, '../List/internal/reject-stats.txt')
),
// Copy reject_sukka.conf for backward compatibility
copy(pathResolve(__dirname, '../Source/domainset/reject_sukka.conf'), pathResolve(__dirname, '../List/domainset/reject_sukka.conf'))
fsp.cp(
path.resolve(__dirname, '../Source/domainset/reject_sukka.conf'),
path.resolve(__dirname, '../List/domainset/reject_sukka.conf'),
{ force: true, recursive: true }
)
]);
});

Expand Down
7 changes: 3 additions & 4 deletions Build/download-previous-build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const { fetch } = require('undici');
const tar = require('tar');
const fs = require('fs');
const fsp = fs.promises;
const { copy } = require('fs-extra');
const fsp = require('fs/promises');
const path = require('path');
const { tmpdir } = require('os');
const { Readable } = require('stream');
Expand Down Expand Up @@ -72,10 +71,10 @@ const downloadPreviousBuild = task(__filename, async () => {
await Promise.all(filesList.map(async p => {
const src = path.join(extractedPath, 'ruleset.skk.moe-master', p);
if (await fileExists(src)) {
return copy(
return fsp.cp(
src,
path.join(__dirname, '..', p),
{ overwrite: true }
{ force: true, recursive: true }
);
}
}));
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"ci-info": "^3.9.0",
"cidr-tools-wasm": "^0.0.11",
"eslint": "^8.51.0",
"fs-extra": "^11.1.1",
"gorhill-publicsuffixlist": "github:gorhill/publicsuffixlist.js",
"jest-worker": "^29.7.0",
"mnemonist": "^0.39.5",
Expand Down
25 changes: 0 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57a306c

Please sign in to comment.