fix(core): update

This commit is contained in:
Philipp Kunz 2024-03-17 21:24:25 +01:00
parent 8909149af8
commit 046a0ff55f
10 changed files with 116 additions and 195 deletions

2
assets/denoentry.ts Normal file
View File

@ -0,0 +1,2 @@
console.log('Hello from deno');

View File

@ -22,9 +22,13 @@
"@types/node": "^20.8.7" "@types/node": "^20.8.7"
}, },
"dependencies": { "dependencies": {
"@api.global/typedserver": "^3.0.27",
"@push.rocks/lik": "^6.0.14",
"@push.rocks/smartarchive": "^4.0.22", "@push.rocks/smartarchive": "^4.0.22",
"@push.rocks/smartfile": "^11.0.4",
"@push.rocks/smartpath": "^5.0.11", "@push.rocks/smartpath": "^5.0.11",
"@push.rocks/smartshell": "^3.0.4" "@push.rocks/smartshell": "^3.0.4",
"@push.rocks/smartunique": "^3.0.8"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

198
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -8,9 +8,13 @@ tap.test('should create a valid smartdeno instance', async () => {
}); });
tap.test('should download deno', async () => { tap.test('should download deno', async () => {
await testSmartdeno.init({ await testSmartdeno.start({
forceLocalDeno: true forceLocalDeno: true
}); });
}) })
tap.test('should execute a script', async () => {
await testSmartdeno.executeScript(`console.log("A script from deno!")`);
})
tap.start() tap.start()

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@push.rocks/smartdeno', name: '@push.rocks/smartdeno',
version: '1.0.2', version: '1.0.3',
description: 'a module to run deno from node' description: 'a module to run deno from node'
} }

View File

@ -65,6 +65,9 @@ export class DenoDownloader {
} catch (error) { } catch (error) {
console.error(`Error downloading Deno: ${error.message}`); console.error(`Error downloading Deno: ${error.message}`);
} }
if (await plugins.smartfile.fs.fileExists(plugins.path.join(paths.nogitDir, 'deno'))) {
return;
}
const smartarchive = await plugins.smartarchive.SmartArchive.fromArchiveFile(outputPath); const smartarchive = await plugins.smartarchive.SmartArchive.fromArchiveFile(outputPath);
const directory = plugins.path.dirname(outputPath); const directory = plugins.path.dirname(outputPath);
console.log(`Extracting deno.zip to ${directory}`); console.log(`Extracting deno.zip to ${directory}`);

View File

@ -0,0 +1,21 @@
import type { ScriptServer } from './classes.scriptserver.js';
import * as plugins from './plugins.js';
/* This file contains logic to execute deno commands in an ephermal way */
export class DenoExecution {
public id: string;
public scriptserverRef: ScriptServer;
public script: string;
constructor(scriptserverRef: ScriptServer, scriptArg: string) {
this.scriptserverRef = scriptserverRef;
this.script = scriptArg;
this.id = plugins.smartunique.shortId();
}
public async execute() {
this.scriptserverRef.executionMap.add(this);
await this.scriptserverRef.smartshellInstance.exec(`deno run http://localhost:3210/getscript/${this.id}`)
}
}

View File

@ -0,0 +1,31 @@
import type { DenoExecution } from './classes.denoexecution.js';
import * as plugins from './plugins.js';
export class ScriptServer {
private server: plugins.typedserver.servertools.Server;
public smartshellInstance = new plugins.smarthshell.Smartshell({
executor: 'bash'
});
public executionMap = new plugins.lik.ObjectMap<DenoExecution>();
public async start() {
this.server = new plugins.typedserver.servertools.Server({
port: 3210,
cors: true,
});
this.server.addRoute(
'/getscript/:executionId',
new plugins.typedserver.servertools.Handler('GET', async (req, res) => {
const executionId = req.params.executionId;
const denoExecution = await this.executionMap.find(async denoExecutionArg => {
return denoExecutionArg.id === executionId;
})
res.write(denoExecution.script);
res.end();
})
);
await this.server.start();
}
public async stop() {}
}

View File

@ -1,14 +1,14 @@
import { DenoDownloader } from './classes.denodownloader.js'; import { DenoDownloader } from './classes.denodownloader.js';
import * as plugins from './plugins.js'; import * as plugins from './plugins.js';
import * as paths from './paths.js'; import * as paths from './paths.js';
import { ScriptServer } from './classes.scriptserver.js';
import { DenoExecution } from './classes.denoexecution.js';
export class SmartDeno { export class SmartDeno {
private denoDownloader = new DenoDownloader(); private denoDownloader = new DenoDownloader();
private smartshellInstance = new plugins.smarthshell.Smartshell({ private scriptServer = new ScriptServer();
executor: 'bash'
});
public async init(optionsArg: { public async start(optionsArg: {
forceLocalDeno?: boolean; forceLocalDeno?: boolean;
} = {}) { } = {}) {
const denoAlreadyInPath = await plugins.smarthshell.which('deno', { const denoAlreadyInPath = await plugins.smarthshell.which('deno', {
@ -17,5 +17,18 @@ export class SmartDeno {
if (!denoAlreadyInPath || optionsArg.forceLocalDeno) { if (!denoAlreadyInPath || optionsArg.forceLocalDeno) {
await this.denoDownloader.download(plugins.path.join(paths.nogitDir, 'deno.zip')); await this.denoDownloader.download(plugins.path.join(paths.nogitDir, 'deno.zip'));
} }
await this.scriptServer.start();
}
/**
* Stops the smartdeno instance
*/
public async stop() {
}
public async executeScript(scriptArg: string) {
const denoExecution = new DenoExecution(this.scriptServer, scriptArg);
await denoExecution.execute();
} }
} }

View File

@ -5,13 +5,26 @@ export {
path, path,
} }
// @push.rocks scope // @api.global scope
import * as smartarchive from '@push.rocks/smartarchive'; import * as typedserver from '@api.global/typedserver';
import * as smartpath from '@push.rocks/smartpath';
import * as smarthshell from '@push.rocks/smartshell';
export { export {
typedserver,
}
// @push.rocks scope
import * as lik from '@push.rocks/lik';
import * as smartarchive from '@push.rocks/smartarchive';
import * as smartfile from '@push.rocks/smartfile';
import * as smartpath from '@push.rocks/smartpath';
import * as smarthshell from '@push.rocks/smartshell';
import * as smartunique from '@push.rocks/smartunique';
export {
lik,
smartarchive, smartarchive,
smartfile,
smartpath, smartpath,
smarthshell, smarthshell,
smartunique,
} }