示例#1
0
文件: servers.js 项目: rlugojr/hotel
 .map((file) => {
   const id = path.basename(file, '.json')
   const serverFile = getServerFile(id)
   const server = JSON.parse(fs.readFileSync(serverFile))
   if (server.cmd) {
     return `${id}\n${chalk.gray(tildify(server.cwd))}\n${chalk.gray(server.cmd)}`
   } else {
     return `${id}\n${chalk.gray(server.target)}`
   }
 })
示例#2
0
文件: list.js 项目: macressler/katon
  listHosts().forEach(function(name) {
    var filename = config.hostsDir + '/' + name
    var host = JSON.parse(fs.readFileSync(filename))

    console.log(
      chalk.cyan(name.replace('.json', '')),
      host.command,
      chalk.grey(tildify(host.cwd))
    )
  })
示例#3
0
    function outputStart(startSizeString, startPath, interestingSize) {
        spinner.stop();

        const fullPath = tildify(path.resolve(startPath));

        console.log(`${startSizeString} ${fullPath}`);

        if (startPathSize > interestingSize) {
            console.log(`Directories larger than ${toMB(interestingSize)}`);
        }
    }
示例#4
0
function logTasks(env, localGulp) {
  var tree = taskTree(localGulp.tasks);
  tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
  archy(tree)
    .split('\n')
    .forEach(function (v) {
      if (v.trim().length === 0) {
        return;
      }
      gutil.log(v);
    });
}
示例#5
0
function rm (name) {
  const id = getId(name)
  const file = getServerFile(id)

  console.log(`Remove  ${tildify(file)}`)
  if (fs.existsSync(file)) {
    fs.unlinkSync(file)
    console.log('Removed')
  } else {
    console.log('No such file')
  }
}
示例#6
0
		function(file, enc, callback) {
			var message;

			if (!opts.verbose) {
				message = chalk.blue(file.relative);
			} else {
				message =
					'\ncwd:         ' + chalk.blue(tildify(file.cwd)) +
					'\nprocess.cwd: ' + chalk.blue(tildify(process.cwd())) +
					'\nrelative:    ' + chalk.blue(file.relative) +
					'\nbase:        ' + chalk.blue(tildify(file.base)) +
					'\npath:        ' + chalk.blue(tildify(file.path)) +
					'\n';
			}

			count++;

			gutil.log(opts.title + ' ' + message);

			callback(null, file);
		},
示例#7
0
  process.nextTick(function() {
    var tree;

    if (opts.tasksSimple) {
      tree = gulpInst.tree();
      return logTasksSimple(tree.nodes);
    }
    if (opts.tasks) {
      tree = gulpInst.tree({ deep: true });
      tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));

      return logTasks(tree, function(task) {
        return gulpInst.task(task).description;
      });
    }
    if (opts.tasksJson) {
      tree = gulpInst.tree({ deep: true });
      tree.label = 'Tasks for ' + tildify(env.configPath);

      var output = JSON.stringify(tree);

      if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
        return console.log(output);
      } else {
        return fs.writeFileSync(opts.tasksJson, output, 'utf-8');
      }
    }
    try {
      log.info('Using gulpfile', chalk.magenta(tildify(env.configPath)));
      gulpInst.parallel(toRun)(function(err) {
        if (err) {
          exit(1);
        }
      });
    } catch (err) {
      log.error(chalk.red(err.message));
      log.error('To list available tasks, try running: gulp --tasks');
      exit(1);
    }
  });
示例#8
0
文件: cli.js 项目: slathrop/knex
function initKnex(env, opts) {
  checkLocalModule(env);
  if (process.cwd() !== env.cwd) {
    process.chdir(env.cwd);
    console.log(
      'Working directory changed to',
      chalk.magenta(tildify(env.cwd))
    );
  }

  if (!opts.knexfile) {
    const configuration = tryLoadingDefaultConfiguration();
    env.configuration = configuration || mkConfigObj(opts);
  }
  // If knexfile is specified
  else {
    const resolvedKnexfilePath = path.resolve(opts.knexfile);
    env.configuration = require(resolvedKnexfilePath);

    if (!env.configuration) {
      exit(
        'Knexfile not found. Specify a path with --knexfile or pass --client and --connection params in commandline'
      );
    }
  }

  let environment = opts.env || process.env.NODE_ENV;
  const defaultEnv = 'development';

  let config = env.configuration;

  if (!environment && typeof config[defaultEnv] === 'object') {
    environment = defaultEnv;
  }

  if (environment) {
    console.log('Using environment:', chalk.magenta(environment));
    config = config[environment] || config;
  }

  if (!config) {
    console.log(chalk.red('Warning: unable to read knexfile config'));
    process.exit(1);
  }

  if (argv.debug !== undefined) {
    config.debug = argv.debug;
  }

  const knex = require(env.modulePath);
  return knex(config);
}
    return through.obj(function(chunk, enc, cb) {
        var webpackOptions = chunk[propsStream.FIELD_NAME] || {},
            compilerOptions = chunk[initStream.FIELD_NAME] || {},
            adapter = new CompilerAdapter(compilerOptions, webpackOptions);

        gutil.log(MESSAGE, gutil.colors.magenta(tildify(chunk.path)));

        adapter.watch(chunk, function(err, stats) {
            callback.apply(chunk, [err, stats]);
        });

        cb();
    });
    return through.obj(function(chunk, enc, cb) {
        var stats = chunk[processStats.STATS_DATA_FIELD_NAME],
            isStats = chunk[processStats.STATS_FLAG_FIELD_NAME];

        if (isStats) {
            var filename = path.resolve(chunk.path);

            gutil.log(MESSAGE, gutil.colors.magenta(tildify(filename)));
            gutil.log('\n' + stats.toString(statsOptions));
        }

        cb(null, chunk);
    });
示例#11
0
文件: index.js 项目: 4gekkman/R5
 process.nextTick(function() {
   if (opts.tasksSimple) {
     return logTasksSimple(env, gulpInst);
   }
   if (opts.tasks) {
     var tree = taskTree(gulpInst.tasks);
     tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
     return logTasks(tree, opts.depth, function(task) {
       return gulpInst.tasks[task].fn;
     });
   }
   gulpInst.start.apply(gulpInst, toRun);
 });
示例#12
0
文件: menu.js 项目: bocoup/js-learn
function draw (menu, context) {
  menu.reset();
  menu.write(`${context.title}\n`);
  menu.write(`${BAR}\n`);
  context.exercises.forEach(exercise => {
    const baseDir = path.join(context.exercisesDir, exercise);
    const meta = require(path.join(baseDir, 'exercise'));
    menu.add(`▪ ${meta.name.toUpperCase()}`, choose.bind(null, context, menu))
  });
  menu.write(`${BAR}\n`);
  menu.add('EXIT');
  menu.write(`Running exercises will copy files to ${tildify(process.cwd())}`);
}
示例#13
0
function rm (opts = {}) {
  const cwd = process.cwd()
  const id = opts.n || getId(cwd)
  const file = getServerFile(id)

  console.log(`Remove  ${tildify(file)}`)
  if (fs.existsSync(file)) {
    fs.unlinkSync(file)
    console.log('Removed')
  } else {
    console.log('No such file')
  }
}
示例#14
0
function add (cmd, opts = {}) {
  mkdirp.sync(serversDir)

  const id = getId(opts.n)
  const file = getServerFile(id)
  const cwd = opts.d || process.cwd()
  const obj = { cwd, cmd }

  if (opts.o) obj.out = opts.o

  obj.env = {}

  // By default, save PATH env for version managers users
  obj.env.PATH = process.env.PATH

  // Copy other env option
  if (opts.e && process.env[opts.e]) {
    obj.env[opts.e] = process.env[opts.e]
  }

  // Copy port option
  if (opts.p) {
    obj.env.PORT = opts.p
  }

  const data = JSON.stringify(obj, null, 2)

  console.log(`Create ${tildify(file)}`)
  fs.writeFileSync(file, data)

  if (obj.out) {
    const logFile = tildify(path.resolve(obj.out))
    console.log(`Output ${logFile}`)
  } else {
    console.log('Output No log file specified (use \'-o app.log\')')
  }
}
示例#15
0
	return through.obj(function (file, enc, cb) {
		if (file.isStream()) {
			cb(new gutil.PluginError('gulp-debug', 'Streaming not supported'));
			return;
		}

		var trim = function (buf) {
			return buf.toString('utf8', 0, options.verbose ? 1000 : 40).trim() + '...\n';
		}

		var fileObj =
			(file.cwd ? 'cwd:      ' + prop(tildify(file.cwd)) : '') +
			(file.base ? '\nbase:     ' + prop(tildify(file.base)) : '') +
			(file.path ? '\npath:     ' + prop(tildify(file.path)) : '') +
			(file.stat && options.verbose ? '\nstat:     ' + prop(stringifyObject(file.stat)) : '') +
			(file.contents ? '\ncontents: ' + prop(trim(file.contents)) : '');

		gutil.log(
			'gulp-debug: ' + title + chalk.gray('(' + dateTime() + ')') + '\n\n' +
			header('File\n') + fileObj
		);

		cb(null, file);
	}, function (cb) {
示例#16
0
// callback is loaded `env` which passed from `LiftOff` instance
// you could tweak the `env` properties in `runner.js` `G.launch(opts, cb);`
function callback (env) {
  validEmberRockProject(env);
  validGulpVersion(env);

  // this is what actually loads up the gulpfile
  require(env.configPath);
  var gulpInst = require(env.modulePath);

  logEvents(gulpInst);
  gutil.log('Using gulpfile', gutil.colors.magenta(tildify(env.configPath)));

  process.nextTick(function () {
    gulpInst.start.apply(gulpInst, [callback.command]);
  });
}
示例#17
0
module.exports = function(pkg, fn){
  var bin = path.resolve(path.current(pkg) + '/bin');

  if(process.env.PATH.indexOf(bin) === -1){
    process.env.PATH = bin + ':' + process.env.PATH;
    debug('added to PATH %s', tildify(bin));
  }

  fs.remove(path.current(pkg), function(){
    fs.symlink(path.dest(pkg), path.current(pkg), function(err){
      if(err) return fn(err);
      debug('symlinked %s -> %s', tildify(path.current(pkg)), tildify(path.dest(pkg)));
      fn();
    });
  });
};
示例#18
0
/**
 * Interpret a color/title/badge setting string,
 * using a default value if need be.
 */
function settingString(s, category) {
  var finalS = s
  if ((s === true) || (!s)) {
    finalS = config.defaults[category]
  }
  if (ARGS_DEBUG)
    console.log('s:', s, 'finalS:', finalS, 'cwd:', cwd)
  if ((finalS === '~') || (finalS == process.env['HOME'])) {
    return tildify(cwd)
  } else if ((finalS === '.') || (finalS === cwd)){
    return path.basename(cwd)
  }
  if (ARGS_DEBUG)
    console.log('backup return')
  return finalS
}
function tryRead(filename, logErrors) {
    var content, err = false;
    try {
        //console.log('tryRead: ' + filename);
        content = fs.readFileSync(filename, 'utf-8')
    } catch(e) {
        if (logErrors) {
            gutil.log('config file not found: ', gutil.colors.red(filename));
        }
        err = true;
    }
    if (!err) {
        gutil.log('Loaded config file', gutil.colors.green(tildify(filename)));
        content = YAML.parse(content);
    }
    return content;
}
示例#20
0
文件: init.js 项目: 450703035/blog
function initConsole(args) {
  args = assign({
    install: true,
    clone: true
  }, args);

  var baseDir = this.base_dir;
  var target = args._[0] ? pathFn.resolve(baseDir, args._[0]) : baseDir;
  var log = this.log;
  var promise;

  log.info('Cloning hexo-starter to', chalk.magenta(tildify(target)));

  if (args.clone) {
    promise = spawn('git', ['clone', '--recursive', GIT_REPO_URL, target], {
      stdio: 'inherit'
    });
  } else {
    promise = copyAsset(target);
  }

  return promise.catch(function() {
    log.warn('git clone failed. Copying data instead');

    return copyAsset(target);
  }).then(function() {
    return Promise.all([
      removeGitDir(target),
      removeGitModules(target)
    ]);
  }).then(function() {
    if (!args.install) return;

    log.info('Install dependencies');

    return spawn('npm', ['install', '--production'], {
      cwd: target,
      stdio: 'inherit'
    });
  }).then(function() {
    log.info('Start blogging with Hexo!');
  }).catch(function() {
    log.warn('Failed to install dependencies. Please run \'npm install\' manually!');
  });
}
示例#21
0
  process.nextTick(function() {
    var tree;

    if (opts.tasksSimple) {
      return logTasksSimple(env, gulpInst);
    }
    if (opts.tasks) {
      tree = taskTree(gulpInst.tasks);
      if (config.description && isString(config.description)) {
        tree.label = config.description;
      } else {
        tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
      }
      return logTasks(tree, opts, function(task) {
        return gulpInst.tasks[task].fn;
      });
    }
    gulpInst.start.apply(gulpInst, toRun);
  });
示例#22
0
function handleArguments(env) {
  if (argv.verbose) {
    console.log(chalk.yellow('LIFTOFF SETTINGS:'), this);
    console.log(chalk.yellow('CLI OPTIONS:'), argv);
    console.log(chalk.yellow('CWD:'), env.cwd);
    console.log(chalk.red('APP CONFIG LOCATION:'),  env.configPath);
    console.log(chalk.red('APP CONFIG BASE DIR:'), env.configBase);
    console.log(chalk.cyan('KALABOX MODULE LOCATION:'), this.modulePath);
    console.log(chalk.cyan('KALABOX PACKAGE.JSON LOCATION:'), this.modulePackage);
    console.log(chalk.cyan('KALABOX PACKAGE.JSON'), require('../package'));
  }

  var workingDir = env.cwd;
  var configPath = path.join(env.cwd, '.kalabox', 'profile.json');

  if (argv.app) {
    var apppath = path.resolve(kconfig.appDataPath, argv.app);
    if (!fs.existsSync(apppath) || !fs.existsSync(path.resolve(apppath, 'app.json'))) {
      console.log(chalk.red('App config not found.'));
      process.exit(1);
    }

    // Load up the app data from ~/.kalabox/apps/<app>/app.json
    var appdata = require(path.resolve(apppath, 'app.json'));
    workingDir = appdata.path;
    configPath = path.resolve(appdata.profilePath, 'profile.json');
  }

  if (fs.existsSync(configPath)) {
    process.chdir(workingDir);
    env.app = new App(manager, workingDir);
  }

  env.manager = manager;

  if (argv.verbose) {
    console.log(chalk.red('APP CONFIG:'), env.config);
    console.log('Using config file', chalk.magenta(tildify(env.configPath)));
  }

  processTask(env);
}
示例#23
0
    fs.exists(dest, function(exists) {
      if (exists) {
        debug('already have artifact ' + dest);
        cleanup.clear();
        return fn();
      }

      debug('downloading %s to %s', url, tildify(dest));
      var out = fs.createWriteStream(dest)
          .on('error', fn)
          .on('finish', function() {
            cleanup.clear();
            fn(null, dest);
          }),
        req = request(url);
      req.on('response', function(res) {
        var total = parseInt(res.headers['content-length'], 10);
        debug('total size %dMB', (total / 1024 / 1024).toFixed(2));

        if (!total) {
          return fn(new Error('No response.  Are you sure ' + pkg.version + ' is the right version?'));
        }

        console.log();
        var bar = new ProgressBar('  Downloading MongoDB v' + pkg.version + ' [:bar] :percent :etasec', {
          complete: '=',
          incomplete: ' ',
          width: 40,
          total: total
        });

        res.on('data', function(chunk) {
          bar.tick(chunk.length);
        });

        res.on('end', function() {
          console.log('\n');
        });
      });
      req.pipe(out);
      req.on('error', fn);
    });
示例#24
0
function execute(opts, env, config) {
  var tasks = opts._;
  var toRun = tasks.length ? tasks : ['default'];

  if (opts.tasksSimple || opts.tasks) {
    // Mute stdout if we are listing tasks
    stdout.mute();
  }

  // This is what actually loads up the gulpfile
  var exported = require(env.configPath);
  log.info('Using gulpfile', chalk.magenta(tildify(env.configPath)));

  var gulpInst = require(env.modulePath);
  logEvents(gulpInst);

  registerExports(gulpInst, exported);

  // Always unmute stdout after gulpfile is required
  stdout.unmute();

  process.nextTick(function() {
    var tree;

    if (opts.tasksSimple) {
      return logTasksSimple(env, gulpInst);
    }
    if (opts.tasks) {
      tree = taskTree(gulpInst.tasks);
      if (config.description && isString(config.description)) {
        tree.label = config.description;
      } else {
        tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
      }
      return logTasks(tree, opts, function(task) {
        return gulpInst.tasks[task].fn;
      });
    }
    gulpInst.start.apply(gulpInst, toRun);
  });
}
  }).then(function(config){
    if (!config || typeof config !== 'object') return;

    ctx.log.debug('Config loaded: %s', chalk.magenta(tildify(configPath)));

    config = _.extend(ctx.config, config);
    ctx.config_path = configPath;

    config.root = config.root.replace(/\/*$/, '/');
    config.url = config.url.replace(/\/+$/, '');

    ctx.public_dir = pathFn.resolve(baseDir, config.public_dir) + sep;
    ctx.source_dir = pathFn.resolve(baseDir, config.source_dir) + sep;
    ctx.source = new Source(ctx);

    if (!config.theme) return;

    config.theme = config.theme.toString();
    ctx.theme_dir = pathFn.join(baseDir, 'themes', config.theme) + sep;
    ctx.theme_script_dir = pathFn.join(ctx.theme_dir, 'scripts') + sep;
    ctx.theme = new Theme(ctx);
  });
示例#26
0
文件: menu.js 项目: bocoup/js-learn
function choose (context, menu, name, idx) {
  const exercise = context.exercises[idx];
  const src = path.join(context.exercisesDir, exercise);
  const dest = path.join(process.cwd(), exercise);
  let waitForCopy = LONG_PAUSE;
  try {
    fs.lstatSync(dest).isDirectory();
    waitForCopy = 0;
  } catch (e) {
    menu.write(CLEAR);
    menu.write(`Copying files to ${tildify(dest)}...`);
    setTimeout(() => { menu.write(CLEAR) }, LONG_PAUSE);
    wrench.copyDirSyncRecursive(src, dest);
  }
  setTimeout(() => {
    menu.write(CLEAR);
    menu.write('Opening exercise in browser...');
    setTimeout(() => {
      open(`http://localhost:8000/exercise/${exercise}`);
      menu.write(CLEAR);
    }, SHORT_PAUSE);
  }, waitForCopy);
}
示例#27
0
function initKnex(env) {
  checkLocalModule(env);

  if (!env.configPath) {
    exit('No knexfile found in this directory. Specify a path with --knexfile');
  }

  if (process.cwd() !== env.cwd) {
    process.chdir(env.cwd);
    console.log(
      'Working directory changed to',
      chalk.magenta(tildify(env.cwd))
    );
  }

  var environment = commander.env || process.env.NODE_ENV;
  var defaultEnv = 'development';
  var config = require(env.configPath);

  if (!environment && typeof config[defaultEnv] === 'object') {
    environment = defaultEnv;
  }

  if (environment) {
    console.log('Using environment:', chalk.magenta(environment));
    config = config[environment] || config;
  }

  if (!config) {
    console.log(chalk.red('Warning: unable to read knexfile config'));
    process.exit(1);
  }

  if (argv.debug !== undefined) config.debug = argv.debug;
  var knex = require(env.modulePath);
  return knex(config);
}
示例#28
0
function download(model, done) {
  debug('downloading artifact from `%s` to `%s`...',
    model.url, tildify(model.directory));

  var quiet = process.env.silent;
  var options = {
    extract: true,
    strip: 1,
    retries: 3
    // filename: model.filename,
    // output: model.directory

  };
  debug(model.url, model.root_directory, options);
  dl(model.url, model.root_directory, options).then(function() {
    debug('successfully downloaded MongoDB version v%s to %s',
      model.version, model.root_directory);
    if (!quiet) {
      console.log(chalk.bold.green(figures.tick),
        ' Downloaded MongoDB', model.version);
    }
    done();
  })
  .catch(function(err) {
    debug('error downloading!', err);
    console.error(err);
    done(err);

    // debug('removing incomplete artifact from `%s`',
    //   model.root_directory);
    //
    // fs.unlink(model.root_directory, function() {
    //   done(err);
    // });
  });
}
示例#29
0
function checkLocalModule(env) {
  if (!env.modulePath) {
    console.log(chalk.red('No local knex install found in:'), chalk.magenta(tildify(env.cwd)));
    exit('Try running: npm install knex.');
  }
}
示例#30
0
 return fs.stat(publicDir).then(function(stats) {
   if (!stats.isDirectory()) {
     throw new Error('%s is not a directory', chalk.magenta(tildify(publicDir)));
   }
 }).catch(function(err) {