Skip to content

Commit

Permalink
3.3.2
Browse files Browse the repository at this point in the history
- Reworked paths system

- `lost build --watch` now detect changes in Categories and other addon folders.

- Fixed issues with 'main.js' module file
  • Loading branch information
dakln committed Dec 12, 2024
1 parent c214b92 commit 02a6081
Show file tree
Hide file tree
Showing 143 changed files with 578 additions and 3,037 deletions.
9 changes: 5 additions & 4 deletions .addon_base/behavior/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
setupUserModules() {
const modules = _lostData.files.filter(file => file.type === 'module');
if (modules.length > 0) {
this._info.SetRuntimeModuleMainScript('c3runtime/main.js');
modules.forEach(file => {
this._info.AddC3RuntimeScript(`c3runtime/modules/${file.path}`);
this._info.AddC3RuntimeScript(file.path);
});
}
}
Expand All @@ -57,14 +58,14 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
files.forEach(file => {
if (file.dependencyType === 'copy-to-output') {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType,
fileType: file.mimeType
});
}
else {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType || 'copy-to-output'
});
}
Expand All @@ -76,7 +77,7 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
if (files.length > 0) {
files.forEach(file => {
this._info.AddFileDependency({
filename: `scripts/${file.path}`,
filename: file.path,
type: file.dependencyType || 'external-dom-script'
});
});
Expand Down
10 changes: 6 additions & 4 deletions .addon_base/behavior/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
private setupUserModules() {
const modules = _lostData.files.filter(file => file.type === 'module');
if (modules.length > 0) {
this._info.SetRuntimeModuleMainScript('c3runtime/main.js');

modules.forEach(file => {
this._info.AddC3RuntimeScript(`c3runtime/modules/${file.path}`);
this._info.AddC3RuntimeScript(file.path);
})
}
}
Expand All @@ -72,13 +74,13 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
files.forEach(file => {
if (file.dependencyType === 'copy-to-output') {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType,
fileType: file.mimeType
})
} else {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType || 'copy-to-output'
})
}
Expand All @@ -92,7 +94,7 @@ const BEHAVIOR_CLASS = SDK.Behaviors[config.addonId] = class LostBehavior extend
if (files.length > 0) {
files.forEach(file => {
this._info.AddFileDependency({
filename: `scripts/${file.path}`,
filename: file.path,
type: file.dependencyType || 'external-dom-script'
})
})
Expand Down
11 changes: 6 additions & 5 deletions .addon_base/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,17 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
if (domSideScripts.length > 0) {
const list = [];
domSideScripts.forEach(file => {
list.push(`c3runtime/domSide/${file.path}`);
list.push(file.path);
});
this._info.SetDOMSideScripts(list);
}
}
setupUserModules() {
const modules = _lostData.files.filter(file => file.type === 'module');
if (modules.length > 0) {
this._info.SetRuntimeModuleMainScript('c3runtime/main.js');
modules.forEach(file => {
this._info.AddC3RuntimeScript(`c3runtime/modules/${file.path}`);
this._info.AddC3RuntimeScript(file.path);
});
}
}
Expand All @@ -147,14 +148,14 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
files.forEach(file => {
if (file.dependencyType === 'copy-to-output') {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType,
fileType: file.mimeType
});
}
else {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType || 'copy-to-output'
});
}
Expand All @@ -166,7 +167,7 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
if (files.length > 0) {
files.forEach(file => {
this._info.AddFileDependency({
filename: `scripts/${file.path}`,
filename: file.path,
type: file.dependencyType || 'external-dom-script'
});
});
Expand Down
12 changes: 7 additions & 5 deletions .addon_base/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
const list: string[] = [];

domSideScripts.forEach(file => {
list.push(`c3runtime/domSide/${file.path}`);
list.push(file.path);
})

this._info.SetDOMSideScripts(list)
Expand All @@ -145,8 +145,10 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
private setupUserModules() {
const modules = _lostData.files.filter(file => file.type === 'module');
if (modules.length > 0) {
this._info.SetRuntimeModuleMainScript('c3runtime/main.js');

modules.forEach(file => {
this._info.AddC3RuntimeScript(`c3runtime/modules/${file.path}`);
this._info.AddC3RuntimeScript(file.path);
})
}
}
Expand All @@ -164,13 +166,13 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
files.forEach(file => {
if (file.dependencyType === 'copy-to-output') {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType,
fileType: file.mimeType
})
} else {
this._info.AddFileDependency({
filename: `files/${file.path}`,
filename: file.path,
type: file.dependencyType || 'copy-to-output'
})
}
Expand All @@ -184,7 +186,7 @@ const PLUGIN_CLASS = SDK.Plugins[config.addonId] = class LostPlugin extends SDK.
if (files.length > 0) {
files.forEach(file => {
this._info.AddFileDependency({
filename: `scripts/${file.path}`,
filename: file.path,
type: file.dependencyType || 'external-dom-script'
})
})
Expand Down
16 changes: 9 additions & 7 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ let rebuildTimeout: number | undefined;

async function BuildAndWatch() {
const watcher = Deno.watchFs([
join(Paths.Main, 'Addon'),
join(Paths.Main, 'Editor'),
join(Paths.Main, 'addon.ts'),
join(Paths.Main, 'lost.config.ts')
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) {
Expand Down Expand Up @@ -118,15 +120,15 @@ if (import.meta.main) {

async function installTypes() {
try {
const response = await fetch(Paths.ConstructTypes)
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.Main, 'Addon', 'Types', 'construct.d.ts'), fileContent);
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}`);
Expand All @@ -136,7 +138,7 @@ async function installTypes() {

async function createBareBones(type: AddonBareBonesType) {
Logger.Process(`Creating bare-bones for ${Colors.magenta(`"${type}"`)} addon type`);
await cloneRepo(Paths.BareBones[type]);
await cloneRepo(Paths.Links.BareBones[type]);

switch (type) {
case "plugin":
Expand Down
14 changes: 7 additions & 7 deletions cli/check-addon-base-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { Paths } from "../shared/paths.ts";
export async function downloadAddonBase(addonType: AddonType) {
Logger.Log(`🌐 Downloading addon base ...`);

await Deno.mkdir(join(Paths.Main, '.addon_base'), { recursive: true });
await Deno.mkdir(join(Paths.Root, '.addon_base'), { recursive: true });

const response = await fetch(Paths.AddonBaseUrl[addonType]);
const response = await fetch(Paths.Links.AddonBase[addonType]);

if (!response.ok) {
Logger.Error('build', 'Error while getting addon base', `Status: ${response.statusText}`);
Expand All @@ -18,25 +18,25 @@ export async function downloadAddonBase(addonType: AddonType) {
const fileContent = await response.text();

const metadata: IAddonBaseMetadata = {
download_url: Paths.AddonBaseUrl[addonType],
download_url: Paths.Links.AddonBase[addonType],
addon_type: addonType,
version: DenoJson.version,
timestamp: Date.now()
}

await Deno.writeTextFile(join(Paths.Main, Paths.AddonBaseFolderName, 'metadata.json'), JSON.stringify(metadata, null, 4));
await Deno.writeTextFile(Paths.LocalAddonBase[addonType], fileContent);
await Deno.writeTextFile(join(Paths.ProjectFolders.AddonBase, 'metadata.json'), JSON.stringify(metadata, null, 4));
await Deno.writeTextFile(Paths.ProjectFiles.AddonBase[addonType], fileContent);
Logger.Success(Colors.bold(`${Colors.green('Successfully')} installed addon base!`));
}


export default async function checkAddonBaseExists(addonType: AddonType) {

try {
const dirStat = await Deno.stat(Paths.LocalAddonBase[addonType]);
const dirStat = await Deno.stat(Paths.ProjectFiles.AddonBase[addonType]);

if (dirStat) {
const fileContent = await Deno.readTextFile(join(Paths.Main, Paths.AddonBaseFolderName, 'metadata.json'));
const fileContent = await Deno.readTextFile(join(Paths.ProjectFolders.AddonBase, 'metadata.json'));
const metadata: IAddonBaseMetadata = JSON.parse(fileContent);

if (metadata.version !== DenoJson.version) {
Expand Down
6 changes: 3 additions & 3 deletions cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export default async function build(opts: { watch?: true }) {

Logger.Clear();
Logger.LogBetweenLines('🚀 Starting build process...');

const addon = (await import(`${Paths.AddonModulePath}?t=${Date.now()}`)).default as Addon<any, any, any>;
// console.log(Paths)
const addon = (await import(`${Paths.ProjectFiles.AddonModule}?t=${Date.now()}`)).default as Addon<any, any, any>;

Parameter.addonId = addon._getConfig().addonId;
await checkAddonBaseExists(addon._getConfig().type);
await addon._build(opts.watch || false);

if (!isBuildError) {
if (!opts.watch) {
Logger.Process('Creating .c3addon file');
Logger.LogBetweenLines(Colors.bgMagenta('Bundling addon...'));
await Zip(addon._getConfig());
}

Expand Down
2 changes: 1 addition & 1 deletion cli/serve-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function serveAddon(port: number) {
try {
const url = new URL(req.url);
// let filePath = url.pathname;
let filePath = join(Paths.Build, url.pathname);
let filePath = join(Paths.ProjectFolders.Build, url.pathname);

try {
const fileInfo = await Deno.stat(filePath);
Expand Down
6 changes: 3 additions & 3 deletions cli/zip-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { Paths } from "../shared/paths.ts";

export default async function zipAddon(config: LostConfig<AddonType>) {
const zipWriter = new ZipWriter(new BlobWriter('application/zip'));
const addonFilePath = join(Paths.Main, 'Builds', `${config.addonId}_${config.version}`)
const addonFilePath = join(Paths.ProjectFolders.Builds, `${config.addonId}_${config.version}`)

for await (const entry of walk(join(Paths.Build))) {
for await (const entry of walk(Paths.ProjectFolders.Build)) {
const {isFile, path} = entry;
if (isFile) {
const data = await Deno.readTextFile(path);
const relativePath = path.substring(join(Paths.Build).length + 1).replace(/\\/g, "/");;
const relativePath = path.substring(Paths.ProjectFolders.Build.length + 1).replace(/\\/g, "/");;

zipWriter.add(relativePath, new TextReader(data))
}
Expand Down
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lost-c3/lib",
"version": "3.3.1",
"version": "3.3.2",
"exports": {
".": "./mod.ts",
"./cli": "./cli.ts",
Expand Down
16 changes: 0 additions & 16 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 02a6081

Please sign in to comment.