all exports work
parent
78b71d0fbc
commit
8dd57227b3
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
/node_modules/
|
||||
/coverage/
|
|
@ -0,0 +1,5 @@
|
|||
tests/
|
||||
test/
|
||||
*.test.js
|
||||
testing/
|
||||
example/
|
|
@ -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)})
|
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Watcher for Restart of Code Changes
|
||||
|
||||
[Path]
|
||||
PathModified=/opt/light/name-device-DE4Y
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
[Unit]
|
||||
Description=Watcher for Restart of Code Changes
|
||||
[Path]
|
||||
PathModified=/opt/light/busRelays-i2cbus-X1D3
|
||||
[Install]
|
||||
WantedBy=default.target
|
|
@ -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
|
|
@ -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 }
|
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue