Skip to content

Commit

Permalink
v1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dakln committed Nov 7, 2024
1 parent 437adbf commit 80c0acf
Show file tree
Hide file tree
Showing 27 changed files with 893 additions and 148 deletions.
8 changes: 6 additions & 2 deletions addon_base/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ const PLUGIN_CLASS = SDK.Plugins[ADDON_ID] = class LostPlugin extends SDK.IPlugi
this._info.SetIsDeprecated(CONFIG.Deprecated || false);
this._info.SetCanBeBundled(CONFIG.CanBeBundled || true);
this._info.SetIsSingleGlobal(CONFIG.IsSingleGlobal || false);
this._info.SetRuntimeModuleMainScript("c3runtime/main.js")
this._info.SetRuntimeModuleMainScript("c3runtime/main.js");

SDK.Lang.PushContext(".properties");

REMOTE_SCRIPTS.forEach(url => {
this._info.AddRemoteScriptDependency(url);
});
SCRIPTS.forEach(script => {
this._info.AddFileDependency({ filename: `scripts/${script.filename}`, type: script.dependencyType });
if (script.scriptType) {
this._info.AddFileDependency({ filename: `scripts/${script.filename}`, type: script.dependencyType, scriptType: script.scriptType });
} else {
this._info.AddFileDependency({ filename: `scripts/${script.filename}`, type: script.dependencyType });
}
});
FILES.forEach(file => {
this._info.AddFileDependency({ filename: `files/${file.filename}`, type: file.dependencyType, fileType: file.fileType });
Expand Down
14 changes: 8 additions & 6 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env deno run --allow-read --allow-write --unstable
import type { AddonType } from "./lib/common.ts";

import { parseArgs } from "jsr:@std/[email protected]";
import { Colors } from "./deps.ts";
import { buildAddon } from "./cli/main.ts";
import type { AddonType } from "./lib/common.ts";
import { build } from "./cli/main.ts";
import { serveAddon } from './cli/serve-addon.ts';

const VERSION = '1.2.5'
Expand All @@ -11,8 +12,8 @@ type LostCommand = 'none' | 'help' | 'version' | 'build' | 'create' | 'serve';

async function main() {
const { _, ...flags } = parseArgs(Deno.args, {
boolean: ["plugin"],
alias: {p: "plugin"},
boolean: ["plugin", "theme", "effect"],
alias: {p: "plugin", t: "theme", e: "effect"},
"--": true,
});

Expand All @@ -38,7 +39,7 @@ async function main() {
}
break;
case 'build':
await buildAddon();
await build();
break;
case 'serve':
await serveAddon(65432);
Expand Down Expand Up @@ -85,8 +86,9 @@ function printHelp() {

console.log(` ${Colors.yellow('create')}`);
console.log(' ⚙️', Colors.gray(' --plugin, -p'), ' Creates a bare-bones for "plugin" addon type.');
console.log(' ⚙️', Colors.gray(' --theme, -t'), ' Creates a bare-bones for "theme" addon type.');
console.log(' ⚙️', Colors.gray(' --effect, -e'), ' Creates a bare-bones for "effect" addon type.');

console.log(` ${Colors.yellow('build')}`);
console.log(' ⚙️', Colors.gray(' --local-base, -c'), ' Builds addon with local addon base.');
console.log(` ${Colors.yellow('serve')}`);
}
62 changes: 62 additions & 0 deletions cli/effect/create-addon-effect-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { EffectParameter } from "../../lib/params.ts";
import type { AddonEffectFile } from './get-addon-effect-files.ts';
import type { LostConfig } from "../../lib/common.ts";
import type { AddonJSON } from "../../lib/json.ts";
import type { EffectParameterOptions } from '../../lib/params/EffectParameters.ts';

import { BUILD_PATH } from "../paths.ts";

interface CreateAddonJSONOptions {
CONFIG: LostConfig<'effect'>;
EFFECT_FILES: AddonEffectFile[];
PARAMETERS: EffectParameter<EffectParameterOptions>[];
}

export async function createAddonEffectJSON({CONFIG, EFFECT_FILES, PARAMETERS}: CreateAddonJSONOptions) {
const AddonJSON: AddonJSON.Effect = {
"is-deprecated": CONFIG.Deprecated || false,
"is-c3-addon": true,
"type": CONFIG.Type,
"name": CONFIG.AddonName,
"id": CONFIG.AddonId,
"version": CONFIG.Version,
"author": CONFIG.Author,
"website": CONFIG.WebsiteURL,
"documentation": CONFIG.DocsURL,
"description": CONFIG.AddonDescription,
"file-list": [
"lang/en-US.json",
"addon.json",
],
"category": CONFIG.Category,
"supported-renderers": CONFIG.SupportedRenderers,
"uses-depth": CONFIG.UsesDepth,
"cross-sampling": CONFIG.CrossSampling,
"preserves-opaqueness": CONFIG.PreservesOpaqueness,
"animated": CONFIG.Animated,
"must-predraw": CONFIG.MustPredraw || false,
"supports-3d-direct-rendering": CONFIG.Supports3DDirectRendering || false,
"extend-box": {
"horizontal": CONFIG.ExtendBox[0],
"vertical": CONFIG.ExtendBox[1],
},
"blends-background": CONFIG.BlendsBackground,
"parameters": []
};

PARAMETERS.forEach(parameter => {
const {Id, Type, InitialValue, Uniform} = parameter.Options;
AddonJSON['parameters'].push({
"id": Id,
"type": Type,
"initial-value": InitialValue,
"uniform": Uniform
})
})

EFFECT_FILES.forEach(effectFile => {
AddonJSON['file-list'].push(`${effectFile.filename}`);
});

await Deno.writeTextFile(`${BUILD_PATH}/addon.json`, JSON.stringify(AddonJSON, null, 4));
}
39 changes: 39 additions & 0 deletions cli/effect/create-addon-effect-language-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { LanguageJSON } from "../../lib/json.ts";
import type { LostConfig } from "../../lib/common.ts";
import type { EffectParameter } from '../../lib/params.ts';
import type { EffectParameterOptions } from '../../lib/params/EffectParameters.ts';

import { BUILD_PATH } from "../paths.ts";

interface CreateLanguageJSONOptions {
CONFIG: LostConfig<'effect'>;
PARAMETERS: EffectParameter<EffectParameterOptions>[];
}

export async function createAddonEffectLanguageJSON({CONFIG, PARAMETERS}: CreateLanguageJSONOptions) {
const LanguageJSON = {
"languageTag": "en-US",
"fileDescription": `Strings for ${CONFIG.AddonName} addon.`,
"text": {
[CONFIG.Type + 's']: {
[CONFIG.AddonId.toLowerCase()]: {
"name": CONFIG.AddonName,
"description": CONFIG.AddonDescription,
"parameters": {}
}
}
}
} as LanguageJSON.Effect;

const DeepJSON = LanguageJSON['text'][CONFIG.Type + 's'][CONFIG.AddonId.toLowerCase()];

PARAMETERS.forEach(parameter => {
const {Id, Name, Description} = parameter.Options;
DeepJSON['parameters'][Id] = {
"name": Name,
"desc": Description || ''
}
})

await Deno.writeTextFile(`${BUILD_PATH}/lang/en-US.json`, JSON.stringify(LanguageJSON, null, 4));
}
24 changes: 24 additions & 0 deletions cli/effect/create-addon-effect-structure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { AddonEffectFile } from './get-addon-effect-files.ts';

import { BUILD_PATH } from "../paths.ts";

interface CreateAddonStructureOptions {
EFFECT_FILES: AddonEffectFile[];
}

export async function createAddonEffectStructure({EFFECT_FILES}: CreateAddonStructureOptions) {
try {
await Deno.remove(BUILD_PATH, { recursive: true });
} catch (e) {
//return;
}
await Deno.mkdir(BUILD_PATH);
await Deno.mkdir(`${BUILD_PATH}/lang`);

if (EFFECT_FILES.length > 0) {
EFFECT_FILES.forEach(effectFile => {
Deno.copyFile(effectFile.path, `${BUILD_PATH}/${effectFile.filename}`);
})
}

}
32 changes: 32 additions & 0 deletions cli/effect/get-addon-effect-files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LOGGER } from '../misc.ts';
import { EFFECT_ADDON_FILES_FOLDER_PATH } from "../paths.ts";

export interface AddonEffectFile {
filename: string;
path: string;
}

export async function getAddonEffectFiles() {
LOGGER.Searching('Searching for files');

const effectFiles: AddonEffectFile[] = [];

const readFilesDirectory = async (path: string) => {
for await (const entry of Deno.readDir(path)) {
if (entry.isDirectory) {
await readFilesDirectory(`${path}/${entry.name}`);
}
if (entry.isFile && (entry.name.endsWith('.fx') || entry.name.endsWith('.wgsl'))) {
LOGGER.Info(`Founded effect file: ${entry.name}`);
effectFiles.push({
filename: entry.name,
path: `${path}/${entry.name}`
})
}
}
}

await readFilesDirectory(EFFECT_ADDON_FILES_FOLDER_PATH);

return effectFiles;
}
12 changes: 12 additions & 0 deletions cli/effect/get-addon-effect-parameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getModule } from "../misc.ts";
import type { EffectParameter } from "../../lib/params.ts";
import { EFFECT_PARAMETERS_FILE_PATH } from "../paths.ts";

interface EffectParametersModule {
default: EffectParameter<any>[];
}

export async function getAddonThemeEffectParameters() {
const module = await getModule<EffectParametersModule>(EFFECT_PARAMETERS_FILE_PATH);
return module.default;
};
2 changes: 1 addition & 1 deletion cli/get-addon-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface AddonFile {
dependencyType: FileDependencyType;
}

export async function getAddonFiles(config: LostConfig<AddonType>) {
export async function getAddonFiles(config: LostConfig<'plugin'>) {
LOGGER.Searching('Searching for files');

const files: AddonFile[] = [];
Expand Down
4 changes: 2 additions & 2 deletions cli/get-addon-scripts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AddonType, LostConfig, ScriptDependencyType } from "../lib/common.ts";
import type { LostConfig, ScriptDependencyType } from "../lib/common.ts";
import { LOGGER } from "./misc.ts";
import { ADDON_SCRIPTS_FOLDER_PATH } from "./paths.ts";

Expand All @@ -9,7 +9,7 @@ export interface AddonScript {
dependencyType: ScriptDependencyType;
}

export async function getAddonScripts(config: LostConfig<AddonType>) {
export async function getAddonScripts(config: LostConfig<'plugin'>) {
LOGGER.Searching('Searching for scripts');

const scripts: AddonScript[] = [];
Expand Down
94 changes: 79 additions & 15 deletions cli/main.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,77 @@
import type { LostConfig } from '../lib/config/Config.ts';

/**
* Common Addon Functions
*/
import { Colors } from "../deps.ts";
import { LOGGER } from "./misc.ts";
import { getConfig } from "./get-config.ts";
import { getPluginProperties } from "./get-plugin-properties.ts";
import { getAddonScripts } from "./get-addon-scripts.ts";
import { getAddonFiles } from "./get-addon-files.ts";
import { getAddonModules } from './get-addon-modules.ts';
import { getCategories } from "./get-categories.ts";
import { createAddonStructure } from "./create-addon-structure.ts";
import { getPluginProperties } from "./get-plugin-properties.ts";
import { getAddonIcon } from "./get-addon-icon.ts";
import { createAddonJSON } from "./create-addon-json.ts";
import { createAcesJSON } from "./create-aces-json.ts";
import { createLanguageJSON } from "./create-language-json.ts";
import { zipAddon } from "./zip-addon.ts";

export async function buildAddon() {
/**
* Plugin Addon Functions
*/
import { createAddonPluginStructure } from "./plugin/create-addon-plugin-structure.ts";
import { createAddonPluginLanguageJSON } from "./plugin/create-addon-plugin-language-json.ts";
import { createAddonPluginJSON } from "./plugin/create-addon-plugin-json.ts";

/**
* Theme Addon Functions
*/
import { getAddonThemeStyleFiles } from './theme/get-addon-theme-style-files.ts';
import { createAddonThemeStructure } from './theme/create-addon-theme-structure.ts';
import { createAddonThemeLanguageJSON } from './theme/create-addon-theme-language-json.ts';
import { createAddonThemeJSON } from './theme/create-addon-theme-json.ts';

/**
* Effect Addon Functions
*/
import { getAddonEffectFiles } from './effect/get-addon-effect-files.ts';
import { getAddonThemeEffectParameters } from './effect/get-addon-effect-parameters.ts';
import { createAddonEffectStructure } from './effect/create-addon-effect-structure.ts';
import { createAddonEffectJSON } from './effect/create-addon-effect-json.ts';
import { createAddonEffectLanguageJSON } from './effect/create-addon-effect-language-json.ts';

export async function build() {
const startTime = performance.now();

LOGGER.Clear();
LOGGER.Process('Fetching addon files');

const CONFIG = await getConfig();
LOGGER.LogBetweenLines('📛', Colors.bold(Colors.yellow('Id:')), Colors.bold(CONFIG.AddonId), '👽', Colors.bold(Colors.green('Name:')), Colors.bold(CONFIG.AddonName));

switch (CONFIG.Type) {
case 'plugin':
await buildPlugin(CONFIG);
break;
case 'theme':
await buildTheme(CONFIG);
break;
case 'effect':
await buildEffect(CONFIG);
break;
}

LOGGER.Process('Creating .c3addon file');
await zipAddon(CONFIG);
LOGGER.Success(Colors.bold(`Addon [${Colors.yellow(CONFIG.AddonId)}] has been ${Colors.green('successfully')} built`));

const endTime = performance.now();
const elapsedTime = endTime - startTime;
LOGGER.LogBetweenLines('⏱️', ` Addon build time: ${Colors.bold(Colors.yellow(String(elapsedTime.toFixed(2))))} ms!`);
}

async function buildPlugin(CONFIG: LostConfig<'plugin'>) {
const PLUGIN_PROPERTIES = await getPluginProperties();
LOGGER.LogBetweenLines('📃', Colors.bold('Plugin properties count:'), Colors.bold(Colors.yellow(`${PLUGIN_PROPERTIES.length}`)))
LOGGER.LogBetweenLines('📃', Colors.bold('Plugin properties count:'), Colors.bold(Colors.yellow(`${PLUGIN_PROPERTIES.length}`)));
const SCRIPTS = await getAddonScripts(CONFIG);
const FILES = await getAddonFiles(CONFIG);
const MODULES = await getAddonModules();
Expand All @@ -31,19 +80,34 @@ export async function buildAddon() {
LOGGER.Line();
LOGGER.Process('Building addon');

await createAddonStructure({CONFIG, PLUGIN_PROPERTIES, SCRIPTS, FILES, MODULES, CATEGORIES, ICON});
await createAddonPluginStructure({CONFIG, PLUGIN_PROPERTIES, SCRIPTS, FILES, MODULES, CATEGORIES, ICON});

await createAddonJSON({CONFIG, ICON, SCRIPTS, FILES, MODULES});
await createAddonPluginJSON({CONFIG, ICON, SCRIPTS, FILES, MODULES});

await createAcesJSON({CATEGORIES});

await createLanguageJSON({CONFIG, PLUGIN_PROPERTIES, CATEGORIES});
await createAddonPluginLanguageJSON({CONFIG, PLUGIN_PROPERTIES, CATEGORIES});
}

LOGGER.Process('Creating .c3addon file');
await zipAddon(CONFIG);
LOGGER.Success(Colors.bold(`Addon [${Colors.yellow(CONFIG.AddonId)}] has been ${Colors.green('successfully')} built`));
async function buildTheme(CONFIG: LostConfig<'theme'>) {
const STYLE_FILES = await getAddonThemeStyleFiles();
const ICON = await getAddonIcon();

const endTime = performance.now();
const elapsedTime = endTime - startTime;
LOGGER.LogBetweenLines('⏱️', ` Addon build time: ${Colors.bold(Colors.yellow(String(elapsedTime.toFixed(2))))} ms!`);
await createAddonThemeStructure({STYLE_FILES, ICON});

await createAddonThemeJSON({CONFIG, STYLE_FILES, ICON});

await createAddonThemeLanguageJSON({CONFIG});
}

async function buildEffect(CONFIG: LostConfig<'effect'>) {
const EFFECT_FILES = await getAddonEffectFiles();
const PARAMETERS = await getAddonThemeEffectParameters();
LOGGER.LogBetweenLines('📃', Colors.bold('Effect parameters count:'), Colors.bold(Colors.yellow(`${PARAMETERS.length}`)));

await createAddonEffectStructure({EFFECT_FILES});

await createAddonEffectJSON({CONFIG, EFFECT_FILES, PARAMETERS});

await createAddonEffectLanguageJSON({CONFIG, PARAMETERS});
}
Loading

0 comments on commit 80c0acf

Please sign in to comment.