async persistSources(sourceContainer, packageVersions) { const sources = sourceContainer.outputSources(); await Promise.all(sources.map((file) => fs.outputFile(path.join(this.appPath, file.fileName), file.content))); const packageJson = fs.readJsonSync(path.join(this.appPath, 'package.json')); packageJson.cubejsTemplates = { ...packageJson.cubejsTemplates, ...packageVersions, }; await fs.writeJson(path.join(this.appPath, 'package.json'), packageJson, { spaces: 2, }); }
static getPackageVersions(appPath) { try { return fs.readJsonSync(path.join(appPath, 'package.json')).cubejsTemplates || {}; } catch (error) { return {}; } }
async ensureDependencies() { const dependencies = this.sourceContainer.importDependencies; const packageJson = fs.readJsonSync(path.join(this.appPath, 'package.json')); if (!packageJson || !packageJson.dependencies) { return []; } const toInstall = R.toPairs(dependencies) .filter(([dependency]) => !packageJson.dependencies[dependency]) .map(([dependency, version]) => (version !== 'latest' ? `${dependency}@${version}` : dependency)); if (toInstall.length) { await this.executeCommand('npm', ['install', '--save'].concat(toInstall), { cwd: path.resolve(this.appPath) }); } return toInstall; }
describe('save()', function () { it('saves file correctly', function () { fs.writeJsonSync('config-test.json', {}); test = new Config('config-test.json'); test.set('a', 'b').save(); expect(fs.readJsonSync('config-test.json')).to.deep.equal({a: 'b'}); fs.removeSync('config-test.json'); }); });
_existsLocaleFile(locale) { return fse.readJsonSync(path.join(__dirname, `${locale.substring(0, 2)}.json`)) }
function expectPackageToMatch (pkgProps) { return result => { expect(result).toBeDefined(); expect(fs.existsSync(result)).toBe(true); const pkg = fs.readJsonSync(path.join(result, 'package.json')); expect(pkg).toEqual(jasmine.objectContaining(pkgProps)); return result; }; }
getServiceConfig () { if (this.usesLocalConfig()) { return settings.get('serviceConfig') } else { return fs.readJsonSync(settings.get('serviceConfigPath')) } }
// 修改脚本config文件 let mixinsScriptConfig = async (scriptName, mixins) => { try{ let confPath = path.resolve(__dirname, `../script/${scriptName}/config.json`); let oldConf = fse.readJsonSync(confPath); let newConf = Object.assign({}, oldConf, mixins); fse.writeJsonSync(confPath, newConf); return true }catch(err){ return false } }
static load (plugins_dir, platform) { const filePath = path.join(plugins_dir, `${platform}.json`); const root = fs.existsSync(filePath) ? fs.readJsonSync(filePath) : null; return new PlatformJson(filePath, platform, root); }
function readFromLog () { try { if (fs.pathExistsSync(logFile)) return fs.readJsonSync(logFile) else return {} // First launch } catch (error) { // Allowed to fail to make healthcheck robust console.error(error) return {} } }
/** * Checks whether or not a config file exists * @param {string} filename Filename to check * * @static * @method exists * @public */ static exists(filename) { try { const result = fs.readJsonSync(filename); return result; } catch (e) { return false; } }
function getConfig() { const configPath = getRootDir('config.json') if (fs.existsSync(configPath)) { return fs.readJsonSync(configPath) } else { return {} } }
const load = () => { try{ if (fs.existsSync(fileName)){ loadedConfig = fs.readJsonSync(fileName); } } catch(ex){ console.error("failed to read config file", ex); } return loadedConfig; }
const cypressConfigResolverByFile = (filename) => { const pathToConfigFile = path.resolve(__dirname, `${filename}.json`); return fs.readJsonSync(pathToConfigFile); }
function setConfig(config) { const configPath = getRootDir('config.json') if (fs.existsSync(configPath)) { const oldConfig = fs.readJsonSync(configPath) config = { ...oldConfig, ...config } } fs.writeJsonSync(configPath, config, { spaces: 2 }) }