From 2f4df627d97a9dac57ffe02bbae4fd1fa80e7c0c Mon Sep 17 00:00:00 2001 From: chyzwar Date: Fri, 20 Sep 2024 19:53:34 +0200 Subject: [PATCH 1/3] chore(deps): update deps --- .github/workflows/checks.yaml | 8 +++--- .github/workflows/publish.yaml | 18 ++++++++------ package.json | 4 +-- packages/conf/package.json | 2 +- packages/ctl/package.json | 2 +- yarn.lock | 45 ++++++++++++++++++++-------------- 6 files changed, 45 insertions(+), 34 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index c12b88d..dce52c1 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -12,7 +12,7 @@ jobs: - name: "Checkout" uses: actions/checkout@v4 - - name: "Use NodeJS 22" + - name: "Setup NodeJS 22" uses: actions/setup-node@v4 with: node-version: '22' @@ -21,11 +21,11 @@ jobs: - name: Install run: yarn install - - name: Run build + - name: Build run: yarn build - - name: Run test + - name: Test run: yarn test - - name: Run lint + - name: Lint run: yarn lint diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 6cc44a2..fbc5bc7 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -32,7 +32,7 @@ jobs: with: fetch-depth: 0 - - name: "Use NodeJS 22" + - name: "Setup NodeJS 22" uses: actions/setup-node@v4 with: node-version: '22' @@ -42,24 +42,26 @@ jobs: - name: Install run: yarn install - - name: Run build + - name: Build run: yarn build - - name: Run test + - name: Test run: yarn test - - name: Run lint + - name: Lint run: yarn lint + - name: Setup git user + run: | + echo "Setup git user to github action user" + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor}}@users.noreply.github.com" + - name: "Version and publish" env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # Setup git user for lerna publish - git config --global user.name "${{ github.actor }}" - git config --global user.email "${{ github.actor }}@users.noreply.github.com" - echo "Version" yarn lerna version \ --conventional-commits \ diff --git a/package.json b/package.json index 44b6434..83bb658 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "@lerna-lite/publish": "^3.9.1", "@lerna-lite/version": "^3.9.1", "@types/node": "^22.5.5", - "conventional-changelog-conventionalcommits": "^7.0.2", - "eslint": "^9.10.0", + "conventional-changelog-conventionalcommits": "^8.0.0", + "eslint": "^9.11.0", "husky": "^9.1.6", "lint-staged": "^15.2.10", "ts-node": "^10.9.2", diff --git a/packages/conf/package.json b/packages/conf/package.json index 0565012..3edf3dc 100644 --- a/packages/conf/package.json +++ b/packages/conf/package.json @@ -39,7 +39,7 @@ "@chyzwar/eslint-config": "^0.2.29", "@chyzwar/tsconfig": "^0.2.29", "@types/node": "^22.5.5", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "typescript": "^5.6.2", "vitest": "^2.1.1" } diff --git a/packages/ctl/package.json b/packages/ctl/package.json index 148ea37..458100b 100644 --- a/packages/ctl/package.json +++ b/packages/ctl/package.json @@ -37,7 +37,7 @@ "@chyzwar/eslint-config": "^0.2.29", "@chyzwar/tsconfig": "^0.2.29", "@types/node": "^22.5.5", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "typescript": "^5.6.2", "vitest": "^2.1.1" } diff --git a/yarn.lock b/yarn.lock index 291120f..b4e086a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -464,10 +464,10 @@ __metadata: languageName: node linkType: hard -"@eslint/js@npm:9.10.0, @eslint/js@npm:^9.9.1": - version: 9.10.0 - resolution: "@eslint/js@npm:9.10.0" - checksum: 10c2/60f81dc817cd165960eb3bf810cf4785abd0cd9f36a0cffbc4d5a0c897d515045736a544e1f8b220adf459b6237c1cf22b10673e4e0fb56f5cc08517be670f2d +"@eslint/js@npm:9.11.0, @eslint/js@npm:^9.9.1": + version: 9.11.0 + resolution: "@eslint/js@npm:9.11.0" + checksum: 10c2/22a280f93df3c9052bbcb2a61938079c6204405f3bd256a5cf0d044b1da4a562619b642ecd6115a121a94488294bc7b36bcd883544e9dccb449c9975084faf6e languageName: node linkType: hard @@ -478,12 +478,12 @@ __metadata: languageName: node linkType: hard -"@eslint/plugin-kit@npm:^0.1.0": - version: 0.1.0 - resolution: "@eslint/plugin-kit@npm:0.1.0" +"@eslint/plugin-kit@npm:^0.2.0": + version: 0.2.0 + resolution: "@eslint/plugin-kit@npm:0.2.0" dependencies: levn: "npm:^0.4.1" - checksum: 10c2/c2d1a6af6fc6acb9177b99604c2ebeb0195a368741db17c61d1b0941cc09180ed375488ae06a94cb37663eea7b5f49a340135523cd58237be8b9bcc378fe683c + checksum: 10c2/ecf7557508c87d894392fb16e399647c74b36a9ce4412b3eb21f702eab5eca2c32db6c27e93cd2bccc7fbd27dbf2933695001496a3a2651fc02d3a8e68e28186 languageName: node linkType: hard @@ -1360,7 +1360,7 @@ __metadata: "@chyzwar/eslint-config": "npm:^0.2.29" "@chyzwar/tsconfig": "npm:^0.2.29" "@types/node": "npm:^22.5.5" - eslint: "npm:^9.10.0" + eslint: "npm:^9.11.0" typescript: "npm:^5.6.2" vitest: "npm:^2.1.1" zod: "npm:^3.23.8" @@ -1375,7 +1375,7 @@ __metadata: "@chyzwar/tsconfig": "npm:^0.2.29" "@systemd-js/conf": "npm:^0.4.0" "@types/node": "npm:^22.5.5" - eslint: "npm:^9.10.0" + eslint: "npm:^9.11.0" typescript: "npm:^5.6.2" vitest: "npm:^2.1.1" languageName: unknown @@ -1392,8 +1392,8 @@ __metadata: "@lerna-lite/publish": "npm:^3.9.1" "@lerna-lite/version": "npm:^3.9.1" "@types/node": "npm:^22.5.5" - conventional-changelog-conventionalcommits: "npm:^7.0.2" - eslint: "npm:^9.10.0" + conventional-changelog-conventionalcommits: "npm:^8.0.0" + eslint: "npm:^9.11.0" husky: "npm:^9.1.6" lint-staged: "npm:^15.2.10" ts-node: "npm:^10.9.2" @@ -2236,6 +2236,15 @@ __metadata: languageName: node linkType: hard +"conventional-changelog-conventionalcommits@npm:^8.0.0": + version: 8.0.0 + resolution: "conventional-changelog-conventionalcommits@npm:8.0.0" + dependencies: + compare-func: "npm:^2.0.0" + checksum: 10c2/767b40c4d56d71939d9e46148c21d7bae7fb155d21effbbfa46b7ce4e21261f045175267e0626546a002eda6f6d6575524db9a3cf1288f1bdf1214ec1fbbe242 + languageName: node + linkType: hard + "conventional-changelog-core@npm:^7.0.0": version: 7.0.0 resolution: "conventional-changelog-core@npm:7.0.0" @@ -2686,16 +2695,16 @@ __metadata: languageName: node linkType: hard -"eslint@npm:^9.10.0": - version: 9.10.0 - resolution: "eslint@npm:9.10.0" +"eslint@npm:^9.11.0": + version: 9.11.0 + resolution: "eslint@npm:9.11.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.2.0" "@eslint-community/regexpp": "npm:^4.11.0" "@eslint/config-array": "npm:^0.18.0" "@eslint/eslintrc": "npm:^3.1.0" - "@eslint/js": "npm:9.10.0" - "@eslint/plugin-kit": "npm:^0.1.0" + "@eslint/js": "npm:9.11.0" + "@eslint/plugin-kit": "npm:^0.2.0" "@humanwhocodes/module-importer": "npm:^1.0.1" "@humanwhocodes/retry": "npm:^0.3.0" "@nodelib/fs.walk": "npm:^1.2.8" @@ -2731,7 +2740,7 @@ __metadata: optional: true bin: eslint: bin/eslint.js - checksum: 10c2/502e18ecea3e773c1270b5474de4341a3c6f8f925c3ffda645044c3932c64bac62b808690f59c0762b9f5ae57627c2275b990cb2eaaaa960b60872a9b984c0a1 + checksum: 10c2/715dce02b76ad75236dbaf1d64d0a1de28a8136f4c96fa1e6b90f78204374de5286099d7f316eddf905b4ea10b68b4c7b4c483d7e9db5f12917db7af28f757e0 languageName: node linkType: hard From 0c87eed2b622abeda4c535018156c10ece9b2829 Mon Sep 17 00:00:00 2001 From: chyzwar Date: Fri, 20 Sep 2024 19:58:17 +0200 Subject: [PATCH 2/3] chore(docs): improve docs added badge --- README.md | 101 +++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 250251c..f6c1899 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Systemd.js +![Publish](https://github.com/systemd-js/systemd/actions/workflows/publish.yaml/badge.svg) + Collection of packages useful when interfacing with systemd. ## @systemd-js/conf @@ -19,7 +21,8 @@ yarn add @systemd-js/conf Parse systemd ini file into object. -Note: Ini parser is not fully implemented, lacks support for escaping and quoting. +Note: Ini parser is not fully implemented, lacks support for escaping and +quoting. ```ts import {INI} from "@systemd-js/conf"; @@ -64,7 +67,6 @@ const ini = INI.fromString(unit).toObject(); User: "root", }, }; - ``` Create service unit for ini string and modify service user definition. @@ -88,12 +90,12 @@ PrivateTmp=yes User=root `; -const ini = INI.fromString(unit) -const service = Service.fromINI(ini) +const ini = INI.fromString(unit); +const service = Service.fromINI(ini); service .getServiceSection() - .setUser("test") + .setUser("test"); service.toINIString(); ``` @@ -101,33 +103,33 @@ service.toINIString(); Create service unit using fluent builder ```ts -import {Service} from "@systemd-js/config"; +import { Service } from "@systemd-js/config"; const service = new Service(); service .getUnitSection() - .setDescription("This is a example unit") + .setDescription("This is a example unit"); service .getInstallSection() - .setWantedBy("multi-user.target") - + .setWantedBy("multi-user.target"); + service - .getServiceSection() - .setType("simple") - .setWorkingDirectory("/tmp") - .setRestart("always") - .setExecStartPre("/usr/bin/echo 'Before'") - .setExecStart("/usr/bin/echo 'Hello World'") - .setExecStartPost("/usr/bin/echo 'After'") + .getServiceSection() + .setType("simple") + .setWorkingDirectory("/tmp") + .setRestart("always") + .setExecStartPre("/usr/bin/echo 'Before'") + .setExecStart("/usr/bin/echo 'Hello World'") + .setExecStartPost("/usr/bin/echo 'After'"); ``` Create timer unit using fluent builder ```ts -import {Timer} from "@systemd-js/config"; -const timer = new Timer() +import { Timer } from "@systemd-js/config"; +const timer = new Timer(); timer .getUnitSection() @@ -136,7 +138,7 @@ timer timer .getInstallSection() - .setWantedBy("multi-user.target"); + .setWantedBy("multi-user.target"); timer .getTimerSection() @@ -146,8 +148,8 @@ timer ## @systemd-js/ctl -Control over units. Interface to systemctl. -At the moment this lack proper error handling. +Control over units. Interface to systemctl. At the moment this lack proper error +handling. ### Installation @@ -160,57 +162,54 @@ yarn add @systemd-js/ctl State manipulation of existing service. ```ts -import {Ctl} from "@systemd-js/ctl"; - -const ctl = new Ctl("test.service") +import { Ctl } from "@systemd-js/ctl"; -ctl.disable() -ctl.enable() -ctl.stop() -ctl.start() -ctl.restart() +const ctl = new Ctl("test.service"); +ctl.disable(); +ctl.enable(); +ctl.stop(); +ctl.start(); +ctl.restart(); ``` Creation of new service "example.service" ```ts -import {Service} from "@systemd-js/config"; -import {Ctl} from "@systemd-js/ctl"; +import { Service } from "@systemd-js/config"; +import { Ctl } from "@systemd-js/ctl"; const service = new Service(); service .getUnitSection() - .setDescription("This is a example unit") + .setDescription("This is a example unit"); service .getInstallSection() - .setWantedBy("multi-user.target") - -service - .getServiceSection() - .setType("simple") - .setExecStart("/usr/bin/echo 'Hello World'") + .setWantedBy("multi-user.target"); -const ctl = new Ctl("example", service) +service + .getServiceSection() + .setType("simple") + .setExecStart("/usr/bin/echo 'Hello World'"); -ctl.create() -ctl.enable() -ctl.start() +const ctl = new Ctl("example", service); +ctl.create(); +ctl.enable(); +ctl.start(); ``` In addition to `Ctl` class, package expose functions to call systemctl directly. ```ts -import {restart, start, stop} from "@systemd-js/ctl"; - -stop("example.service") -start("example.service") -enable("example.service") -disable("example.service") -reload("example.service") -restart("example.service") - +import { restart, start, stop } from "@systemd-js/ctl"; + +stop("example.service"); +start("example.service"); +enable("example.service"); +disable("example.service"); +reload("example.service"); +restart("example.service"); ``` From 8c9b5aaa16a77b10fdcc4d913df638227c1a5110 Mon Sep 17 00:00:00 2001 From: chyzwar Date: Fri, 20 Sep 2024 19:59:53 +0200 Subject: [PATCH 3/3] chore(ctl): added jsdoc in ctl get unit --- packages/ctl/src/ctl.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/ctl/src/ctl.ts b/packages/ctl/src/ctl.ts index fe7a65f..19dc8d8 100644 --- a/packages/ctl/src/ctl.ts +++ b/packages/ctl/src/ctl.ts @@ -30,6 +30,9 @@ const getPath = (name: string, type: string) => { : `/etc/containers/systemd/${name}.${type}`; }; +/** + * Create Unit from filesystem + */ function getUnit(unitName: string, type: string = getType(unitName)): Unit | undefined { const name = getName(unitName); const path = `/etc/systemd/system/${name}.${type}`;