Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate locales/*.json; package.json #8

Open
nfreear opened this issue Jun 6, 2017 · 0 comments
Open

Validate locales/*.json; package.json #8

nfreear opened this issue Jun 6, 2017 · 0 comments

Comments

@nfreear
Copy link
Owner

nfreear commented Jun 6, 2017


bin/nice.js:

#!/usr/bin/env node

const Package = require('nice-package');
const path = require('path');
const pkg = new Package(require(path.join(__dirname, '/../package.json')));

console.log('nice-package? %s', pkg.valid);
console.log(pkg.validationErrors);

process.exit(pkg.valid ? 0 : 1);

bin/lintl.js:

#!/usr/bin/env node

/**
 * Node CLI. Validate the locale JSON files.
 */
const revalidator = require('revalidator');
const path = require('path');
const LOCALE_DIR = path.join(__dirname, '/../locales/');

var result = {};
var allValid = true;

require('fs').readdirSync(LOCALE_DIR).forEach(function (file) {
  var lname = file.replace('.json', '');
  var locale = require(path.join(LOCALE_DIR, file));

  result[ file ] = revalidator.validate(locale, {
    properties: {
      name: {
        type: 'string',
        required: false
      },
      before: {
        type: 'string',
        required: true
      },
      after: {
        type: 'string',
        required: true
      },
      url: {
        type: 'string',
        // format: 'url', ?
        required: false
      }
    }
  });
  result[ file ].file = file;

  allValid = allValid && result[ file ].valid;

  console.dir(result[ file ]);
});

console.log('Locale JSON valid? %s', allValid);
process.exit(allValid ? 0 : 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant