Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. const chalk = require('chalk');
  9. const url = require('url');
  10. const globalModules = require('global-modules');
  11. const fs = require('fs');
  12. function printHostingInstructions(
  13. appPackage,
  14. publicUrl,
  15. publicPath,
  16. buildFolder,
  17. useYarn
  18. ) {
  19. if (publicUrl && publicUrl.includes('.github.io/')) {
  20. // "homepage": "http://user.github.io/project"
  21. const publicPathname = url.parse(publicPath).pathname;
  22. const hasDeployScript = typeof appPackage.scripts.deploy !== 'undefined';
  23. printBaseMessage(buildFolder, publicPathname);
  24. printDeployInstructions(publicUrl, hasDeployScript, useYarn);
  25. } else if (publicPath !== '/') {
  26. // "homepage": "http://mywebsite.com/project"
  27. printBaseMessage(buildFolder, publicPath);
  28. } else {
  29. // "homepage": "http://mywebsite.com"
  30. // or no homepage
  31. printBaseMessage(buildFolder, publicUrl);
  32. printStaticServerInstructions(buildFolder, useYarn);
  33. }
  34. console.log();
  35. console.log('Find out more about deployment here:');
  36. console.log();
  37. console.log(` ${chalk.yellow('http://bit.ly/CRA-deploy')}`);
  38. console.log();
  39. }
  40. function printBaseMessage(buildFolder, hostingLocation) {
  41. console.log(
  42. `The project was built assuming it is hosted at ${chalk.green(
  43. hostingLocation || 'the server root'
  44. )}.`
  45. );
  46. console.log(
  47. `You can control this with the ${chalk.green(
  48. 'homepage'
  49. )} field in your ${chalk.cyan('package.json')}.`
  50. );
  51. if (!hostingLocation) {
  52. console.log('For example, add this to build it for GitHub Pages:');
  53. console.log();
  54. console.log(
  55. ` ${chalk.green('"homepage"')} ${chalk.cyan(':')} ${chalk.green(
  56. '"http://myname.github.io/myapp"'
  57. )}${chalk.cyan(',')}`
  58. );
  59. }
  60. console.log();
  61. console.log(`The ${chalk.cyan(buildFolder)} folder is ready to be deployed.`);
  62. }
  63. function printDeployInstructions(publicUrl, hasDeployScript, useYarn) {
  64. console.log(`To publish it at ${chalk.green(publicUrl)}, run:`);
  65. console.log();
  66. // If script deploy has been added to package.json, skip the instructions
  67. if (!hasDeployScript) {
  68. if (useYarn) {
  69. console.log(` ${chalk.cyan('yarn')} add --dev gh-pages`);
  70. } else {
  71. console.log(` ${chalk.cyan('npm')} install --save-dev gh-pages`);
  72. }
  73. console.log();
  74. console.log(
  75. `Add the following script in your ${chalk.cyan('package.json')}.`
  76. );
  77. console.log();
  78. console.log(` ${chalk.dim('// ...')}`);
  79. console.log(` ${chalk.yellow('"scripts"')}: {`);
  80. console.log(` ${chalk.dim('// ...')}`);
  81. console.log(
  82. ` ${chalk.yellow('"predeploy"')}: ${chalk.yellow(
  83. `"${useYarn ? 'yarn' : 'npm run'} build",`
  84. )}`
  85. );
  86. console.log(
  87. ` ${chalk.yellow('"deploy"')}: ${chalk.yellow(
  88. '"gh-pages -d build"'
  89. )}`
  90. );
  91. console.log(' }');
  92. console.log();
  93. console.log('Then run:');
  94. console.log();
  95. }
  96. console.log(` ${chalk.cyan(useYarn ? 'yarn' : 'npm')} run deploy`);
  97. }
  98. function printStaticServerInstructions(buildFolder, useYarn) {
  99. console.log('You may serve it with a static server:');
  100. console.log();
  101. if (!fs.existsSync(`${globalModules}/serve`)) {
  102. if (useYarn) {
  103. console.log(` ${chalk.cyan('yarn')} global add serve`);
  104. } else {
  105. console.log(` ${chalk.cyan('npm')} install -g serve`);
  106. }
  107. }
  108. console.log(` ${chalk.cyan('serve')} -s ${buildFolder}`);
  109. }
  110. module.exports = printHostingInstructions;