atomic-cli.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. #!/usr/bin/env node
  2. "use strict";
  3. // https://github.com/yeoman/update-notifier
  4. // https://github.com/tj/commander.js
  5. var path = require("path");
  6. var fs = require("fs");
  7. var program = require('commander');
  8. var cli = require("atomic-cli")
  9. var open = require("open");
  10. var prompt = require('prompt');
  11. var osenv = require('osenv')
  12. prompt.message = "";
  13. prompt.delimiter = "";
  14. var saveAtomicConfig = function(activated) {
  15. var directory = osenv.home() + "/.atomicgameengine";
  16. if (!fs.existsSync(directory)) {
  17. fs.mkdir(directory);
  18. }
  19. var config = {
  20. "nodePath" : process.execPath,
  21. "cliScript" : __filename,
  22. "activated" : activated
  23. }
  24. fs.writeFile(directory + "/config.json", JSON.stringify(config, null, 4), function(err) {
  25. if(err) {
  26. console.log(err);
  27. } else {
  28. //console.log("config saved to " + directory + "/config.json");
  29. }
  30. });
  31. }
  32. program
  33. .version('0.0.1')
  34. // activation command
  35. program
  36. .command('activate')
  37. .description('activate')
  38. .action(function(folder){
  39. prompt.start();
  40. prompt.get([ { description: 'Please confirm EULA agreement (Y)es, (N)o, or (V)iew', default: "Y", name: "eulaconfirm" }], function (err, result) {
  41. var eulaconfirm = result.eulaconfirm.toLowerCase();
  42. if (eulaconfirm == 'y') {
  43. prompt.get([ { description: 'Please enter Product Key or (G)et free key: ', name: "productkey" }], function (err, result) {
  44. var productkey = result.productkey.toLowerCase();
  45. if (productkey == 'g') {
  46. console.log ("Opening Atomic Store in default browser window");
  47. open("https://store.atomicgameengine.com/site");
  48. } else {
  49. cli.activate(productkey)
  50. .then(function () {
  51. saveAtomicConfig(true);
  52. })
  53. }
  54. });
  55. } else if (eulaconfirm == 'v') {
  56. console.log ("Opening EULA in default browser window");
  57. open("https://github.com/AtomicGameEngine/AtomicGameEngine/blob/master/LICENSE.md");
  58. }
  59. });
  60. });
  61. // deactivation
  62. program
  63. .command('deactivate')
  64. .description('deactivates and returns a product activation to the server')
  65. .action(function(){
  66. cli.deactivate().
  67. then(function() {
  68. saveAtomicConfig(false);
  69. })
  70. });
  71. // new project command
  72. program
  73. .command('new <folder>')
  74. .description('creates a new project in the specified folder')
  75. .action(function(folder){
  76. cli.newProject(folder)
  77. .then(function () {
  78. console.log("New Atomic project created in " + path.resolve(folder));
  79. })
  80. .catch(function (error) {
  81. console.error("Error: Could not create " + path.resolve(folder));
  82. process.exit(1);
  83. });
  84. });
  85. program
  86. .command('add <platform>')
  87. .description('adds a platform to the project')
  88. .action(function(platform){
  89. cli.addPlatform(platform)
  90. .then(function () {
  91. })
  92. .catch(function (error) {
  93. process.exit(1);
  94. });
  95. });
  96. program
  97. .command('run <platform>')
  98. .option('--project <path>')
  99. .description('runs the project on a specified platform')
  100. .action(function(platform, options) {
  101. if(options.project) {
  102. process.chdir(options.project)
  103. }
  104. cli.run(platform)
  105. .then(function () {
  106. })
  107. .catch(function (error) {
  108. process.exit(1);
  109. });
  110. });
  111. program
  112. .command('build <platform>')
  113. .option('--project <path>')
  114. .description('builds the project for the specified platform')
  115. .action(function(platform, options) {
  116. if(options.project) {
  117. process.chdir(options.project)
  118. }
  119. cli.build(platform)
  120. .then(function () {
  121. })
  122. .catch(function (error) {
  123. process.exit(1);
  124. });
  125. });
  126. program
  127. .command('edit [path_to_project]')
  128. .description('edits the project in the cwd or on at a specified path')
  129. .action(function(path_to_project, options){
  130. var path = path_to_project || process.cwd();
  131. cli.atomiceditor(["-project", path], {output:true});
  132. });
  133. // http server
  134. program
  135. .command('serve')
  136. .option('-p, --port [8000]', 'The port to run the server on [8000]', '8000')
  137. .description('start a http server on the specified port which serves the current folder')
  138. .action(function(options) {
  139. var args = {}
  140. args.port = options.port;
  141. var server = require("../lib/httpserver");
  142. server.run(args)
  143. });
  144. program.parse(process.argv);
  145. if (!program.args.length) program.help();