Skip to content

Commit

Permalink
Commit Inicial
Browse files Browse the repository at this point in the history
  • Loading branch information
bibiwatson committed May 30, 2020
0 parents commit 7f58834
Show file tree
Hide file tree
Showing 6 changed files with 402 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Servicio Consola

Crea un servicio de windows mediante la consola


### install
Instala e inicia un nuevo servicio

```
service install -n "Mi Servicio" -d "Mi Descripcion" -s RutaDeScript
```

#### Parámetros
* --name, -n Service name [string] [required]
* --description, -d Service short desc [string]
* --script, -s Script path [string] [required]



### uninstall
Desintala un servicio existente

```
service uninstall -n "Mi Servicio" -s RutaDeScript
```

#### Parámetros
* --name, -n Service name [string] [required]
* --script, -s Script path [string] [required]
208 changes: 208 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "servicio-consola",
"version": "1.0.0",
"description": "Crea servicios de windows",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bibiwatson/servicio-windows.git"
},
"author": "Emma Colorado",
"license": "ISC",
"bugs": {
"url": "https://github.com/bibiwatson/servicio-windows/issues"
},
"homepage": "https://github.com/bibiwatson/servicio-windows#readme",
"dependencies": {
"colors": "^1.4.0",
"readline": "^1.3.0",
"yargs": "^15.3.1"
}
}
27 changes: 27 additions & 0 deletions service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { argv } = require('./yargs.js');
const { CustomService } = require('./service/CustomService');
const wincmd = require('node-windows');


const command = argv._[0];

switch(command){
case 'install':
new CustomService({
name : argv.name,
description : argv.description || '',
script : argv.script || ''
}).install();
break;

case 'uninstall':
new CustomService({
name : argv.name,
script : argv.script || ''
}).uninstall();
break;

default:
console.log('Command not accepted');
break;
}
73 changes: 73 additions & 0 deletions service/CustomService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const Service = require('node-windows').Service;
const colors = require('colors');
const EventLogger = require('node-windows').EventLogger;

class CustomService {
constructor(data){
this.name = data.name;
this.description = data.description || '';
this.script = data.script;

this.log = new EventLogger('');

return this;
}

install() {
this.svc = new Service({
name : this.name,
description : this.description,
script : this.script
});

this.listen();
this.svc.install();
}

uninstall() {
this.svc = new Service({
name : this.name,
script : this.script
});

this.listen();
this.svc.uninstall();
}

listen(){
this.svc.on('install', () => {
console.log('Service is installed'.green);
console.log('Starting service ...'.yellow);

this.svc.start();
});

this.svc.on('alreadyinstalled', () => {
console.log('Service is alreadyinstalled'.yellow)
});

this.svc.on('invalidinstallation', () => {
console.log('Invalid Instalation'.red);
})

this.svc.on('uninstall', () => {
console.log('Service has been uninstalled'.green);
})

this.svc.on('start', () => {
console.log('Service is running'.green);
});

this.svc.on('stop', () => {
console.log('Service has stopped'.yellow);
});

this.svc.on('error', function(err){
this.log.error(err || 'Something went wrong');
})
}
}

module.exports = {
CustomService
}
Loading

0 comments on commit 7f58834

Please sign in to comment.