@sequencemedia/minimserver 0.1.27 → 1.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{app.js → app.mjs} +16 -14
- package/babel.config.cjs +21 -0
- package/package.json +16 -29
- package/src/{index.js → index.mjs} +16 -10
- package/babel.config.js +0 -35
- package/lib/index.js +0 -1
package/{app.js → app.mjs}
RENAMED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import 'dotenv/config'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import debug from 'debug'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import {
|
|
8
|
+
readFile
|
|
9
|
+
} from 'fs/promises'
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
execute
|
|
11
|
-
} = require('./lib')
|
|
11
|
+
import psList from 'ps-list'
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
import commander from 'commander'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import execute from '#minimserver'
|
|
16
16
|
|
|
17
|
-
const log = debug('minimserver')
|
|
17
|
+
const log = debug('@sequencemedia/minimserver')
|
|
18
18
|
|
|
19
19
|
log('`minimserver` is awake')
|
|
20
20
|
|
|
@@ -22,6 +22,8 @@ const NAME = 'ms.App'
|
|
|
22
22
|
process.title = NAME
|
|
23
23
|
|
|
24
24
|
async function app () {
|
|
25
|
+
const PACKAGE = JSON.parse(await readFile('./package.json', 'utf8'))
|
|
26
|
+
|
|
25
27
|
const {
|
|
26
28
|
name
|
|
27
29
|
} = PACKAGE
|
|
@@ -42,14 +44,14 @@ async function app () {
|
|
|
42
44
|
pid
|
|
43
45
|
} = a.find(({ pid }) => pid !== PID)
|
|
44
46
|
|
|
45
|
-
const log = debug('minimserver:process:log')
|
|
47
|
+
const log = debug('@sequencemedia/minimserver:process:log')
|
|
46
48
|
|
|
47
49
|
log(`Killing application "${name}" in process ${pid}.`)
|
|
48
50
|
|
|
49
51
|
process.kill(pid)
|
|
50
52
|
}
|
|
51
53
|
} catch ({ message }) {
|
|
52
|
-
const error = debug('minimserver:process:error')
|
|
54
|
+
const error = debug('@sequencemedia/minimserver:process:error')
|
|
53
55
|
|
|
54
56
|
error(message)
|
|
55
57
|
return
|
|
@@ -88,7 +90,7 @@ async function app () {
|
|
|
88
90
|
code
|
|
89
91
|
} = e
|
|
90
92
|
|
|
91
|
-
const error = debug('minimserver:commander:error')
|
|
93
|
+
const error = debug('@sequencemedia/minimserver:commander:error')
|
|
92
94
|
|
|
93
95
|
if (code !== 'commander.missingMandatoryOptionValue') error(e)
|
|
94
96
|
|
|
@@ -115,10 +117,10 @@ async function app () {
|
|
|
115
117
|
try {
|
|
116
118
|
await execute(origin, destination, server, ignore, bounce)
|
|
117
119
|
} catch ({ message }) {
|
|
118
|
-
const error = debug('minimserver:execute:error')
|
|
120
|
+
const error = debug('@sequencemedia/minimserver:execute:error')
|
|
119
121
|
|
|
120
122
|
error(message)
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
export default app()
|
package/babel.config.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const presets = [
|
|
2
|
+
[
|
|
3
|
+
'@babel/env',
|
|
4
|
+
{
|
|
5
|
+
targets: {
|
|
6
|
+
node: 'current'
|
|
7
|
+
},
|
|
8
|
+
useBuiltIns: 'usage',
|
|
9
|
+
corejs: 3
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
const plugins = []
|
|
15
|
+
|
|
16
|
+
module.exports = {
|
|
17
|
+
compact: true,
|
|
18
|
+
comments: false,
|
|
19
|
+
presets,
|
|
20
|
+
plugins
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/minimserver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.27",
|
|
4
4
|
"description": "Watch for changes to M3Us and rescan MinimServer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"minimserver",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"m3u",
|
|
15
15
|
"m3u8"
|
|
16
16
|
],
|
|
17
|
-
"main": "./app.
|
|
17
|
+
"main": "./app.mjs",
|
|
18
18
|
"author": "Jonathan Perry for Sequence Media Limited <sequencemedia@sequencemedia.net>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"engines": {
|
|
@@ -29,49 +29,36 @@
|
|
|
29
29
|
"url": "https://github.com/sequencemedia/minimserver/issues"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"build:watch": "npm run babel:watch",
|
|
34
|
-
"clean": "rimraf lib",
|
|
35
|
-
"babel": "babel src -d lib",
|
|
36
|
-
"babel:watch": "npm run babel -- -w",
|
|
37
|
-
"lint": "eslint .",
|
|
32
|
+
"lint": "eslint . --ext .mjs --ext .cjs",
|
|
38
33
|
"lint:fix": "npm run lint -- --fix",
|
|
39
|
-
"start": "cross-env DEBUG
|
|
40
|
-
"
|
|
41
|
-
"prepublishOnly": "npm run build",
|
|
42
|
-
"prebuild": "npm run clean"
|
|
34
|
+
"start": "cross-env DEBUG=@sequencemedia/minimserver* NODE_ENV=production node .",
|
|
35
|
+
"dev": "cross-env DEBUG=@sequencemedia/minimserver* NODE_ENV=development node ."
|
|
43
36
|
},
|
|
44
37
|
"dependencies": {
|
|
45
|
-
"@babel/runtime": "^7.16.3",
|
|
46
38
|
"anymatch": "^3.1.2",
|
|
47
39
|
"chokidar": "^3.5.2",
|
|
48
40
|
"commander": "^8.3.0",
|
|
49
41
|
"cross-env": "^7.0.3",
|
|
50
|
-
"debug": "^4.3.
|
|
42
|
+
"debug": "^4.3.3",
|
|
51
43
|
"del": "^6.0.0",
|
|
52
44
|
"dotenv": "^10.0.0",
|
|
53
45
|
"fs-extra": "^10.0.0",
|
|
54
|
-
"ps-list": "
|
|
55
|
-
"supports-color": "^9.1
|
|
46
|
+
"ps-list": "^8.0.0",
|
|
47
|
+
"supports-color": "^9.2.1"
|
|
56
48
|
},
|
|
57
49
|
"devDependencies": {
|
|
58
50
|
"@babel/cli": "^7.16.0",
|
|
59
|
-
"@babel/core": "^7.16.
|
|
60
|
-
"@babel/eslint-parser": "^7.16.
|
|
61
|
-
"@babel/
|
|
62
|
-
"
|
|
63
|
-
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
64
|
-
"@babel/preset-env": "^7.16.4",
|
|
65
|
-
"@babel/register": "^7.16.0",
|
|
66
|
-
"babel-plugin-module-resolver": "^4.1.0",
|
|
67
|
-
"babel-plugin-syntax-async-functions": "^6.13.0",
|
|
68
|
-
"core-js": "^3.19.1",
|
|
51
|
+
"@babel/core": "^7.16.5",
|
|
52
|
+
"@babel/eslint-parser": "^7.16.5",
|
|
53
|
+
"@babel/preset-env": "^7.16.5",
|
|
54
|
+
"core-js": "^3.20.1",
|
|
69
55
|
"eslint": "7.32.0",
|
|
70
56
|
"eslint-config-standard": "^16.0.3",
|
|
71
|
-
"eslint-import-resolver-babel-module": "^5.3.1",
|
|
72
57
|
"eslint-plugin-import": "^2.25.3",
|
|
73
58
|
"eslint-plugin-node": "^11.1.0",
|
|
74
|
-
"eslint-plugin-promise": "
|
|
75
|
-
|
|
59
|
+
"eslint-plugin-promise": "5.2.0"
|
|
60
|
+
},
|
|
61
|
+
"imports": {
|
|
62
|
+
"#minimserver": "./src/index.mjs"
|
|
76
63
|
}
|
|
77
64
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import debug from 'debug'
|
|
2
|
+
|
|
1
3
|
import os from 'os'
|
|
2
4
|
import path from 'path'
|
|
3
5
|
import {
|
|
4
6
|
exec
|
|
5
7
|
} from 'child_process'
|
|
6
8
|
|
|
7
|
-
import
|
|
8
|
-
ensureDir,
|
|
9
|
-
ensureFile
|
|
10
|
-
} from 'fs-extra'
|
|
9
|
+
import fsExtra from 'fs-extra'
|
|
11
10
|
|
|
12
11
|
import {
|
|
13
12
|
stat,
|
|
@@ -18,10 +17,13 @@ import chokidar from 'chokidar'
|
|
|
18
17
|
import anymatch from 'anymatch'
|
|
19
18
|
import del from 'del'
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
const {
|
|
21
|
+
ensureDir,
|
|
22
|
+
ensureFile
|
|
23
|
+
} = fsExtra
|
|
22
24
|
|
|
23
|
-
const error = debug('minimserver:error')
|
|
24
|
-
const log = debug('minimserver')
|
|
25
|
+
const error = debug('@sequencemedia/minimserver:error')
|
|
26
|
+
const log = debug('@sequencemedia/minimserver')
|
|
25
27
|
|
|
26
28
|
log('`minimserver` is awake')
|
|
27
29
|
|
|
@@ -49,7 +51,9 @@ export async function removeAllM3UFromDestinationDir (path) {
|
|
|
49
51
|
/**
|
|
50
52
|
* log('removeAllM3UFromDestinationDir')
|
|
51
53
|
*/
|
|
52
|
-
return
|
|
54
|
+
return (
|
|
55
|
+
await del(path, { force: true })
|
|
56
|
+
)
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
export function ensureDestinationDir (path) {
|
|
@@ -192,7 +196,9 @@ export function removeFactory (origin, destination) {
|
|
|
192
196
|
log('remove', to)
|
|
193
197
|
|
|
194
198
|
try {
|
|
195
|
-
return
|
|
199
|
+
return (
|
|
200
|
+
await del(to, { force: true })
|
|
201
|
+
)
|
|
196
202
|
} catch ({ message }) {
|
|
197
203
|
error(message)
|
|
198
204
|
}
|
|
@@ -345,7 +351,7 @@ export function ignorePatternFactory (ignore) {
|
|
|
345
351
|
}
|
|
346
352
|
}
|
|
347
353
|
|
|
348
|
-
export async function execute (
|
|
354
|
+
export default async function execute (
|
|
349
355
|
origin = '.',
|
|
350
356
|
destination = '.',
|
|
351
357
|
server = 'http://0.0.0.0:9790',
|
package/babel.config.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const presets = [
|
|
2
|
-
[
|
|
3
|
-
'@babel/env',
|
|
4
|
-
{
|
|
5
|
-
useBuiltIns: 'usage',
|
|
6
|
-
targets: {
|
|
7
|
-
node: 'current'
|
|
8
|
-
},
|
|
9
|
-
corejs: 3
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
const plugins = [
|
|
15
|
-
'@babel/transform-runtime',
|
|
16
|
-
'@babel/proposal-export-default-from',
|
|
17
|
-
'@babel/proposal-export-namespace-from',
|
|
18
|
-
'syntax-async-functions',
|
|
19
|
-
[
|
|
20
|
-
'module-resolver', {
|
|
21
|
-
root: ['./src'],
|
|
22
|
-
cwd: 'babelrc',
|
|
23
|
-
alias: {
|
|
24
|
-
'~': './src'
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
module.exports = {
|
|
31
|
-
compact: true,
|
|
32
|
-
comments: false,
|
|
33
|
-
presets,
|
|
34
|
-
plugins
|
|
35
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.changeFactory=changeFactory;exports.createFactory=createFactory;exports.ensureDestinationDir=ensureDestinationDir;exports.ensureDestinationM3U=ensureDestinationM3U;exports.execute=execute;exports.exit=exit;exports.ignorePatternFactory=ignorePatternFactory;exports.queueRelaunchFactory=queueRelaunchFactory;exports.queueRescanFactory=queueRescanFactory;exports.queueRestartFactory=queueRestartFactory;exports.relaunch=relaunch;exports.removeAllM3UFromDestinationDir=removeAllM3UFromDestinationDir;exports.removeFactory=removeFactory;exports.rescan=rescan;exports.restart=restart;var _os=_interopRequireDefault(require("os"));var _path=_interopRequireDefault(require("path"));var _child_process=require("child_process");var _fsExtra=require("fs-extra");var _promises=require("fs/promises");var _chokidar=_interopRequireDefault(require("chokidar"));var _anymatch=_interopRequireDefault(require("anymatch"));var _del=_interopRequireDefault(require("del"));var _debug=_interopRequireDefault(require("debug"));const error=(0,_debug.default)('minimserver:error');const log=(0,_debug.default)('minimserver');log('`minimserver` is awake');async function originDirExists(path){try{await(0,_promises.stat)(path);return true;}catch(e){const{code}=e;if(code!=='ENOENT'){const{message}=e;error(message);}return false;}}async function removeAllM3UFromDestinationDir(path){return await(0,_del.default)(path,{force:true});}function ensureDestinationDir(path){return new Promise((resolve,reject)=>{(0,_fsExtra.ensureDir)(path,e=>!e?resolve():reject(e));});}function ensureDestinationM3U(filePath){return new Promise((resolve,reject)=>{(0,_fsExtra.ensureFile)(filePath,e=>!e?resolve():reject(e));});}function rescan(server){return new Promise((resolve,reject)=>{(0,_child_process.exec)(`curl -X POST -H "Content-Type: text/plain" ${server} -d rescan`,(e,r)=>!e?resolve(r):reject(e));});}function restart(server){return new Promise((resolve,reject)=>{(0,_child_process.exec)(`curl -X POST -H "Content-Type: text/plain" ${server} -d restart`,(e,r)=>!e?resolve(r):reject(e));});}function relaunch(server){return new Promise((resolve,reject)=>{(0,_child_process.exec)(`curl -X POST -H "Content-Type: text/plain" ${server} -d relaunch`,(e,r)=>!e?resolve(r):reject(e));});}function exit(server){return new Promise((resolve,reject)=>{(0,_child_process.exec)(`curl -X POST -H "Content-Type: text/plain" ${server} -d exit`,(e,r)=>!e?resolve(r):reject(e));});}function createFactory(origin,destination){return async function create(filePath){const to=filePath.replace(origin,destination);log('create',to);try{await ensureDestinationM3U(to);return await(0,_promises.copyFile)(filePath,to);}catch(e){const{code}=e;if(code==='ENOENT'){error(`ENOENT in create for "${filePath}"`);}else{const{message}=e;error(message);}}};}function changeFactory(origin,destination){return async function change(filePath){const to=filePath.replace(origin,destination);log('change',to);try{await ensureDestinationM3U(to);return await(0,_promises.copyFile)(filePath,to);}catch(e){const{code}=e;if(code==='ENOENT'){error(`ENOENT in change for "${filePath}"`);}else{const{message}=e;error(message);}}};}function removeFactory(origin,destination){return async function remove(filePath){const to=filePath.replace(origin,destination);log('remove',to);try{return await(0,_del.default)(to,{force:true});}catch({message}){error(message);}};}function queueRescanFactory(server,bounce){let t=null;let x=null;let y=null;return function enqueue(){if(t){clearTimeout(t);if(x){y=true;return;}}t=setTimeout(async function dequeue(){x=true;try{const response=await rescan(server);log(response.trim());t=null;x=null;if(y){y=null;enqueue();}}catch({message}){error(message);}},bounce);};}function queueRestartFactory(server,bounce){let t=null;let x=null;let y=null;return function enqueue(){if(t){clearTimeout(t);if(x){y=true;return;}}t=setTimeout(async function dequeue(){x=true;try{const response=await restart(server);log(response.trim());t=null;x=null;if(y){y=null;enqueue();}}catch({message}){error(message);}},bounce);};}function queueRelaunchFactory(server,bounce){let t=null;let x=null;let y=null;return function enqueue(){if(t){clearTimeout(t);if(x){y=true;return;}}t=setTimeout(async function dequeue(){x=true;try{const response=await relaunch(server);log(response.trim());t=null;x=null;if(y){y=null;enqueue();}}catch({message}){error(message);}},bounce);};}function ignorePatternFactory(ignore){const ignorePatterns=ignore.split(',');return function ignorePattern(filePath){return /(^|[/\\])\../.test(filePath)||(0,_anymatch.default)(ignorePatterns,filePath);};}async function execute(origin='.',destination='.',server='http://0.0.0.0:9790',ignore='',bounce=60000){let watcher;try{const o=_path.default.resolve(origin.replace('~',_os.default.homedir));if(!(await originDirExists(o)))throw new Error(`Origin "${origin}" does not exist.`);const d=_path.default.resolve(destination.replace('~',_os.default.homedir));const ignorePattern=ignorePatternFactory(ignore);watcher=_chokidar.default.watch(o,{ignored:ignorePattern});const create=createFactory(o,d);const change=changeFactory(o,d);const remove=removeFactory(o,d);await ensureDestinationDir(d);await removeAllM3UFromDestinationDir(d);const queueRescan=queueRescanFactory(server,bounce);watcher.on('add',async function handleAdd(filePath){try{await create(filePath);queueRescan();}catch({message}){error(message);}}).on('change',async function handleChange(filePath){try{await change(filePath);queueRescan();}catch({message}){error(message);}}).on('unlink',async function handleUnlink(filePath){try{await remove(filePath);queueRescan();}catch({message}){error(message);}}).on('error',function handleError({message}){error(`Error in watcher: "${message}"`);});queueRescan();}catch({message}){if(watcher)watcher.close();error(message);}}
|