🎨 Unified code style
This commit is contained in:
5
bin/utils/dir.ts
vendored
5
bin/utils/dir.ts
vendored
@@ -5,7 +5,4 @@ import { fileURLToPath } from 'url';
|
||||
const currentModulePath = fileURLToPath(import.meta.url);
|
||||
|
||||
// Resolve the parent directory of the current module
|
||||
export const npmDirectory = path.join(
|
||||
path.dirname(currentModulePath),
|
||||
'..'
|
||||
);
|
||||
export const npmDirectory = path.join(path.dirname(currentModulePath), '..');
|
||||
|
||||
30
bin/utils/info.ts
vendored
30
bin/utils/info.ts
vendored
@@ -1,14 +1,11 @@
|
||||
import crypto from 'crypto';
|
||||
import prompts from "prompts";
|
||||
import ora from "ora";
|
||||
import prompts from 'prompts';
|
||||
import ora from 'ora';
|
||||
import chalk from 'chalk';
|
||||
|
||||
// Generates an identifier based on the given URL.
|
||||
export function getIdentifier(url: string) {
|
||||
const postFixHash = crypto.createHash('md5')
|
||||
.update(url)
|
||||
.digest('hex')
|
||||
.substring(0, 6);
|
||||
const postFixHash = crypto.createHash('md5').update(url).digest('hex').substring(0, 6);
|
||||
return `pake-${postFixHash}`;
|
||||
}
|
||||
|
||||
@@ -28,17 +25,12 @@ export function capitalizeFirstLetter(string: string) {
|
||||
|
||||
export function getSpinner(text: string) {
|
||||
const loadingType = {
|
||||
"interval": 80,
|
||||
"frames": [
|
||||
"✦",
|
||||
"✶",
|
||||
"✺",
|
||||
"✵",
|
||||
"✸",
|
||||
"✴︎",
|
||||
"✹",
|
||||
"✺",
|
||||
]
|
||||
}
|
||||
return ora({ text: `${chalk.blue(text)}\n`, spinner: loadingType, color: 'blue' }).start();
|
||||
interval: 80,
|
||||
frames: ['✦', '✶', '✺', '✵', '✸', '✹', '✺'],
|
||||
};
|
||||
return ora({
|
||||
text: `${chalk.cyan(text)}\n`,
|
||||
spinner: loadingType,
|
||||
color: 'cyan',
|
||||
}).start();
|
||||
}
|
||||
|
||||
5
bin/utils/ip.ts
vendored
5
bin/utils/ip.ts
vendored
@@ -13,13 +13,13 @@ const ping = async (host: string) => {
|
||||
|
||||
// Prevent timeouts from affecting user experience.
|
||||
const requestPromise = new Promise<number>((resolve, reject) => {
|
||||
const req = http.get(`http://${ip.address}`, (res) => {
|
||||
const req = http.get(`http://${ip.address}`, res => {
|
||||
const delay = new Date().getTime() - start.getTime();
|
||||
res.resume();
|
||||
resolve(delay);
|
||||
});
|
||||
|
||||
req.on('error', (err) => {
|
||||
req.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
@@ -33,7 +33,6 @@ const ping = async (host: string) => {
|
||||
return Promise.race([requestPromise, timeoutPromise]);
|
||||
};
|
||||
|
||||
|
||||
async function isChinaDomain(domain: string): Promise<boolean> {
|
||||
try {
|
||||
const [ip] = await resolve(domain);
|
||||
|
||||
6
bin/utils/shell.ts
vendored
6
bin/utils/shell.ts
vendored
@@ -1,9 +1,9 @@
|
||||
import shelljs from "shelljs";
|
||||
import { npmDirectory } from "./dir";
|
||||
import shelljs from 'shelljs';
|
||||
import { npmDirectory } from './dir';
|
||||
|
||||
export function shellExec(command: string) {
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, (code) => {
|
||||
shelljs.exec(command, { async: true, silent: false, cwd: npmDirectory }, code => {
|
||||
if (code === 0) {
|
||||
resolve(0);
|
||||
} else {
|
||||
|
||||
3
bin/utils/url.ts
vendored
3
bin/utils/url.ts
vendored
@@ -9,7 +9,7 @@ export function getDomain(inputUrl: string): string | null {
|
||||
const parsed = psl.parse(url.hostname);
|
||||
|
||||
// If domain is available, split it and return the SLD.
|
||||
if ("domain" in parsed && parsed.domain) {
|
||||
if ('domain' in parsed && parsed.domain) {
|
||||
return parsed.domain.split('.')[0];
|
||||
} else {
|
||||
return null;
|
||||
@@ -19,7 +19,6 @@ export function getDomain(inputUrl: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Appends 'https://' protocol to the URL if not present.
|
||||
export function appendProtocol(inputUrl: string): string {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user