index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. let prompt = require('prompt');
  2. let shelljs = require('shelljs');
  3. let fs = require('fs-extra');
  4. let basePath = '../../dist/preview release';
  5. // This can be changed when we have a new major release.
  6. let minimumDependency = '>=3.2.0-alpha';
  7. let packages = [
  8. {
  9. name: 'core',
  10. path: '../../'
  11. },
  12. {
  13. name: 'gui',
  14. path: basePath + '/gui/'
  15. },
  16. {
  17. name: 'materials',
  18. path: basePath + '/materialsLibrary/'
  19. },
  20. {
  21. name: 'postProcess',
  22. path: basePath + '/postProcessesLibrary/'
  23. },
  24. {
  25. name: 'loaders',
  26. path: basePath + '/loaders/'
  27. },
  28. {
  29. name: 'serializers',
  30. path: basePath + '/serializers/'
  31. },
  32. {
  33. name: 'proceduralTextures',
  34. path: basePath + '/proceduralTexturesLibrary/'
  35. },
  36. {
  37. name: 'inspector',
  38. path: basePath + '/inspector/'
  39. },
  40. {
  41. name: 'viewer',
  42. path: basePath + '/viewer/'
  43. }
  44. ];
  45. //check if logged in
  46. console.log("Using npm user:");
  47. let loginCheck = shelljs.exec('npm whoami');
  48. console.log("Not that I can check, but - did you run gulp typescript-all?");
  49. if (loginCheck.code === 0) {
  50. prompt.start();
  51. prompt.get(['version'], function (err, result) {
  52. let version = result.version;
  53. packages.forEach((package) => {
  54. if (package.name === "core") {
  55. processCore(package, version);
  56. } else {
  57. let packageJson = require(package.path + 'package.json');
  58. packageJson.version = version;
  59. if (packageJson.peerDependencies) packageJson.peerDependencies.babylonjs = minimumDependency;
  60. fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
  61. console.log('Publishing ' + package.name + " from " + package.path);
  62. //publish the respected package
  63. shelljs.exec('npm publish \"' + package.path + "\"");
  64. }
  65. });
  66. console.log("done, please don't forget to commit the changes")
  67. });
  68. } else {
  69. console.log('not logged in.');
  70. }
  71. function processCore(package, version) {
  72. let packageJson = require(package.path + 'package.json');
  73. // make a temporary directory
  74. fs.ensureDirSync(basePath + '/package/');
  75. let files = [
  76. {
  77. path: basePath + "/babylon.d.ts",
  78. objectName: "babylon.d.ts"
  79. },
  80. {
  81. path: basePath + "/es6.js",
  82. objectName: "es6.js"
  83. },
  84. {
  85. path: basePath + "/babylon.js",
  86. objectName: "babylon.js"
  87. },
  88. {
  89. path: basePath + "/babylon.max.js",
  90. objectName: "babylon.max.js"
  91. },
  92. {
  93. path: basePath + "/babylon.worker.js",
  94. objectName: "babylon.worker.js"
  95. },
  96. {
  97. path: basePath + "/Oimo.js",
  98. objectName: "Oimo.js"
  99. },
  100. {
  101. path: package.path + "readme.md",
  102. objectName: "readme.md"
  103. }
  104. ];
  105. fs.readdirSync(basePath + '/modules/').forEach(object => {
  106. console.log(object);
  107. if (fs.statSync(basePath + '/modules/' + object).isDirectory) {
  108. files.push({
  109. path: basePath + '/modules/' + object,
  110. objectName: object,
  111. isDir: true
  112. });
  113. }
  114. })
  115. //copy them to the package path
  116. files.forEach(file => {
  117. fs.copySync(file.path, basePath + '/package/' + file.objectName);
  118. });
  119. // update package.json
  120. packageJson.version = version;
  121. console.log("generating file list");
  122. let packageFiles = ["package.json"];
  123. files.forEach(file => {
  124. if (!file.isDir) {
  125. packageFiles.push(file.objectName);
  126. } else {
  127. //todo is it better to read the content and add it? leave it like that ATM
  128. packageFiles.push(file.objectName + "/index.js", file.objectName + "/index.d.ts", file.objectName + "/es6.js")
  129. }
  130. });
  131. console.log("updating package.json");
  132. packageJson.files = packageFiles;
  133. packageJson.main = "babylon.max.js";
  134. packageJson.typings = "babylon.d.ts";
  135. fs.writeFileSync(basePath + '/package/' + 'package.json', JSON.stringify(packageJson, null, 4));
  136. console.log('Publishing ' + package.name + " from " + basePath + '/package/');
  137. //publish the respected package
  138. shelljs.exec('npm publish \"' + basePath + '/package/' + "\"");
  139. // remove package directory
  140. //fs.removeSync(basePath + '/package/');
  141. // now update the main package.json
  142. packageJson.files = packageJson.files.map(file => {
  143. if (file !== 'package.json' && file !== 'readme.md') {
  144. return 'dist/preview release/' + file;
  145. } else {
  146. return file;
  147. }
  148. });
  149. packageJson.main = "dist/preview release/babylon.max.js";
  150. packageJson.typings = "dist/preview release/babylon.d.ts";
  151. fs.writeFileSync(package.path + 'package.json', JSON.stringify(packageJson, null, 4));
  152. }