snips-sam
Version:
The Snips Assistant Manager
79 lines • 2.5 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const path = require("path");
const fs = require("fs-extra");
const yaml = require("js-yaml");
const os = require("os");
exports.samConfigDirectory = path.join(os.homedir(), '.sam');
const configurationName = 'configuration.yml';
exports.localConfigurationFilePath = path.join(exports.samConfigDirectory, configurationName);
class Config {
constructor() {
this.load();
}
load() {
try {
fs.ensureFileSync(exports.localConfigurationFilePath);
const cfg = yaml.safeLoad(fs.readFileSync(exports.localConfigurationFilePath, 'utf8'));
if (!cfg)
return;
if (cfg['credentials'])
this.credentials = cfg['credentials'];
if (cfg['user'])
this.user = cfg['user'];
if (cfg['token'])
this.consoleToken = cfg['token'];
}
catch (e) {
throw new Error(`No config found on disk ${e.message}`);
}
}
save() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const ymlFile = yaml.safeDump({ credentials: this.credentials ? this.credentials : null, user: this.user ? this.user : null, token: this.consoleToken ? this.consoleToken : null });
return fs.outputFile(exports.localConfigurationFilePath, ymlFile);
});
}
}
exports.Config = Config;
Config.hostnameQuestion = [
{
name: 'hostname',
type: 'input',
default: 'hostname.local',
message: 'Enter your device hostname or IP:',
validate: value => {
if (value.length)
return true;
return 'Hostname cannot be blank';
},
},
];
Config.usernameQuestion = [
{
name: 'username',
type: 'username',
default: 'pi',
message: 'Enter username for the device:',
validate: value => {
if (value.length)
return true;
return 'Username cannot be blank';
},
},
];
Config.passwordQuestion = [
{
name: 'password',
type: 'password',
default: 'raspberry',
message: 'Enter password for the device:',
validate: value => {
if (value.length)
return true;
return 'Password cannot be blank';
},
},
];
//# sourceMappingURL=config.js.map
;