Skip to content

Commit

Permalink
Move from deno.land to jsr. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon authored Mar 26, 2024
1 parent 3fc7f9d commit 0443bbb
Show file tree
Hide file tree
Showing 19 changed files with 268 additions and 265 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/bun.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/deno.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/jsr.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/node.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .github/workflows/publish-jsr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Publish to jsr.io
on:
release:
types: [released]
workflow_dispatch:

jobs:
publish:
permissions:
contents: read
id-token: write
uses: cross-org/workflows/.github/workflows/jsr-publish.yml@main
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Testing CI

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # Allow manual runs

jobs:
deno_ci:
uses: cross-org/workflows/.github/workflows/deno-ci.yml@main
with:
entrypoint: mod.ts
lint_docs: false
bun_ci:
uses: cross-org/workflows/.github/workflows/bun-ci.yml@main
with:
jsr_dependencies: "@cross/test @std/assert @cross/runtime @cross/utils @std/path @cross/env"
node_ci:
uses: cross-org/workflows/.github/workflows/node-ci.yml@main
with:
jsr_dependencies: "@cross/test @std/assert @cross/runtime @cross/utils @std/path @cross/env"
test_target: "test/**/*.test.ts" # Optional
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,31 @@ class ManagerTemplate {
* steps needed to finish the installation, such as `sudo systemctl daemon-reload`.
* generateConfig do only output the base configuration file.
*/
async install(config: InstallServiceOptions, onlyGenerate: boolean) {
// TODO: Implement this method for the target init system.
async install(config: InstallServiceOptions, onlyGenerate: boolean): Promise<InstallServiceOptions> {
/*
* ToDo: Implement this method for the target init system.
*
return {
servicePath,
serviceFileContent,
manualSteps: null,
}; */
throw new Error("Not implemented");
}

/**
* Uninstalls the service based on the given options.
* @param config - The configuration options for uninstalling the service.
*/
async uninstall(config: UninstallServiceOptions) {
// TODO: Implement this method for the target init system.
async uninstall(config: UninstallServiceOptions): Promise<UninstallServiceOptions> {
/*
* TODO: Implement this method for the target init system.
*
return {
pathToServiceFile,
manualSteps: null,
};
*/
throw new Error("Not implemented");
}
}
Expand Down
13 changes: 8 additions & 5 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"name": "@cross/service",
"version": "1.0.0-rc.1",
"version": "1.0.0-rc.2",
"fmt": {
"lineWidth": 200
},
"tasks": {
"check": "deno fmt && deno lint && deno check service.ts && deno test --allow-read --allow-write --allow-env --allow-net"
},
"imports": {
"@cross/env": "jsr:@cross/env@^0.2.7",
"@cross/runtime": "jsr:@cross/runtime@^0.0.17",
"@cross/test": "jsr:@cross/test@^0.0.8",
"@cross/utils": "jsr:@cross/utils@^0.6.1",
"@cross/env": "jsr:@cross/env@^1.0.0",
"@cross/runtime": "jsr:@cross/runtime@^1.0.0",
"@cross/test": "jsr:@cross/test@^0.0.9",
"@cross/utils": "jsr:@cross/utils@^0.8.2",
"@std/assert": "jsr:@std/assert@^0.220.1",
"@std/path": "jsr:@std/path@^0.220.1"
},
"publish": {
"exclude": [".github", "*.test.ts"]
},
"exports": {
".": "./mod.ts",
"./install": "./service.ts"
Expand Down
14 changes: 13 additions & 1 deletion lib/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ import { ArgsParser } from "@cross/utils/args";
* @returns - A parsed object containing the command line arguments.
*/
function parseArguments(args: string[]): ArgsParser {
return new ArgsParser(args);
const aliases = {
"help": "h",
"system": "s",
"name": "n",
"cwd": "w",
"cmd": "c",
"user": "u",
"home": "H",
"force": "f",
"path": "p",
"env": "e",
};
return new ArgsParser(args, { aliases });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function main(inputArgs: string[]) {
}

// Handle arguments
const system = args.get("system") as boolean;
const system = args.getBoolean("system");
const name = args.get("name") as string;
const cmd = (args.get("cmd") || args.getRest()) as string;
const cwd = args.get("cwd") as string | undefined;
Expand Down
66 changes: 38 additions & 28 deletions lib/managers/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { InstallServiceOptions, UninstallServiceOptions } from "../service.ts";
import { getEnv } from "@cross/env";
import { join } from "@std/path";
import { mkdtemp, writeFile } from "node:fs/promises";
import { exit } from "@cross/utils";
import { ServiceInstallResult, ServiceUninstallResult } from "../result.ts";

const initScriptTemplate = `#!/bin/sh
### BEGIN INIT INFO
Expand Down Expand Up @@ -90,54 +90,64 @@ class InitService {
return initScriptContent;
}

async install(config: InstallServiceOptions, onlyGenerate: boolean) {
async install(config: InstallServiceOptions, onlyGenerate: boolean): Promise<ServiceInstallResult> {
const initScriptPath = `/etc/init.d/${config.name}`;

if (await exists(initScriptPath)) {
console.error(`Service '${config.name}' already exists in '${initScriptPath}'. Exiting.`);
exit(1);
throw new Error(`Service '${config.name}' already exists in '${initScriptPath}'.`);
}

const initScriptContent = this.generateConfig(config);

if (onlyGenerate) {
console.log("\nThis is a dry-run, nothing will be written to disk or installed.");
console.log("\nPath: ", initScriptPath);
console.log("\nConfiguration:\n");
console.log(initScriptContent);
return {
servicePath: initScriptPath,
serviceFileContent: initScriptContent,
manualSteps: null,
};
} else {
// Store temporary file
const tempFilePathDir = await mkdtemp("svcinstall");
const tempFilePath = join(tempFilePathDir, "svc-init");
await writeFile(tempFilePath, initScriptContent);

console.log("\nThe service installer does not have (and should not have) root permissions, so the next steps have to be carried out manually.");
console.log(`\nStep 1: The init script has been saved to a temporary file, copy this file to the correct location using the following command:`);
console.log(`\n sudo cp ${tempFilePath} ${initScriptPath}`);
console.log(`\nStep 2: Make the script executable:`);
console.log(`\n sudo chmod +x ${initScriptPath}`);
console.log(`\nStep 3: Enable the service to start at boot:`);
console.log(`\n sudo update-rc.d ${config.name} defaults`);
console.log(`\nStep 4: Start the service now`);
console.log(`\n sudo service ${config.name} start`);
let manualSteps = "";
manualSteps += "\nThe service installer does not have (and should not have) root permissions, so the next steps have to be carried out manually.";
manualSteps += `\nStep 1: The init script has been saved to a temporary file, copy this file to the correct location using the following command:`;
manualSteps += `\n sudo cp ${tempFilePath} ${initScriptPath}`;
manualSteps += `\nStep 2: Make the script executable:`;
manualSteps += `\n sudo chmod +x ${initScriptPath}`;
manualSteps += `\nStep 3: Enable the service to start at boot:`;
manualSteps += `\n sudo update-rc.d ${config.name} defaults`;
manualSteps += `\nStep 4: Start the service now`;
manualSteps += `\n sudo service ${config.name} start`;
return {
servicePath: tempFilePath,
serviceFileContent: initScriptContent,
manualSteps,
};
}
}

async uninstall(config: UninstallServiceOptions) {
async uninstall(config: UninstallServiceOptions): Promise<ServiceUninstallResult> {
const initScriptPath = `/etc/init.d/${config.name}`;

if (!await exists(initScriptPath)) {
console.error(`Service '${config.name}' does not exist in '${initScriptPath}'. Exiting.`);
exit(1);
throw new Error(`Service '${config.name}' does not exist in '${initScriptPath}'.`);
}

console.log("The uninstaller does not have (and should not have) root permissions, so the next steps have to be carried out manually.");
console.log(`\nStep 1: Stop the service (if it's running):`);
console.log(`\n sudo service ${config.name} stop`);
console.log(`\nStep 2: Disable the service from starting at boot:`);
console.log(`\n sudo update-rc.d -f ${config.name} remove`);
console.log(`\nStep 3: Remove the init script:`);
console.log(`\n sudo rm ${initScriptPath}`);
let manualSteps = "";
manualSteps += "The uninstaller does not have (and should not have) root permissions, so the next steps have to be carried out manually.";
manualSteps += `\nStep 1: Stop the service (if it's running):`;
manualSteps += `\n sudo service ${config.name} stop`;
manualSteps += `\nStep 2: Disable the service from starting at boot:`;
manualSteps += `\n sudo update-rc.d -f ${config.name} remove`;
manualSteps += `\nStep 3: Remove the init script:`;
manualSteps += `\n sudo rm ${initScriptPath}`;

return {
servicePath: initScriptPath,
manualSteps,
};
}
}

Expand Down
Loading

0 comments on commit 0443bbb

Please sign in to comment.