How to use the mz/fs.statSync function in mz

To help you get started, we’ve selected a few mz 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 streamplace / streamplace / packages / streamplace-cli / src / config.js View on Github external
export default function getConfig(program) {
  const { spConfig } = program;
  let stat;
  try {
    stat = fs.statSync(spConfig);
  } catch (e) {
    // Create if it doesn't exist.
    if (e.code !== "ENOENT") {
      throw e;
    }
    mkdirp(dirname(spConfig));
    fs.writeFileSync(spConfig, writeYaml(CONFIG_DEFAULT));
  }
  const data = fs.readFileSync(spConfig, "utf8");
  return readYaml(data);
}
github Polymer / tools / src / tools / test-polymer.ts View on Github external
(async () => {
  let exitCode = 0;

  try {
    console.assert(fs.statSync(sourceDir).isDirectory());
    console.assert(fs.statSync(expectedDir).isDirectory());
  } catch (err) {
    console.log(
        'Error: No checkpoint found, run `yarn run polymer:checkpoint` to generate a good checkpoint to compare against.');
    process.exit(1);
  }

  const options = {
    inDir: sourceDir,
    outDir: sourceDir,
    packageName: '@polymer/polymer',
    packageVersion: '3.0.0',
  };
  const analyzer = configureAnalyzer(options);
  const analysis = await analyzer.analyzePackage();
  const converter = configureConverter(analysis, options);
github Polymer / tools / src / tools / test-polymer.ts View on Github external
(async () => {
  let exitCode = 0;

  try {
    console.assert(fs.statSync(sourceDir).isDirectory());
    console.assert(fs.statSync(expectedDir).isDirectory());
  } catch (err) {
    console.log(
        'Error: No checkpoint found, run `yarn run polymer:checkpoint` to generate a good checkpoint to compare against.');
    process.exit(1);
  }

  const options = {
    inDir: sourceDir,
    outDir: sourceDir,
    packageName: '@polymer/polymer',
    packageVersion: '3.0.0',
  };
  const analyzer = configureAnalyzer(options);
  const analysis = await analyzer.analyzePackage();
  const converter = configureConverter(analysis, options);
  const results = await converter.convert();
github Polymer / tools / src / tools / test-polymer.ts View on Github external
function* walkDir(dir: string, base = dir): Iterable {
  for (const fn of fs.readdirSync(dir)) {
    const fullPath = path.join(dir, fn);
    if (fs.statSync(fullPath).isDirectory()) {
      yield* walkDir(fullPath, base);
    } else {
      yield path.relative(base, fullPath);
    }
  }
}
github agreatfool / SASDN / src / bin / sasdn-scaffold.ts View on Github external
private async _copyScaffold() {
    const scaffoldDir = LibPath.join(__dirname, '..', '..', 'scaffold');
    if (!LibFs.existsSync(scaffoldDir) || !LibFs.statSync(scaffoldDir).isDirectory()) {
      throw new Error('scaffold dir not found, path:' + scaffoldDir);
    }

    const outputDir = LibPath.join(process.cwd(), this._input.name);
    if (LibFs.existsSync(outputDir) && LibFs.statSync(outputDir).isDirectory()) {
      throw new Error('output dir already exists, path:' + outputDir);
    }

    try {
      await mkdir(outputDir);
      await LibFsExtra.copy(scaffoldDir, outputDir);
      console.log('ScaffoldCLI _genScaffold finish.');
    } catch (e) {
      throw e;
    }
  }
github agreatfool / SASDN / src / bin / sasdn-scaffold.ts View on Github external
private async _copyScaffold() {
    const scaffoldDir = LibPath.join(__dirname, '..', '..', 'scaffold');
    if (!LibFs.existsSync(scaffoldDir) || !LibFs.statSync(scaffoldDir).isDirectory()) {
      throw new Error('scaffold dir not found, path:' + scaffoldDir);
    }

    const outputDir = LibPath.join(process.cwd(), this._input.name);
    if (LibFs.existsSync(outputDir) && LibFs.statSync(outputDir).isDirectory()) {
      throw new Error('output dir already exists, path:' + outputDir);
    }

    try {
      await mkdir(outputDir);
      await LibFsExtra.copy(scaffoldDir, outputDir);
      console.log('ScaffoldCLI _genScaffold finish.');
    } catch (e) {
      throw e;
    }
  }
github surf-build / surf / src / git-api.ts View on Github external
return ret.reduce((acc: string[], x) => {
    let nwo = getNwoFromRepoUrl(repoUrl).split('/')[1];
    if (x.match(/^surfg-/i)) {
      let tgt = path.join(tmp, x);
      let stats = fs.statSync(tgt);
      let now = new Date();

      if ((now.getTime() - stats.mtime.getTime()) > 1000 * 60 * 60 * 2) {
        acc.push(path.join(tmp, x));
      }

      return acc;
    }

    if (!x.match(/-[a-f0-9A-F]{6}/i)) return acc;
    if (x.indexOf(`${nwo}-`) < 0) return acc;

    acc.push(path.join(tmp, x));
    return acc;
  }, []);
}
github whxaxes / blog / app / controller / blog.js View on Github external
async index() {
    const { ctx, app } = this;
    const visitUrl = app.config.biz.docForwardUrl[ctx.url] || ctx.url;
    const mdPath = visitUrl.substring(app.config.biz.docPrefix.length);
    const extname = path.extname(mdPath);
    const docDir = app.config.biz.docDir;

    if (!extname) {
      const dirPath = path.resolve(docDir, mdPath);
      if (!fs.existsSync(dirPath) || !fs.statSync(dirPath).isDirectory()) {
        return;
      }

      const { docList, docInfo } = await this.service.blog.getDocInfo(dirPath);
      if (!docList.length) return;

      const allInfo = await this.service.blog.readAllInfo();
      await ctx.render('blog/list', {
        docList,
        docInfo,
        allInfo,
      });
    } else if (extname === '.html') {
      const fileUrl = path.resolve(docDir, `${mdPath.replace(/\.html$/, '.md')}`);
      if (!fs.existsSync(fileUrl)) {
        return;
github avetjs / avet / packages / avet-server / lib / sendfile.js View on Github external
function loadFile(filepath, options, files) {
  if (!files.get(filepath)) files.set(filepath, {});
  const obj = files.get(filepath);
  const filename = (obj.path = filepath);
  const stats = fs.statSync(filename);
  let buffer = fs.readFileSync(filename);

  obj.cacheControl = options.cacheControl;
  obj.maxAge = obj.maxAge ? obj.maxAge : options.maxAge || 0;
  obj.type = obj.mime = mime.lookup(filepath) || 'application/octet-stream';
  obj.mtime = stats.mtime;
  obj.length = stats.size;
  obj.md5 = crypto
    .createHash('md5')
    .update(buffer)
    .digest('base64');

  if (options.buffer) obj.buffer = buffer;

  buffer = null;
  return obj;
github erzu / porter / packages / porter / index.js View on Github external
const transform = require('./lib/transform')
const findBabelrc = require('./lib/findBabelrc')

const loaderPath = path.join(__dirname, 'loader.js')
const loaderSource = fs.readFileSync(loaderPath, 'utf8').replace(/\$\{(\w+)\}/g, function(m, key) {
  if (key == 'NODE_ENV') {
    return process.env.NODE_ENV || 'development'
  } else {
    return ''
  }
})
const loaderStats = fs.statSync(loaderPath)

const serviceWorkerPath = path.join(__dirname, 'porter-sw.js')
const serviceWorkerSource = fs.readFileSync(serviceWorkerPath, 'utf8')
const serviceWorkerStats = fs.statSync(serviceWorkerPath)

const RE_EXT = /(\.\w+)$/i
const RE_ASSET_EXT = /\.(?:gif|jpg|jpeg|png|svg|swf|ico)$/i

const { exists, lstat, readFile } = fs


/**
 * @typedef  {Module}
 * @type     {Object}
 * @property {string} name
 * @property {string} version
 * @property {string} entry
 *
 * @typedef  {DependenciesMap}
 * @type     {Object}