all exports work

master
David Kebler 2020-01-01 20:56:23 -08:00
parent 78b71d0fbc
commit 8dd57227b3
10 changed files with 154 additions and 0 deletions

37
.eslintrc.js Normal file
View File

@ -0,0 +1,37 @@
module.exports = {
"ecmaFeatures": {
"modules": true,
"spread" : true,
"restParams" : true
},
// "plugins": [
// "unicorn"
// ],
"env": {
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
// "unicorn/no-array-instanceof": "error",
"no-console": 0,
"semi": ["error", "never"],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
]
}
}

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules/
/coverage/

5
.npmignore Normal file
View File

@ -0,0 +1,5 @@
tests/
test/
*.test.js
testing/
example/

28
example/index.js Normal file
View File

@ -0,0 +1,28 @@
import systemd from '../'
const SERVICE = 'uci.service'
const PATH = 'uci.path'
const DEST = '/opt/light'
const NAME = 'name-device-DE4Y'
;
(async () => {
let settings= await systemd.read('./example/'+SERVICE)
.catch(err => {throw err})
settings.Service.WorkingDirectory=`${DEST}/${NAME}`
console.log(systemd.stringify(settings))
systemd.write(`./example/${NAME}.service`,settings)
settings= await systemd.read('./example/'+PATH)
.catch(err => {throw err})
settings.Path.PathModified=`${DEST}/${NAME}`
console.log(systemd.stringify(settings))
systemd.write(`./example/${NAME}.path`,settings)
})().catch((err) => {console.log('fatal error', err)})

View File

@ -0,0 +1,8 @@
[Unit]
Description=Watcher for Restart of Code Changes
[Path]
PathModified=/opt/light/name-device-DE4Y
[Install]
WantedBy=default.target

View File

@ -0,0 +1,11 @@
[Unit]
Description=I2C Bus
After=network-online.target
[Service]
WorkingDirectory=/opt/light/name-device-DE4Y
ExecStart=/usr/bin/node -r esm index.js
Restart=on-failure
[Install]
WantedBy=default.target

6
example/uci.path Normal file
View File

@ -0,0 +1,6 @@
[Unit]
Description=Watcher for Restart of Code Changes
[Path]
PathModified=/opt/light/busRelays-i2cbus-X1D3
[Install]
WantedBy=default.target

11
example/uci.service Normal file
View File

@ -0,0 +1,11 @@
[Unit]
Description=I2C Bus
After=network-online.target
[Service]
WorkingDirectory=/opt/light/busRelays-i2cbus-X1D3
ExecStart=/usr/bin/node -r esm index.js
Restart=on-failure
[Install]
WantedBy=default.target

24
index.js Normal file
View File

@ -0,0 +1,24 @@
import { promisify } from 'util'
import { readFile as readF, writeFile as writeF } from 'fs'
const readFile = promisify(readF)
const writeFile = promisify(writeF)
import { stringify as toToml } from '@iarna/toml'
import parse from 'xdg-parse'
async function read (file) {
return readFile(file).then( buf => {
try { return parse(buf.toString()) }
catch(error) { return error }
})}
function stringify(obj) {
try { return toToml(obj).replace(/["]/gi,'').replace(/\ = /gi,'=') }
catch(error) { return error }
}
async function write(file,obj) {
return writeFile(file,stringify(obj))
}
export default { read, write, stringify, parse }
export {read, write, stringify, parse }

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "@uci-utils/systemd",
"version": "0.1.1",
"description": "",
"main": "index.js",
"scripts": {
"example": "node -r esm ./example || true",
"dev": "./node_modules/.bin/nodemon -r esm ./example || true"
},
"settings": "https://www.freedesktop.org/software/systemd/man/systemd.service.html",
"docs": "https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files",
"author": "",
"license": "ISC",
"dependencies": {
"@iarna/toml": "^2.2.3",
"xdg-parse": "0.0.2"
},
"devDependencies": {
"esm": "^3.2.6",
"nodemon": "^1.18.10"
}
}