Skip to content

Commit

Permalink
refactor: rewrite the project code (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese authored Aug 10, 2023
1 parent efa5202 commit 43e4578
Show file tree
Hide file tree
Showing 20 changed files with 666 additions and 456 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"homepage": "https://github.com/LoveCouple/serein#readme",
"dependencies": {
"axios": "^1.4.0",
"chalk": "^5.3.0",
"commander": "^11.0.0",
"del": "^7.0.0",
Expand Down
44 changes: 43 additions & 1 deletion src/base/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ const SERVER_ADMIN = '@minecraft/server-admin';
const SERVER_GAMETEST = '@minecraft/server-gametest';
const SERVER_NET = '@minecraft/server-net';
const SERVER_EDITOR = '@minecraft/server-editor';
const VANILLA_DATA = '@minecraft/vanilla-data';
const DATA = [VANILLA_DATA];
const ALL = [
SERVER,
SERVER_UI,
SERVER_ADMIN,
SERVER_GAMETEST,
SERVER_NET,
SERVER_EDITOR,
VANILLA_DATA
];
// === END NPM PACKAGES

// === NPM MIRRORS
Expand All @@ -27,6 +38,32 @@ const DefaultCode =
const GULPFILE = 'https://serein.meowshe.com/gulpfile.js';
// === END GULPFILE URL

// === DEFUALT TSCONFIG
const TSCONFIG = {
compilerOptions: {
target: 'es2020',
module: 'es2020',
noLib: false,
emitDecoratorMetadata: true,
experimentalDecorators: true,
pretty: true,
allowUnreachableCode: true,
allowUnusedLabels: true,
noImplicitAny: true,
rootDir: '.',
listFiles: false,
noEmitHelpers: true
},
include: [],
compileOnSave: false
};
// === END DEFAULT tsconfig

// === DEFAULT MCATTRIBUTES
const MCATTRIBUTES =
'diagnostic.disable.minecraft.manifest.module.missing=true';
// === END DEFAULT MCATTRIBUTES

export {
CLI_VERSION,
SERVER,
Expand All @@ -35,7 +72,12 @@ export {
SERVER_GAMETEST,
SERVER_NET,
SERVER_EDITOR,
VANILLA_DATA,
DATA,
ALL,
Mirrors,
DefaultCode,
GULPFILE
GULPFILE,
TSCONFIG,
MCATTRIBUTES
};
56 changes: 32 additions & 24 deletions src/base/inquirer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ import inquirer from 'inquirer';
import { basename } from 'path';
import NetWork from '../handlers/network.js';
import { magenta, warning } from './console.js';
import {
SERVER,
SERVER_UI,
SERVER_ADMIN,
SERVER_GAMETEST,
SERVER_NET,
SERVER_EDITOR
} from './constants.js';
import { DATA } from './constants.js';

async function askBase(str, options) {
const { answer } = await inquirer.prompt([
Expand Down Expand Up @@ -62,23 +55,36 @@ async function promptUser(message, choices) {
return selected;
}

async function askVersion(packageName) {
const versions = await NetWork.getNpmPackageVersions(packageName);
const keys = Object.keys(versions).sort().reverse();
async function askVersion(packageName, isData = false) {
const versions = await NetWork.getNpmPackageVersions(packageName, isData);
if (isData) {
const npm = await promptUser(
`Select your ${magenta(packageName)} version in manifest`,
versions
);

const api = await promptUser(
`Select your ${magenta(packageName)} version in manifest`,
keys
);
const npm = await promptUser(
`Select your ${magenta(packageName)} version in npm`,
versions[api].sort().reverse()
);
return {
npm,
isData: true
};
} else {
const keys = Object.keys(versions).sort().reverse();

return {
api,
npm
};
const api = await promptUser(
`Select your ${magenta(packageName)} version in manifest`,
keys
);
const npm = await promptUser(
`Select your ${magenta(packageName)} version in npm`,
versions[api].sort().reverse()
);

return {
api,
npm,
isData: false
};
}
}

async function getDeps(versions, msg) {
Expand All @@ -93,7 +99,9 @@ async function getDeps(versions, msg) {
]);
const packageVersions = {};
for (const packageName of deps) {
packageVersions[packageName] = await askVersion(packageName);
if (DATA.includes(packageName))
packageVersions[packageName] = await askVersion(packageName, true);
else packageVersions[packageName] = await askVersion(packageName);
}
return packageVersions;
}
Expand Down
10 changes: 7 additions & 3 deletions src/base/io.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { done } from './console.js';
import { execSync } from 'child_process';
import { writeFileSync, existsSync, mkdirSync } from 'fs';
import { writeFileSync, existsSync, mkdirSync, readFileSync } from 'fs';

async function mkdir(dirs) {
function mkdir(dirs) {
for (const x of dirs) {
if (!existsSync(x)) {
mkdirSync(x);
Expand All @@ -21,9 +21,13 @@ function writeJSON(filename, obj) {
done('Create ' + filename);
}

function readJSON(filename) {
return JSON.parse(readFileSync(filename, 'utf-8'));
}

function exec(command, withLog = true) {
if (withLog) execSync(command, { stdio: [0, 1, 2] });
else execSync(command, { stdio: 'ignore' });
}

export { mkdir, writeText, writeJSON, exec };
export { mkdir, writeText, writeJSON, readJSON, exec };
26 changes: 0 additions & 26 deletions src/base/network.js

This file was deleted.

Loading

0 comments on commit 43e4578

Please sign in to comment.