Ejemplo n.º 1
0
function checkMessage(msg) {

  const msgPattern = preGit.customMsgPattern();
  
  if (msgPattern) {
    checkMessageAgainstPattern(msg, msgPattern);
  }

  const wizard = preGit.wizard();
  if (!wizard) {
    log('no commit message wizard defined');
    process.exit(0);
  }

  log('found commit message wizard with name', wizard.name);

  la(check.fn(wizard.validate),
      'missing wizard validate method,', Object.keys(wizard));
  la(check.fn(preGit.printError),
      'missing preGit.printError,', Object.keys(preGit));

  log('checking commit message:', msg);
  const isValid = wizard.validate(msg);
  if (!isValid) {
    log('invalid commit message', msg);
    process.exit(-1);
  }
  log('valid git commit message');
}
Ejemplo n.º 2
0
 it('can make multiple setters', () => {
   const o = {}
   const set = littleStore(o)
   const setFoo = set('foo')
   const setBar = set('bar')
   la(is.fn(setFoo))
   la(is.fn(setBar))
   setFoo(42)
   setBar(-1)
   la(o.foo === 42, o)
   la(o.bar === -1, o)
 })
function checkForFile (filename) {
  la(is.unemptyString(filename), 'expected filename', filename)
  const name = path.basename(filename)
  const check = nameToCheck[name]
  la(is.fn(check), 'not a check function for', name, check)

  function readFile () {
    return Promise.resolve(read(filename, 'utf-8'))
  }

  if (is.fn(check)) {
    log('checking file', filename)
    return check(readFile)
  }
}
Ejemplo n.º 4
0
  it('parses line', function () {
    la(check.fn(parse));

    var result = parse('M\tfoo.js');
    la(result.diff === 'M', result);
    la(result.name === 'foo.js', result);
  });
Ejemplo n.º 5
0
function proxyExports(options, exports, filename) {
  options = options || {};

  la(check.unemptyString(filename), 'missing loaded filename');
  console.log('loaded', filename);

  if (!check.has(used, filename)) {
    used[filename] = false;
  }

  if (isPrimitive(exports)) {
    used[filename] = true;
    return exports;
  }

  if (check.fn(exports)) {
    console.log('proxying a function', quote(exports.name));
    return function proxyFn() {
      used[filename] = true;
      return exports.apply(null, arguments);
    };
  }

  return exports;
}
Ejemplo n.º 6
0
passport.serializeUser(function(user, done) {
  la(check.object(user), 'expected user object');
  la(check.fn(done), 'expected done callback');
  la(check.unemptyString(user.id || user.email),
    'expected user id or email to be a string', Object.keys(user));
  done(null, user.id || user.email);
});
Ejemplo n.º 7
0
 it('can make a setter', () => {
   const o = {}
   const setFoo = littleStore(o, 'foo')
   la(is.fn(setFoo))
   setFoo(42)
   la(o.foo === 42, o)
 })
Ejemplo n.º 8
0
 it('finds the solution', () => {
   const solution = solve(input, output)
   la(solution, 'returns solution', solution)
   la(isNamed(solution), solution)
   la(is.fn(solution.f), 'finds function')
   la(solution.name === 'R.flatten', solution)
 })
Ejemplo n.º 9
0
 it('replaces spaced arguments', function () {
   la(check.fn(replace));
   var result = replace(pkg, ['something', 'pkg.name']);
   la(check.array(result));
   la(result.length === 2);
   la(result[0] === 'something');
   la(result[1] === 'foo');
 });
Ejemplo n.º 10
0
function createUserStore(pouchDb) {
  la(pouchDb, 'expected pouch db');
  la(check.fn(pouchDb.store), 'missing pouch store function, use store.pouchdb');
  var User = pouchDb.store();

  User.gravatar = userGravatar;

  return User;
}
Ejemplo n.º 11
0
// maybe we can just keep passing around expressions instead of forming functions?
function lookupRamdaFunction (name) {
  la(is.unemptyString(name), 'missing ramda function', name)
  /*eslint-disable no-eval*/
  const f = eval(name)
  la(is.fn(f), 'could not lookup name', name)
  return {
    f: f,
    name: name
  }
}
Ejemplo n.º 12
0
function testExamples (tester, examples, fn) {
  la(is.fn(tester), 'missing tester function')
  if (is.not.fn(fn)) {
    return false
  }

  la(is.array(examples), 'invalid examples', examples)
  return examples.every((example) => {
    la(is.array(example) && example.length === 2, 'invalid example', example)
    // console.log('testing example', example[0], example[1])
    return tester(example[0], example[1], fn)
  })
}
Ejemplo n.º 13
0
function isValidMessage(message) {
  if (!wizard) {
    return message;
  }

  la(check.unemptyString(message), 'missing message');

  const first = firstLine(message);

  if (!check.unemptyString(first)) {
    return Promise.reject(new Error('missing first line'));
  }
  if (check.fn(wizard.validate)) {
    if (!wizard.validate(message)) {
      return Promise.reject(new Error('Invalid commit message\n' + message));
    }
  }
  return message;
}
Ejemplo n.º 14
0
function load(filename, options) {
  check.verify.string(filename, 'missing filename');
  var content = fs.readFileSync(filename, 'utf-8');
  check.verify.string(content, 'missing content from ' + filename);
  var lines = content.split(eol);
  console.assert(lines.length > 1, 'invalid number of lines ' +
    lines.length + ' in file ' + filename);

  var splitToColumns = options && check.fn(options.getColumns)
    ? options.getColumns : getColumns;

  var results = [];
  var columns = stripQuotes(splitToColumns(lines[0], 0));

  check.verify.array(columns, 'could not get columns from first line ' +
    lines[0]);
  lines.forEach(function (line, index) {
    if (index === 0) {
      return; // we already have columns
    }
    if (!line) {
      return;
    }

    var obj = {};
    var values = stripQuotes(splitToColumns(line, index));

    check.verify.array(values, 'could not get values from line ' + line);
    console.assert(values.length === columns.length,
      'expected values from line ' + line + ' to match property names ' +
      ' from first line ' + lines[0]);

    values.forEach(function (value, columnIndex) {
      obj[columns[columnIndex]] = value;
    });
    results.push(obj);
  });

  return results;
}
Ejemplo n.º 15
0
 it('should return an Observable of products', () => {
   la(is.fn(observableFindAllProducts.findAllWithLowStock({ limit: 10, offset: 0 }).subscribe), 'has subscribe method');
 });
Ejemplo n.º 16
0
'use strict'

var la = require('lazy-ass')
var is = require('check-more-types')
var run = require('./npm-test')
var debug = require('debug')('npm-utils')
var q = require('q')

la(is.fn(run), 'expected function')

function publish (options) {
  options = options || {}
  var command = 'npm publish'
  if (is.unemptyString(options.tag)) {
    debug('publishing with a tag', options.tag)
    command += ' --tag ' + options.tag
  }

  if (is.unemptyString(options.access)) {
    debug('publishing with specific access', options.access)
    command += ' --access ' + options.access
  }

  return run(command)
    .catch(function (info) {
      debug('publishing hit an error')
      debug(info)
      la(is.string(info.testErrors), 'missing test errors string', info)
      return q.reject(new Error(info.testErrors))
    })
}
Ejemplo n.º 17
0
 it('should return an Observable of products', () => {
   la(is.fn(observableFindProducts.findProductByBarcode({ barcode: '0001' }).subscribe), 'has subscribe method');
 });
Ejemplo n.º 18
0
 it('is a function', () => {
   la(is.fn(chdir.nextTo))
 })
Ejemplo n.º 19
0
 it('is a function', () => {
   la(is.fn(chdir.back))
 })
Ejemplo n.º 20
0
 it('is a function', () => {
   la(is.fn(install))
 })
Ejemplo n.º 21
0
 it('is is a function', function () {
   la(check.fn(confirm))
 })
 it('returns a function', () => {
   const report = init()
   la(is.fn(report))
 })
 it('init is a function', () => {
   la(is.fn(init))
 })
Ejemplo n.º 24
0
'use strict'

var q = require('q')
var la = require('lazy-ass')
var check = require('check-more-types')
var isRepoUrl = require('./is-repo-url')
var debug = require('debug')('dont-break')
var exists = require('fs').existsSync
var rimraf = require('rimraf')
var chdir = require('chdir-promise')

var npmInstall = require('npm-utils').install
var postinstall = require('npm-utils').test
la(check.fn(npmInstall), 'install should be a function', npmInstall)
la(check.fn(postinstall), 'postinstall should be a function', postinstall)
var cloneRepo = require('ggit').cloneRepo

function removeFolder (folder) {
  if (exists(folder)) {
    debug('removing folder %s', folder)
    rimraf.sync(folder)
  }
}

function install (options) {
  var postInstall = function (arg) {
    if (options.postinstall) {
      console.log('running ' + options.postinstall + ' in %s', process.cwd())
      return postinstall(options.postinstall).then(function () {
        return arg
      })
 it('is a function', function () {
   la(is.fn(split))
 })
Ejemplo n.º 26
0
 it('should return an Observable of categories', () => {
   la(is.fn(observableCategories.findAll().subscribe), 'has subscribe method');
 });
Ejemplo n.º 27
0
 it('is a function', function () {
   la(check.fn(parse));
 });
Ejemplo n.º 28
0
 it('is a function', function () {
   la(check.fn(banner))
 })
 it('is a function', function () {
   la(is.fn(toHuman))
 })
Ejemplo n.º 30
0
#!/usr/bin/env node

console.log('running commit-wizard in folder %s', process.cwd());
const la = require('lazy-ass');
const check = require('check-more-types');
const join = require('path').join;
const pkgPath = join(process.cwd(), 'package.json');
const pkg = require(pkgPath);
const preGit = require('pre-git');
const git = require('ggit');
const chalk = require('chalk');
const log = require('debug')('pre-git');
la(check.fn(log), 'missing debug log', log);

/* jshint -W079 */
const Promise = require('bluebird');

const label = 'pre-commit';

const config = pkg.config &&
  pkg.config['pre-git'];

const wizard = preGit.wizard();
la(check.maybe.object(wizard),
  'could not get commit message wizard', wizard);

function getPreCommitCommands(config) {
  if (!config) {
    return;
  }
  const preCommit = config[label];