mirror of
https://github.com/PreMiD/PreMiD.git
synced 2026-04-06 04:41:58 +02:00
♻️ Refactoring
This commit is contained in:
112
devMode.ts
112
devMode.ts
@@ -1,112 +0,0 @@
|
||||
import * as ts from "typescript";
|
||||
import chalk = require("chalk");
|
||||
import { ChildProcess, spawn } from "child_process";
|
||||
import { removeSync, writeFileSync, copySync } from "fs-extra";
|
||||
import { extname } from "path";
|
||||
import * as glob from "fast-glob";
|
||||
|
||||
//* Current child process = null
|
||||
var currChild: ChildProcess = null;
|
||||
|
||||
//* Format Host
|
||||
const formatHost: ts.FormatDiagnosticsHost = {
|
||||
getCanonicalFileName: path => path,
|
||||
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
||||
getNewLine: () => ts.sys.newLine
|
||||
};
|
||||
|
||||
//* Create ts program
|
||||
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
|
||||
|
||||
//* Create Watch compoile host
|
||||
const host = ts.createWatchCompilerHost(
|
||||
"./tsconfig.json",
|
||||
{},
|
||||
ts.sys,
|
||||
createProgram,
|
||||
null,
|
||||
fileChange
|
||||
);
|
||||
|
||||
if (process.argv.length == 3 && process.argv[2] == "compile")
|
||||
prepareDist().then(() => process.exit());
|
||||
//* Create watch program
|
||||
else ts.createWatchProgram(host);
|
||||
|
||||
async function fileChange(diagnostic: ts.Diagnostic) {
|
||||
//* TS compilation != done
|
||||
if (diagnostic.code !== 6194) {
|
||||
//* If error
|
||||
if ([6031, 6032].includes(diagnostic.code))
|
||||
console.log(
|
||||
chalk.blueBright(ts.formatDiagnostic(diagnostic, formatHost))
|
||||
);
|
||||
else
|
||||
console.log(chalk.redBright(ts.formatDiagnostic(diagnostic, formatHost)));
|
||||
return;
|
||||
} else
|
||||
console.log(chalk.greenBright(ts.formatDiagnostic(diagnostic, formatHost)));
|
||||
|
||||
console.log(currChild && currChild.killed);
|
||||
//* Kill old child if exists && alive
|
||||
if (currChild && !currChild.killed) currChild.kill();
|
||||
|
||||
//* Run devMode script
|
||||
prepareDist();
|
||||
|
||||
//* Clear console
|
||||
console.clear();
|
||||
|
||||
//* Run child
|
||||
currChild = spawn("yarn start", {
|
||||
shell: true,
|
||||
stdio: "inherit"
|
||||
});
|
||||
}
|
||||
|
||||
//* Prepare dist folder
|
||||
async function prepareDist() {
|
||||
//* Select files
|
||||
var dist = await glob("dist/app/**/*", { onlyFiles: true }),
|
||||
src = await glob("src/**/*", { onlyFiles: true });
|
||||
|
||||
//* Filter file differences
|
||||
var nDist = dist.map(f => [f.replace("dist/app/", ""), f]);
|
||||
src = src
|
||||
.map(f => f.replace("src/", "").split(".")[0])
|
||||
.filter(sf => nDist.find(d => d[0].split(".")[0] == sf));
|
||||
|
||||
//* Old files, delete
|
||||
Promise.all(
|
||||
dist
|
||||
.filter(f => !src.includes(f.replace("dist/app/", "").split(".")[0]))
|
||||
.map(f => removeSync(f))
|
||||
);
|
||||
|
||||
//* Copy package.json (minified)
|
||||
var packageJSON = require("./package.json"),
|
||||
srcPackageJSON = packageJSON;
|
||||
|
||||
//* Delete scripts, not needed
|
||||
delete srcPackageJSON.scripts;
|
||||
|
||||
//* only electron as devDependency
|
||||
srcPackageJSON.devDependencies = {
|
||||
electron: packageJSON.devDependencies.electron
|
||||
};
|
||||
|
||||
//* Write file
|
||||
await writeFileSync(
|
||||
"./src/package.json",
|
||||
JSON.stringify(srcPackageJSON, null, 2)
|
||||
);
|
||||
|
||||
//* Copy files from src to dist
|
||||
copySync("src", "dist/app", {
|
||||
filter: function(path) {
|
||||
if (path.includes("node_modules")) return false;
|
||||
return extname(path) !== ".ts";
|
||||
console.log(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "premid",
|
||||
"productName": "PreMiD",
|
||||
"description": "Discord Rich Presence for websites.",
|
||||
"version": "1.0.0",
|
||||
"version": "2.0.5",
|
||||
"repository": "https://github.com/PreMiD/PreMiD",
|
||||
"scripts": {
|
||||
"init": "tsc && tsc pkg && devScript --copyOnly",
|
||||
|
||||
@@ -8,10 +8,5 @@
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": [
|
||||
"devMode.ts",
|
||||
"pkg.ts",
|
||||
"installer_assets/builder.ts",
|
||||
".github/deploy.ts"
|
||||
]
|
||||
"exclude": ["pkg.ts", "installer_assets/builder.ts", ".github/deploy.ts"]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { parse, stringify } from "ini";
|
||||
import { ensureDirSync } from "fs-extra";
|
||||
|
||||
let file = readFileSync("installer_assets/installer.xml", "utf-8");
|
||||
|
||||
@@ -14,7 +13,9 @@ file = file.replace(/(\.\.\/)/g, "");
|
||||
|
||||
writeFileSync("installer.xml", file);
|
||||
|
||||
let versionId = "0" + require("../package.json").version.replace(/[.]/g, ""),
|
||||
let versionId = (require("../package.json").version as string)
|
||||
.replace(/[.]/g, "")
|
||||
.padStart(4, "0"),
|
||||
updateIni = parse(readFileSync("installer_assets/update.ini", "utf-8"));
|
||||
|
||||
updateIni.Update.version_id = versionId;
|
||||
|
||||
Reference in New Issue
Block a user