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




JSR Score
41%
Published
3 months ago (3.3.2)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196import 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.')); }