Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function readParseFile() {
let data;
console.log('readParseFile');
try {
data = fs.readFileSync(this.path, 'utf-8');
} catch (e) {
console.log('readParseFile error; starting with empty data');
data = {};
}
// Parse the INI-format configuration file
return ini.parse(data);
}
export async function getMetadata() {
if (fs.existsSync(TCBRC)) {
const tcbrc = ini.parse(fs.readFileSync(TCBRC, 'utf-8'))
if (!tcbrc.secretId || !tcbrc.secretKey || !tcbrc.host || !tcbrc.password || !tcbrc.username || !tcbrc.port) {
// 缺少信息,重新登录
return await login()
}
return tcbrc
} else {
// 没有登录过
return await login()
}
}
$(document).ready(function() {
// read config
// get default config
config = ini.parse(fs.readFileSync('./app/default.ini', 'utf-8'));
// helper returns true if file exists, false otherwise
var fileExists = function(filename) {
try {
fs.accessSync(filename);
} catch(e) {
return false;
}
return true;
};
// for linux or osx overwrite values from ~/.sum.ini configuration file
if (os.platform() == 'linux' || os.platform() == 'darwin')
if (fileExists(process.env.HOME + '/.sum.ini'))
$.extend(config, ini.parse(fs.readFileSync(process.env.HOME + '/.sum.ini', 'utf-8')));
fs.readFile(that.filePath, "utf8", (err, data) => {
if (err && err.code !== "ENOENT") {
reject(err);
} else {
try {
console.log("config from", that.filePath);
that.settings = ini.parse(data || "");
if (that.settings[""]) {
delete that.settings[""];
}
resolve(that);
} catch (e) {
reject(e);
}
}
});
});
read() {
this.credentials = ini.parse(
fs.readFileSync(this.readFilename(), 'utf-8')
);
return this.credentials;
}
function getConfig() {
try {
require.resolve(path.resolve(process.cwd(), './.comfy/config'));
} catch (e) {
return { project: {} };
}
return ini.parse(fs.readFileSync(path.resolve(process.cwd(), './.comfy/config'), 'utf-8'));
}
const readRc = filePath => {
try {
return ini.parse(fs.readFileSync(filePath, 'utf8')).prefix;
} catch (_) {}
};
function readRc(fname) {
const rcFname = Path.basename(fname);
try {
const rcData = Fs.readFileSync(fname).toString();
let rc;
try {
assert(rcFname === ".fynrc" && rcData.startsWith("---"));
rc = Yaml.parse(rcData);
logger.debug(`Loaded ${rcFname} YAML RC`, fname, JSON.stringify(rc));
} catch (e) {
rc = Ini.parse(rcData);
logger.debug(`Loaded ${rcFname} ini RC`, fname, JSON.stringify(rc));
}
return rc;
} catch (e) {
if (e.code !== "ENOENT") {
logger.error(`Failed to process ${rcFname} RC file`, fname, e.message);
}
return {};
}
}
function modifyPlatformioIni() {
if (!keepCompatible && !useArduinoLibManager) {
return;
}
const iniPath = path.join(projectPath, 'platformio.ini');
let contentToPreserve = '';
const fullConfig = fs.readFileSync(iniPath).toString();
const envPosition = fullConfig.search(/^\[env:/m);
if (envPosition > -1) {
contentToPreserve = fullConfig.slice(0, envPosition);
}
const config = ini.parse(fullConfig);
if (!config.platformio) {
config.platformio = {};
}
if (keepCompatible) {
config.platformio.src_dir = path.basename(projectPath);
}
if (useArduinoLibManager) {
config.platformio.lib_dir = view.getLibManagerDirectory();
}
fs.writeFileSync(iniPath, contentToPreserve);
fs.appendFileSync(iniPath, ini.stringify(config));
}
function getProfileCredentials(profileName) {
let profileCredentials;
if (fs.existsSync(credentialsFilePath)) {
const credentials = ini.parse(fs.readFileSync(credentialsFilePath, 'utf-8'));
Object.keys(credentials).forEach(key => {
const keyName = key.trim();
if (profileName === keyName) {
profileCredentials = credentials[key];
}
});
}
return normalizeKeys(profileCredentials);
}