-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
executable file
·65 lines (52 loc) · 1.92 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
const files = require('./lib/files');
const inquirer = require('./lib/inquirer');
const figlet = require('figlet');
const clear = require('clear');
const chalk = require('chalk');
const fs = require('fs');
const CLI = require('clui')
const Spinner = CLI.Spinner;
const path = require('path');
var exec = require('child_process').exec;
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(stdout); });
};
clear();
console.log(
chalk.yellow(
figlet.textSync('Ontra-Js', { horizontalLayout: 'full' })
)
);
if (files.directoryExists('./server')) {
console.log(chalk.red('Server has already been created, run update instead!'));
process.exit();
}
const run = async () => {
let credentials = await inquirer.askOntraportCredentials();
let str = [`API_KEY = "${credentials.api_key}"`, `APP_ID = "${credentials.app_id}"`].join('\n')
if(!files.directoryExists(`${credentials.appname}`)){
fs.mkdir(`./${credentials.appname}`, function(err){
console.error(new Error(err));
});
} else {
console.log(chalk.red('App Directory Already Exists!'));
process.exit();
}
let appRoot = `./${credentials.appname}`;
fs.writeFile(`${appRoot}/.env`, str, res => {
console.log(chalk.green('Successfully saved Ontraport Credentials to Env file!'));
})
if(!files.directoryExists('./services')){
fs.mkdir(`${appRoot}/services`);
}
const status = new Spinner('Scaffolding files...');
status.start();
let createOs = execute('npm root -g', function(location){
files.createPackageFile(`${location.replace("\\","/").replace("\n", "")}`,appRoot, `${credentials.appname}`)
fs.createReadStream(`${location.replace("\\","/").replace("\n", "")}/ontrajs/lib/ontraport_service.txt`).pipe(fs.createWriteStream(`${appRoot}/services/ontraport_service.js`))
})
status.stop();
// files.createTypeFile( `${appRoot}`, 'schema', contents);
}
run()