Major migration to Deno runtime following the nupst project pattern: Core Changes: - Created deno.json configuration with tasks, imports, and settings - Created mod.ts as main entry point with Deno permissions - Updated all TypeScript imports from .js to .ts extensions - Replaced Node.js APIs (process.exit) with Deno equivalents (Deno.exit) - Updated path imports to use @std/path from JSR Dependencies: - Migrated all npm dependencies to use npm: prefix in import map - Added Deno standard library imports (@std/path, @std/assert) - Configured import aliases for all @push.rocks and @serve.zone packages Build & Distribution: - Created install.sh for downloading pre-compiled binaries - Created uninstall.sh for clean system removal - Created scripts/compile-all.sh for multi-platform compilation - Supports Linux (x64, ARM64), macOS (x64, ARM64), Windows (x64) Testing: - Migrated tests to Deno test framework using @std/assert - Created test.simple.ts for basic verification - Updated test structure to use Deno.test instead of tap CI/CD: - Created .gitea/workflows/ci.yml for type checking, linting, and builds - Created .gitea/workflows/release.yml for automated releases - Created .gitea/release-template.md for release documentation Cleanup: - Removed package.json, pnpm-lock.yaml, tsconfig.json - Removed Node.js CLI files (cli.js, cli.child.ts, cli.ts.js) - Removed dist_ts/ compiled output directory - Removed npmextra.json configuration This migration enables standalone binary distribution without Node.js runtime dependency while maintaining all existing functionality.
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import * as plugins from './spark.plugins.ts';
|
|
import { Spark } from './index.ts';
|
|
import * as paths from './spark.paths.ts';
|
|
import { logger } from './spark.logging.ts';
|
|
|
|
export class SparkTaskManager {
|
|
public sparkRef: Spark;
|
|
public taskmanager: plugins.taskbuffer.TaskManager;
|
|
|
|
// tasks
|
|
public updateSpark: plugins.taskbuffer.Task;
|
|
public updateHost: plugins.taskbuffer.Task;
|
|
public updateServices: plugins.taskbuffer.Task;
|
|
|
|
constructor(sparkRefArg: Spark) {
|
|
this.sparkRef = sparkRefArg;
|
|
this.taskmanager = new plugins.taskbuffer.TaskManager();
|
|
|
|
// updateSpark
|
|
this.updateSpark = new plugins.taskbuffer.Task({
|
|
name: 'updateSpark',
|
|
taskFunction: async () => {
|
|
const smartupdateInstance = new plugins.smartupdate.SmartUpdate({
|
|
npmRegistryUrl: 'https://registry.npmjs.org',
|
|
});
|
|
const shouldUpdate = await smartupdateInstance.check(
|
|
this.sparkRef.sparkInfo.projectInfo.name,
|
|
this.sparkRef.sparkInfo.projectInfo.version
|
|
);
|
|
if (shouldUpdate) {
|
|
await this.stop();
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
executor: 'bash',
|
|
});
|
|
|
|
await smartshellInstance.exec(`cd / && npm upgrade -g && spark updatedaemon`);
|
|
logger.log('info', 'Cooling off before restart...');
|
|
await plugins.smartdelay.delayFor(5000);
|
|
logger.log('ok', '######## Trying to exit / Restart expected... ########');
|
|
Deno.exit(0);
|
|
}
|
|
},
|
|
});
|
|
|
|
this.updateHost = new plugins.taskbuffer.Task({
|
|
name: 'updateHost',
|
|
taskFunction: async () => {
|
|
await this.stop();
|
|
const smartshellInstance = new plugins.smartshell.Smartshell({
|
|
executor: 'bash',
|
|
});
|
|
await smartshellInstance.exec(
|
|
`apt-get update && apt-get upgrade -y --force-yes && apt-get autoremove -y --force-yes && apt-get autoclean -y --force-yes`
|
|
);
|
|
await this.start();
|
|
},
|
|
});
|
|
|
|
/**
|
|
* only being run when mode is cloudly
|
|
*/
|
|
this.updateServices = new plugins.taskbuffer.Task({
|
|
name: 'updateCloudly',
|
|
taskFunction: async () => {
|
|
logger.log('info', 'now running updateCloudly task');
|
|
this.sparkRef.sparkUpdateManager.updateServices();
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* start the taskmanager
|
|
*/
|
|
public async start() {
|
|
this.taskmanager.addAndScheduleTask(this.updateServices, '30 */2 * * * *');
|
|
this.taskmanager.addAndScheduleTask(this.updateSpark, '0 * * * * *');
|
|
this.taskmanager.addAndScheduleTask(this.updateHost, '0 0 0 * * *');
|
|
this.taskmanager.start();
|
|
}
|
|
|
|
/**
|
|
* stops the taskmanager
|
|
*/
|
|
public async stop() {
|
|
this.taskmanager.descheduleTask(this.updateSpark);
|
|
this.taskmanager.descheduleTask(this.updateHost);
|
|
this.taskmanager.descheduleTask(this.updateServices);
|
|
this.taskmanager.stop();
|
|
}
|
|
}
|