Exemplo n.º 1
0
Directory.writeJSON = function(data, options) {
  options = options || {};
  options = Object.assign({encoding:'utf8'}, options);

  return fs.ensureDir(this.filepath())
    .then(() => fs.writeFile(this.physicalFilepath(), JSON.stringify(data), options))
    .then(() => {
      console.error('Wrote: ' + this.filepath() + path.sep);  // eslint-disable-line no-console
      return this;
    });
};
Exemplo n.º 2
0
export async function setupConfig (args) {
  const keysFile = path.resolve('battleaxe-keys.js')
  const configFile = path.resolve('battleaxe-config.js')

  const baseDir = path.resolve('.battleaxe')
  const stateFile = path.resolve(baseDir, 'state.json')
  const trashCanFile = path.resolve(baseDir, 'trash.json')

  await fs.ensureDir(baseDir)

  if (!await fs.exists(stateFile)) {
    await fs.outputJson(stateFile, {})
  }

  if (!await fs.exists(trashCanFile)) {
    await fs.outputJson(trashCanFile, {})
  }

  config.keys = require(keysFile)
  config.data = require(configFile)
  config.state = require(stateFile)
  config.trashCan = require(trashCanFile)

  config.stateFile = stateFile
  config.trashCanFile = trashCanFile
  // const config = {
  //   keys: require(keysFile),
  //   keysFile,
  //
  //   data: require(configFile),
  //   configFile,
  //
  //   state: require(stateFile),
  //   stateFile,
  //
  //   trashCan: require(trashCanFile),
  //   trashCanFile
  // }
}
Exemplo n.º 3
0
 await Promise.all(dirs.map(p => fs.ensureDir(getTargetPath(p.path))));
Exemplo n.º 4
0
fs.remove(path.join(__dirname, "release")).then(function () {
    return fs.ensureDir(path.join(__dirname, "release"));
}).then(function () {
Exemplo n.º 5
0
/**
 * render cdnex
 * @return {Promise/object} It depends... should decouple this.
 */
export default async function render (options = {}) {
  try {
    if (!options.args) {
      options.args = []
    }

    if (!options.validate && options.validate !== false) {
      options.validate = true
    }

    if (options.validate && !validator.isURL(options.url)) {
      throw new Error(`${options.url} is not a valid domain name.`)
    }

    let input
    let isDir
    if (options.src) { /* input data was passed through as string */
      if (options.input) {
        throw new Error('dont specify both input and src. only choose one!')
      }

      input = options.src
    } else { /* input is a file/dirname, read from disk */
      input = options.input || options.args[0]
      if (!input) throw new Error('no input file or directory was specified.')

      const exists = await fs.exists(input)
      if (!exists) throw new Error(`"${input}" does not exist!`)

      const stats = await fs.lstat(input)
      isDir = stats.isDirectory()
    }

    let cdnexed
    if (isDir) {
      options.pattern = options.pattern || '/**/*.{html,css}'
      if (options.pattern.charAt(0) !== '/') {
        options.pattern = '/' + options.pattern
      }

      const files = await dn(glob)(path.resolve(input) + options.pattern)

      cdnexed = await Promise.all(
        files.map(async (file) => {
          try {
            cdnexed = await prepend(file, options)
            return { file, cdnexed }
          } catch (err) {
            return Promise.reject(err)
          }
        })
      )
    } else {
      cdnexed = await prepend(input, options)
    }

    if (options.output) {
      /* warn if overwriting */
      let outputExists = await fs.exists(options.output)
      if (outputExists) {
        /* doesnt really exist if its just an empty directory */
        outputExists = (await dn(glob)(`${options.output}/**/*`, {
          nodir: true
        })).length > 0
      }

      if (outputExists && !options.force && options.args.length > 0) {
        /* ask if they want to overwrite */
        const { overwrite } = await dn(inquirer.prompt, (a) => [null, a])([{
          type: 'confirm',
          name: 'overwrite',
          message: chalk.yellow(`${options.output} already exists. overwrite?`)
        }])

        /* abort if they dont */
        if (!overwrite) {
          throw new Error(chalk.red('change your output and try again.'))
        }
      } else if (outputExists && options.args.length === 0 && !options.force) {
        throw new Error('output already exists')
      }

      /* output to file(s) */
      if (typeof cdnexed === 'object') {
        await fs.ensureDir(options.output)

        await Promise.all(cdnexed.map((obj) => {
          /* generate output filename */
          obj.output = obj.file.replace(input, options.output)

          /* log paths without the cwd */
          if (!options.quiet) {
            console.log('rendering',
              obj.file.replace(process.cwd() + '/', ''), 'to',
              obj.output.replace(process.cwd() + '/', '')
            )
          }

          return fs.writeFile(obj.output, obj.cdnexed)
        }))
      } else {
        /* output to a single file */
        if (!options.quiet) {
          console.log(`rendering ${input} to ${options.output}`)
        }

        await fs.writeFile(options.output, cdnexed)
      }
    } else {
      /* no output, just return it */
      return cdnexed
    }
  } catch (err) {
    return Promise.reject(err)
  }
}
Exemplo n.º 6
0
 await Promise.all(dirs.map(p => fs.ensureDir(getBuildPath(p.path))));
"use strict";

var temp             = require('temp').track();
var path             = require('path');
var fs               = require('fs-promise');

var moveDirectory    = require('../lib/utilities/move-directory');
var runCommand       = require('../lib/utilities/run-command');
var symlinkDirectory = require('../lib/utilities/symlink-directory');

var tmpDir           = temp.mkdirSync();
var root             = process.cwd();
var name             = 'precooked-app';
var args             = [require.resolve('ember-cli/bin/ember'), 'new', '--disable-analytics', '--watcher = node', '--skip-git', name];

fs.ensureDir('tmp')
  .then(function() {
    process.chdir(tmpDir);
    return runCommand.apply(undefined, args);
  })
  .then(function() {
    moveDirectory(path.join(tmpDir, name, 'node_modules'), path.join(root, 'tmp', 'precooked_node_modules'));
    symlinkDirectory(root, path.join(root, 'tmp', 'precooked_node_modules', 'ember-cli-fastboot'));
  })
  .catch(function(e) {
    console.log(e);
  });
Exemplo n.º 8
0
 return co(function * () {
   yield fsp.ensureDir(dest)
   yield fsp.copy(source, dest)
 }).catch(e => {
Exemplo n.º 9
0
let ensureTmpDir = () => {
  return fsp.ensureDir(SHIPS_PATH);
};