Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@steambrew/ttc",
"version": "2.8.6",
"version": "2.9.0",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand All @@ -9,6 +9,7 @@
},
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"prepare": "npm run build"
},
"publishConfig": {
Expand Down
7 changes: 4 additions & 3 deletions src/check-health.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import chalk from 'chalk';
import path from 'path';
import { existsSync, readFile } from 'fs';
import path from 'path';
import { PluginJson } from './plugin-json';

export const ValidatePlugin = (bIsMillennium: boolean, target: string): Promise<any> => {
return new Promise<any>((resolve, reject) => {
export const ValidatePlugin = (bIsMillennium: boolean, target: string): Promise<PluginJson> => {
return new Promise<PluginJson>((resolve, reject) => {
if (!existsSync(target)) {
console.error(chalk.red.bold(`\n[-] --target [${target}] `) + chalk.red('is not a valid system path'));
reject();
Expand Down
23 changes: 13 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* - typescript transpiler
* - rollup configurator
*/
import { BuildType, ValidateParameters } from './query-parser';
import { CheckForUpdates } from './version-control';
import { performance } from 'perf_hooks';
import { ValidatePlugin } from './check-health';
import { Logger } from './logger';
import { PluginJson } from './plugin-json';
import { BuildType, ValidateParameters } from './query-parser';
import { TranspilerPluginComponent, TranspilerProps } from './transpiler';
import { performance } from 'perf_hooks';
import chalk from 'chalk';
// import { Logger } from './Logger'
import { CheckForUpdates } from './version-control';

declare global {
var PerfStartTime: number;
Expand All @@ -25,17 +25,20 @@ const StartCompilerModule = () => {
const parameters = ValidateParameters(process.argv.slice(2));
const bIsMillennium = parameters.isMillennium || false;
const bTersePlugin = parameters.type == BuildType.ProdBuild;
const bWatchMode = parameters.watch || false;

console.log(chalk.greenBright.bold('config'), 'Building target:', parameters.targetPlugin, 'with type:', BuildType[parameters.type], 'minify:', bTersePlugin, '...');
Logger.Config('Building target:', parameters.targetPlugin, 'with type:', BuildType[parameters.type], 'minify:', bTersePlugin, '...');

ValidatePlugin(bIsMillennium, parameters.targetPlugin)
.then((json: any) => {
.then((json: PluginJson) => {
const props: TranspilerProps = {
bTersePlugin: bTersePlugin,
strPluginInternalName: json?.name,
bTersePlugin,
strPluginInternalName: json.name,
bWatchMode,
bIsMillennium,
};

TranspilerPluginComponent(bIsMillennium, json, props);
TranspilerPluginComponent(json, props);
})

/**
Expand Down
4 changes: 4 additions & 0 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const Logger = {
console.log(chalk.magenta.bold(name), ...LogMessage);
},

Config: (...LogMessage: any) => {
console.log(chalk.greenBright.bold('config'), ...LogMessage);
},

Warn: (...LogMessage: any) => {
console.log(chalk.yellow.bold('**'), ...LogMessage);
},
Expand Down
16 changes: 16 additions & 0 deletions src/plugin-json.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* generated from https://raw.githubusercontent.com/SteamClientHomebrew/Millennium/main/src/sys/plugin-schema.json
*/
export interface PluginJson {
backend?: string;
common_name?: string;
description?: string;
frontend?: string;
include?: string[];
name: string;
splash_image?: string;
thumbnail?: string;
useBackend?: boolean;
venv?: string;
version?: string;
}
33 changes: 16 additions & 17 deletions src/query-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ import { Logger } from './logger';
* @brief print the parameter list to the stdout
*/
export const PrintParamHelp = () => {
console.log(
'millennium-ttc parameter list:' +
'\n\t' +
chalk.magenta('--help') +
': display parameter list' +
'\n\t' +
chalk.bold.red('--build') +
': ' +
chalk.bold.red('(required)') +
': build type [dev, prod] (prod minifies code)' +
'\n\t' +
chalk.magenta('--target') +
': path to plugin, default to cwd',
);
console.log(`
millennium-ttc parameter list:
${chalk.magenta('--help')}: display parameter list
${chalk.bold.red('--build')}: ${chalk.bold.red('(required)')}: build type [dev, prod] (prod minifies code)
${chalk.magenta('--target')}: path to plugin, default to cwd
${chalk.magenta('--watch')}: enable watch mode for continuous rebuilding`);
};

export enum BuildType {
Expand All @@ -30,12 +22,14 @@ export interface ParameterProps {
type: BuildType;
targetPlugin: string; // path
isMillennium?: boolean;
watch?: boolean;
}

export const ValidateParameters = (args: Array<string>): ParameterProps => {
let typeProp: BuildType = BuildType.DevBuild,
targetProp: string = process.cwd(),
isMillennium: boolean = false;
isMillennium: boolean = false,
watch: boolean = false;

if (args.includes('--help')) {
PrintParamHelp();
Expand Down Expand Up @@ -67,7 +61,7 @@ export const ValidateParameters = (args: Array<string>): ParameterProps => {
}
}

if (args[i] == '--target') {
if (args[i] === '--target') {
if (args[i + 1] === undefined) {
Logger.Error('--target parameter must be preceded by system path');
process.exit();
Expand All @@ -76,14 +70,19 @@ export const ValidateParameters = (args: Array<string>): ParameterProps => {
targetProp = args[i + 1];
}

if (args[i] == '--millennium-internal') {
if (args[i] === '--millennium-internal') {
isMillennium = true;
}

if (args[i] === '--watch') {
watch = true;
}
}

return {
type: typeProp,
targetPlugin: targetProp,
isMillennium: isMillennium,
watch: watch,
};
};
13 changes: 11 additions & 2 deletions src/static-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default function constSysfsExpr(options: EmbedPluginOptions = {}): Plugin
}

try {
const currentLocString = node.loc?.start ? ` at ${id}:${node.loc.start.line}:${node.loc.start.column}` : ` in ${id}`;
const currentLocString = node.loc?.start ? ` at ${chalk.cyan.bold(id)}:${node.loc.start.line}:${node.loc.start.column}` : ` in ${id}`;

const searchBasePath = callOptions.basePath
? path.isAbsolute(callOptions.basePath)
Expand All @@ -197,7 +197,11 @@ export default function constSysfsExpr(options: EmbedPluginOptions = {}): Plugin
fs.statSync(path.resolve(searchBasePath, pathOrPattern)).isFile()
) {
const singleFilePath = path.resolve(searchBasePath, pathOrPattern);
Log(`Mode: Single file (first argument "${pathOrPattern}" resolved to "${singleFilePath}" relative to "${searchBasePath}")`);
Log(
`Mode: Single file (first argument "${chalk.cyan.bold(pathOrPattern)}" resolved to "${chalk.cyan.bold(
singleFilePath,
)}" relative to "${chalk.cyan.bold(searchBasePath)}")`,
);

try {
const rawContent: string | Buffer = fs.readFileSync(singleFilePath, callOptions.encoding);
Expand All @@ -209,6 +213,9 @@ export default function constSysfsExpr(options: EmbedPluginOptions = {}): Plugin
};
embeddedContent = JSON.stringify(fileInfo);
embeddedCount = 1;

this.addWatchFile(singleFilePath);

Log(`Embedded 1 specific file for call${currentLocString}`);
} catch (fileError: unknown) {
let message = String(fileError instanceof Error ? fileError.message : fileError ?? 'Unknown file read error');
Expand Down Expand Up @@ -236,6 +243,8 @@ export default function constSysfsExpr(options: EmbedPluginOptions = {}): Plugin
filePath: fullPath,
fileName: path.relative(searchBasePath, fullPath),
});

this.addWatchFile(fullPath);
} catch (fileError: unknown) {
let message = String(fileError instanceof Error ? fileError.message : fileError ?? 'Unknown file read error');
this.warn(`Error reading file ${fullPath}: ${message}`);
Expand Down
Loading