UNPKG

rollup-umd-scripts

Version:

CLI for rollup-umd projects

116 lines (103 loc) 3.38 kB
'use strict'; var _keys = require('babel-runtime/core-js/object/keys'); var _keys2 = _interopRequireDefault(_keys); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /* eslint-disable */ var async = require('async'); var path = require('path'); /** define the state where is has not been release yet, * only gitlab and local installation of the module are possible */ exports.isPrivate = function (argv, cb) { var packageJsonPath = path.join(argv.path, 'package.json'); var pkg = require(packageJsonPath); if (pkg.release.npmPublish) { if (cb) cb(null, false); return false; } if (cb) cb(null, true); return true; }; /** define the state where it has been release on npm the private registry */ exports.isProtected = function (argv, cb) { var isPrivate = exports.isPrivate(argv); var isPublic = exports.isPublic(argv); var isTransitive = exports.isTransitive(argv); var isProtected = !isPrivate && !isPublic && !isTransitive; if (cb) cb(null, isProtected); return isProtected; }; /** define the state where is has been release to github */ exports.isPublic = function (argv, cb) { var packageJsonPath = path.join(argv.path, 'package.json'); var pkg = require(packageJsonPath); var isPublic = pkg.repository.url.indexOf('github.com') !== -1; if (cb) cb(null, isPublic); return isPublic; }; /** define the state where in the next release, we will pipe the project to GitHub */ exports.isTransitive = function (argv, cb) { var packageJsonPath = path.join(argv.path, 'package.json'); var pkg = require(packageJsonPath); var isTransitive = typeof pkg.private === 'undefined'; if (cb) cb(null, isTransitive); return isTransitive; }; function getBadgeUrl(status) { var badges = { private: 'https://img.shields.io/badge/publishing-private-red.svg', protected: 'https://img.shields.io/badge/publishing-protected-orange.svg', public: 'https://img.shields.io/badge/publishing-public-blue.svg' }; badges.transitive = badges.public; return badges[status]; } exports.command = 'status'; exports.desc = 'Display publishing status'; exports.builder = function (yargs) { return yargs.option('path', { alias: 'p', describe: 'path', default: process.cwd() }).option('badge', { alias: 'b', default: false, describe: 'Display the shields badge url' }); }; exports.handler = function (argv) { switch (argv.path[0]) { case '/': break; default: argv.path = argv.path[1] === '/' ? path.join(process.cwd(), argv.path.slice(2)) : path.join(process.cwd(), argv.path); break; } var end = function end(status) { console.log(argv.badge ? getBadgeUrl(status) : status); }; async.auto({ private: function _private(cb) { return exports.isPrivate(argv, cb); }, protected: function _protected(cb) { return exports.isProtected(argv, cb); }, public: function _public(cb) { return exports.isPublic(argv, cb); }, transitive: function transitive(cb) { return exports.isTransitive(argv, cb); } }, function (err, results) { (0, _keys2.default)(results).forEach(function (key) { if (results[key]) { end(key); process.exit(); } }); if (err) { console.error('[ERROR] ' + err.message); process.exit(1); } }); };