Skip to main content
This release is 5 versions behind 4.1.0 ā€” the latest version of @lost-c3/lib. Jump to latest

Lost for easy making Construct 3 Addons.

This package works with DenoIt is unknown whether this package works with Cloudflare Workers, Node.js, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
41%
Published
3 months ago (3.3.2)
import DenoJson from './deno.json' with { type: "json" }; import { Colors, join, Logger, parseArgs } from './deps.ts'; import { Paths } from './shared/paths.ts'; import Build from './cli/main.ts'; import Serve from './cli/serve-addon.ts'; import { dedent } from "./shared/misc.ts"; import { downloadAddonBase } from "./cli/check-addon-base-exists.ts"; import { AddonFileManager } from "./lib/managers/addon-file-manager.ts"; let rebuildTimeout: number | undefined; async function BuildAndWatch() { const watcher = Deno.watchFs([ Paths.ProjectFolders.Addon, Paths.ProjectFolders.Editor, 'addon.ts', 'lost.config.ts' ]); Logger.Clear(); Logger.Log( '\nšŸ‘€', Colors.blue('Watching for file changes...\n') ); await Build({ watch: true }); for await (const event of watcher) { if (event.kind === 'modify') { for (const path of event.paths) { if ( path.endsWith('.ts') || path.endsWith('.js') || path.endsWith('.css') ) { if (!rebuildTimeout) { clearTimeout(rebuildTimeout); } rebuildTimeout = setTimeout(async () => { await Build({ watch: true }); }, 500); } } } } } async function main() { const { _, ...flags } = parseArgs(Deno.args, { boolean: ['drawing-plugin', 'plugin', 'behavior', 'watch', 'minify'], alias: { dp: 'drawing-plugin', p: 'plugin', b: 'behavior', w: 'watch', m: 'minify'}, "--": true, }); const command = _[0] switch (command) { case 'help': printHelp(); break; case 'version': Logger.LogBetweenLines(dedent` šŸ‘¾ ${Colors.bold(`Lost āžœ ${Colors.yellow(DenoJson.version)} by ${Colors.italic(Colors.magenta('lostinmind.'))}`)} šŸŒ ${Colors.bold('https://github.com/lostinmind-dev/lost-c3')} `) break; case 'create': if ( !flags.plugin && !flags.behavior && !flags["drawing-plugin"] ) { Logger.Log('šŸŽ“', Colors.blue(Colors.italic('Specify one of the available types of addon:'))) printCreate(); break; } else { if (flags.plugin) { await createBareBones('plugin'); } if (flags.behavior) { await createBareBones('behavior'); } if (flags["drawing-plugin"]) { await createBareBones('drawing-plugin'); } } break; case 'build': if (flags.watch) { await BuildAndWatch(); } else { if (flags.minify) { AddonFileManager.minify = true; } else { AddonFileManager.minify = false; } await Build({}); } break; case 'serve': Serve(65432); break; case 'types': await installTypes(); break; default: Logger.Log(`āŒ ${Colors.red(Colors.bold(`Unknown command:`)), Colors.italic(String(command))}`); Logger.Log(Colors.blue(Colors.italic('Enter')), Colors.italic(Colors.bold(`${Colors.yellow('lost')} help`)), Colors.italic(Colors.blue('to get of available commands.'))) Deno.exit(1); } } if (import.meta.main) { await main(); } async function installTypes() { try { const response = await fetch(Paths.Links.ConstructTypes) if (!response.ok) { Logger.Error('cli', 'Error while installing "construct.d.ts" file', `Status: ${response.statusText}`); Deno.exit(1); } const fileContent = await response.text(); await Deno.writeTextFile(join(Paths.Root, 'Addon', 'Types', 'construct.d.ts'), fileContent); Logger.Success(Colors.bold(`${Colors.green('Successfully')} installed construct types!`)); } catch (e) { Logger.Error('cli', 'Error while installing construct types file', `Error: ${e}`); Deno.exit(1); } } async function createBareBones(type: AddonBareBonesType) { Logger.Process(`Creating bare-bones for ${Colors.magenta(`"${type}"`)} addon type`); await cloneRepo(Paths.Links.BareBones[type]); switch (type) { case "plugin": await downloadAddonBase('plugin'); break; case "drawing-plugin": await downloadAddonBase('plugin'); break; case "behavior": await downloadAddonBase('behavior'); break; } } async function cloneRepo(url: string) { const command = new Deno.Command('git', { args: ['clone', url, './'], stdout: "piped", stderr: "piped" }) const { code } = await command.output(); if (code === 0) { Logger.Success(Colors.bold(`${Colors.green('Successfully')} created bare-bones!`)); await installTypes(); } else { Logger.Error('cli', 'Error occured while creating bare-bones.', `Error code: ${code}`); } } function printHelp() { Logger.Info(Colors.bold('Usage: lost <command> [options]')); Logger.Log('āœ…', Colors.bold("Valid commands:")); Logger.Log(` ${Colors.yellow('help')}`); Logger.Log(` ${Colors.yellow('version')}`); Logger.Log(` ${Colors.yellow('create')}`); printCreate(); Logger.Log(` ${Colors.yellow('build')}`); Logger.Log(' āš™ļø', Colors.gray(' --watch, -w'), Colors.italic(' Runs build command with auto-reload.')); Logger.Log(' āš™ļø', Colors.gray(' --minify, -m'), Colors.italic(' Runs build command with minification.')); Logger.Log(` ${Colors.yellow('serve')}`); Logger.Log(` ${Colors.yellow('types')}`, Colors.italic(' Creates "properties.d.ts" of your plugin properties.')); } function printCreate() { Logger.Log(' āš™ļø', Colors.gray(' --plugin, -p'), Colors.italic(' Creates a bare-bones for "Plugin" addon type.')); Logger.Log(' āš™ļø', Colors.gray(' --drawing-plugin, -dp'), Colors.italic(' Creates a bare-bones for "Drawing Plugin" addon type.')); Logger.Log(' āš™ļø', Colors.gray(' --behavior, -b'), Colors.italic(' Creates a bare-bones for "Behavior" addon type.')); // Logger.Log(' āš™ļø', Colors.gray(' --theme, -t'), Colors.italic(' Creates a bare-bones for "theme" addon type.')); // Logger.Log(' āš™ļø', Colors.gray(' --effect, -e'), Colors.italic(' Creates a bare-bones for "effect" addon type.')); }