How to use the fs-extra.readFileSync function in fs-extra

To help you get started, we’ve selected a few fs-extra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fredsiika / 30-seconds-of-c / scripts / util.js View on Github external
const readSnippets = snippetsPath => {
    const snippetFilenames = getFilesInDir(snippetsPath, false);
  
    let snippets = {};
    try {
      for (let snippet of snippetFilenames)
        snippets[snippet] = fs.readFileSync(path.join(snippetsPath, snippet), 'utf8');
    } catch (err) {
      console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
      process.exit(1);
    }
    return snippets;
  };
  // Creates an object from pairs
github newmips / newmips / structure / structure_component.js View on Github external
function deleteAccessManagment(idApplication, urlComponent, urlModule, callback) {
    // Write new data entity to access.json file, within module's context
    var accessPath = __dirname + '/../workspace/' + idApplication + '/config/access.json';
    var accessLockPath = __dirname + '/../workspace/' + idApplication + '/config/access.lock.json';
    var accessObject = JSON.parse(fs.readFileSync(accessPath, 'utf8'));
    if (accessObject[urlModule.toLowerCase()] && accessObject[urlModule.toLowerCase()].entities) {
        var entities = accessObject[urlModule.toLowerCase()].entities;
        var dataIndexToRemove = -1;
        for (var i = 0; i < entities.length; i++) {
            if (entities[i].name === urlComponent) {
                dataIndexToRemove = i;
                break;
            }
        }
        if (dataIndexToRemove !== -1)
            entities.splice(dataIndexToRemove, 1);
        fs.writeFileSync(accessPath, JSON.stringify(accessObject, null, 4), "utf8");
        fs.writeFileSync(accessLockPath, JSON.stringify(accessObject, null, 4), "utf8");
        callback();
    } else
        callback();
github nadav96 / rocketsam / src / settings.js View on Github external
async function getRocketSamSettings() {
  try {
    var doc = yaml.safeLoad(fs.readFileSync(`${process.cwd()}/rocketsam.yaml`, 'utf8'));
    return doc
  }
  catch (e) {
    console.log("rocketsam not found, is project configured?");
  }
}
github decentraland / explorer / kernel / scripts / prepareDist.ts View on Github external
await fs.copy(src, dst)

    if (!fs.existsSync(dst)) {
      throw new Error(`${dst} does not exist`)
    }
  }

  const targetIndexHtml = path.resolve(root, 'static/index.html')

  if (!fs.existsSync(targetIndexHtml)) {
    throw new Error(`${targetIndexHtml} does not exist`)
  }

  console.log(`> replace ${filename}.js -> ${newFileName} in html`)
  {
    let content = readFileSync(targetIndexHtml).toString()

    if (!content.includes(`${filename}.js`)) {
      throw new Error(`index.html is dirty and does\'t contain the text "${filename}.js"`)
    }

    content = content.replace(new RegExp(filename + '.(S+.)?js'), newFileName)
    content = content.replace(/\s*/, '')
    content = content + `\n\n`

    writeFileSync(targetIndexHtml, content)
  }
}
github pytorch / botorch / website / core / Tutorial.js View on Github external
render() {
    const {baseUrl, tutorialID} = this.props;

    const htmlFile = `${CWD}/_tutorials/${tutorialID}.html`;
    const normalizedHtmlFile = path.normalize(htmlFile);

    return (
      <div>
        
        
          <div>
          <div>
            <a href="{`${baseUrl}files/${tutorialID}.ipynb`}" download="">
              {renderDownloadIcon()}
              {'Download Tutorial Jupyter Notebook'}
            </a>
          </div>
          <div>
            </div></div></div>
github ant-move / Antmove / src / transform / index.js View on Github external
beforeRun (cb = () => {}) {
        process.env.compilerType = this.$options.type;
        let inputDir = this.$options.entry;
        let outputDir = this.$options.dist;

        let lifeCycles = this.$plugin.lifeCycles;
        let self = this;
        const packagePath = path.join(__dirname, '../..', 'package.json');
        const packageJson = fs.readFileSync(packagePath);
        const versionData = { version: JSON.parse(packageJson).version};
        if (lifeCycles.defaultOptions.exclude) {
            this.$options.exclude = this.$options.exclude.concat(lifeCycles.defaultOptions.exclude);
        }
        lifeCycles.$options = Object.assign(lifeCycles.defaultOptions, this.$options, versionData);
        /**
         * Setting compile env
         */
        process.env.NODE_ENV = lifeCycles.$options.env;
        lifeCycles.beforeParse(function () {
            self.run(inputDir, outputDir, cb);

        });
    }
github standard-things / esm / script / publish.js View on Github external
function cleanPackageJSON() {
  const content = fs.readFileSync(pkgPath, "utf8")

  process.once("exit", () => fs.outputFileSync(pkgPath, content))

  const pkgJSON = JSON.parse(content)

  for (const field of fieldsToRemove) {
    Reflect.deleteProperty(pkgJSON, field)
  }

  pkgJSON.scripts = defaultScripts
  fs.outputFileSync(pkgPath, fleece.patch(content, pkgJSON))
}
github jasperapp / jasper / src / Bootstrap.ts View on Github external
_loadTheme() {
    if (Config.themeMainPath)  {
      const css = fs.readFileSync(Config.themeMainPath).toString();
      Global.getMainWindow().webContents.send('load-theme-main', css);
    } else {
      Global.getMainWindow().webContents.send('load-theme-main', '');
    }
  }
}
github mapseed / platform / scripts / static-build.js View on Github external
fs.readdirSync(outputJSTemplatesPath).forEach((jsTemplate) => {
    if (jsTemplate.endsWith("html")) {
      templatePath = path.resolve(outputJSTemplatesPath, jsTemplate);
      localizedTemplate = fs.readFileSync(
        templatePath,
        "utf8"
      ).replace(
        jsTemplatesGettextRegex,
        (match, capture) => {
          return gt.gettext(capture);
        }
      );

      fs.writeFileSync(
        templatePath,
        localizedTemplate,
        "utf8"
      );
    }
  });
github material-components / material-components-site-generator / scripts / lib / platform-site.js View on Github external
function readYaml(yamlPath) {
  return yaml.safeLoad(fs.readFileSync(yamlPath));
}