diff --git a/index.html b/index.html
new file mode 100644
index 0000000..86f8091
--- /dev/null
+++ b/index.html
@@ -0,0 +1,89 @@
+
+
+
+
+ The #!openrc-run generator
+
+
+
+
+ The #!openrc-run generator
+
+
+
+ Paste a systemd service unit here to convert it to openrc
+
+
+
+
+
+
+
+ Supported systemd keys
+
+
+ - Description
+ - Before
+ - After
+ - Requires
+ - Wants
+ - Type (simple, exec, forking and oneshot)
+ - ExecStart
+ - ExecStop
+ - ExecReload
+ - PIDFile
+ - User
+ - Group
+
+ For "simple" and "exec" type:
+
+ - WorkingDirectory
+ - RootDirectory
+ - UMask
+ - Nice
+ - Environment
+ - IOSchedulingClass
+ - IOSchedulingPriority
+ - StandardOutput=file:...
+ - StandardError=file:...
+
+ For "oneshot" and "forking" type:
+
+ - WorkingDirectory
+ - RootDirectory
+ - UMask
+ - Nice
+ - IOSchedulingClass
+ - IOSchedulingPriority
+ - CPUSchedulingPolicy
+ - CPUSchedulingPriority
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..7a9eeaf
--- /dev/null
+++ b/index.js
@@ -0,0 +1,31 @@
+import { convert } from './magic.js'
+
+function convertForBrowser (convertFunction){
+ return function(event){
+ event.preventDefault();
+ const raw = document.getElementById('unit').value;
+
+ const response = convertFunction(raw)
+ const validated = response.validated;
+ const result = response.result;
+ if (validated !== null) {
+ document.getElementById('error').innerHTML = validated;
+ return;
+ } else {
+ document.getElementById('error').innerHTML = '';
+ }
+ document.getElementById('openrc').innerText = result;
+
+ }
+}
+
+function setup(){
+ if(typeof window !== "undefined" && typeof window.document !== "undefined"){
+ const convertFunction = convertForBrowser(convert)
+ document.addEventListener("DOMContentLoaded", function () {
+ document.getElementById('convert').addEventListener('click', convertFunction);
+ });
+ }
+}
+
+setup();
diff --git a/magic.js b/magic.js
index 85f1b54..9982196 100644
--- a/magic.js
+++ b/magic.js
@@ -270,17 +270,10 @@ function generateReload(unit) {
}
-function convert(event) {
- event.preventDefault();
- var raw = document.getElementById('unit').value;
+export function convert(raw) {
var parsed = parseINIString(raw);
var validated = validate(parsed);
- if (validated !== null) {
- document.getElementById('error').innerHTML = validated;
- return;
- } else {
- document.getElementById('error').innerHTML = '';
- }
+
console.log(parsed);
var result = '#!/sbin/openrc-run\n\nname=$RC_SVCNAME\ndescription="' + parsed.Unit.Description + '"\n';
@@ -311,9 +304,12 @@ function convert(event) {
result += generateStop(parsed);
result += generateReload(parsed);
- document.getElementById('openrc').innerText = result;
+ var response = {
+ validated,
+ parsed,
+ result
+ }
+ return response;
}
-document.addEventListener("DOMContentLoaded", function () {
- document.getElementById('convert').addEventListener('click', convert);
-});
\ No newline at end of file
+// This does not run a function like the default
\ No newline at end of file