Advertisement
Guest User

Untitled

a guest
Sep 7th, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var fs = require('fs');
  4. var path = require('path');
  5. var nopt = require('nopt');
  6. var chalk = require('chalk');
  7. var _ = require('lodash');
  8. var pkg = require('../package.json');
  9. var updateNotifier = require('update-notifier');
  10. var sudoBlock = require('sudo-block');
  11. var Insight = require('insight');
  12.  
  13. var opts = nopt({
  14. help: Boolean,
  15. version: Boolean
  16. }, {
  17. h: '--help',
  18. v: '--version'
  19. });
  20.  
  21. var args = opts.argv.remain;
  22. var cmd = args[0];
  23.  
  24. var intro = _.template(fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf8'));
  25.  
  26. var insight = new Insight({
  27. trackingCode: 'UA-31537568-1',
  28. packageName: pkg.name,
  29. packageVersion: pkg.version
  30. });
  31.  
  32. if (opts.insight === false) {
  33. insight.config.set('optOut', true);
  34. } else if (opts.insight) {
  35. insight.config.set('optOut', false);
  36. }
  37.  
  38. /*jshint multistr:true */
  39. var insightMsg = chalk.gray('\
  40. ==========================================================================') + chalk.yellow('\n\
  41. We\'re constantly looking for ways to make ') + chalk.bold.red(pkg.name) + chalk.yellow(' better! \n\
  42. May we anonymously report usage statistics to improve the tool over time? \n\
  43. More info: yeoman.io/insight.html & http://yeoman.io') + chalk.gray('\n\
  44. ==========================================================================');
  45.  
  46.  
  47. function rootCheck() {
  48. var msg = chalk.red('Easy with the "sudo"; Yeoman is the master around here.') + '\n\
  49. Since yo is a user command, there is no need to execute it with superuser\n\
  50. permissions. If you\'re having permission errors when using yo without sudo,\n\
  51. please spend a few minutes learning more about how your system should work\n\
  52. and make any necessary repairs.\n\n\
  53. http://www.joyent.com/blog/installing-node-and-npm\n\
  54. https://gist.github.com/isaacs/579814\n';
  55.  
  56. sudoBlock({ message: msg });
  57. }
  58.  
  59. function init() {
  60. var env = require('yeoman-generator')();
  61.  
  62. // register each built-in generator individually
  63. env.plugins('node_modules', __dirname);
  64.  
  65. // alias any single namespace to `*:all` and `webapp` namespace specifically
  66. // to webapp:app.
  67. env.alias(/^([^:]+)$/, '$1:all');
  68. env.alias(/^([^:]+)$/, '$1:app');
  69.  
  70. // lookup for every namespaces, within the environments.paths and lookups
  71. env.lookup('*:*');
  72.  
  73. env.on('end', function () {
  74. console.log('Done running sir');
  75. });
  76.  
  77. env.on('error', function (err) {
  78. console.error('Error', process.argv.slice(2).join(' '), '\n');
  79. console.error(opts.debug ? err.stack : err.message);
  80. process.exit(err.code || 1);
  81. });
  82.  
  83. // Register the `yo yo` generator.
  84. if (!cmd) {
  85. if (opts.help) {
  86. return console.log(env.help('yo'));
  87. }
  88.  
  89. env.register(path.resolve(__dirname, './yoyo'), 'yo');
  90. args = ['yo'];
  91. // make the insight instance available in `yoyo`
  92. opts = { insight: insight };
  93. }
  94.  
  95. // Note: at some point, nopt needs to know about the generator options, the
  96. // one that will be triggered by the below args. Maybe the nopt parsing
  97. // should be done internally, from the args.
  98. env.run(args, opts);
  99. }
  100.  
  101. function pre() {
  102. if (opts.version) {
  103. return console.log(pkg.version);
  104. }
  105.  
  106. if (!cmd) {
  107. console.log(intro({ supportsColor: chalk.supportsColor }));
  108. }
  109.  
  110. init();
  111. }
  112.  
  113. if (!process.env.yeoman_test && opts.insight !== false) {
  114. if (insight.optOut === undefined) {
  115. insight.optOut = insight.config.get('optOut');
  116. insight.track('downloaded');
  117. insight.askPermission(insightMsg, pre);
  118. return;
  119. }
  120. // only track the two first subcommands
  121. insight.track.apply(insight, args.slice(0, 2));
  122. }
  123.  
  124. if (!process.env.yeoman_test && opts['update-notifier'] !== false) {
  125. var notifier = updateNotifier({
  126. packagePath: '../package'
  127. });
  128.  
  129. if (notifier.update) {
  130. notifier.notify(true);
  131. }
  132. }
  133.  
  134. rootCheck();
  135. pre();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement