视频播放器仓库

deploy:demo.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* eslint-disable no-console */
  2. const ghpages = require('gh-pages');
  3. const pkg = require('./../package.json');
  4. const path = require('path');
  5. const chalk = require('chalk');
  6. const fs = require('fs');
  7. const distPath = path.join(__dirname, '../demo/dist');
  8. const deploy = (options = {}) => {
  9. ghpages.publish(distPath, Object.assign({
  10. message: pkg.version
  11. }, options), (err) => {
  12. if (err) {
  13. error([err]);
  14. return;
  15. }
  16. console.log(chalk.green('Demo has succesfully deployed.'));
  17. });
  18. };
  19. const error = (errs = []) => {
  20. errs.forEach((err) => {
  21. console.log(chalk.red(err));
  22. });
  23. process.exit(1);
  24. };
  25. try {
  26. fs.accessSync(distPath, fs.F_OK);
  27. if (process.env.TRAVIS) {
  28. if (process.env.GITHUB_TOKEN) {
  29. deploy({
  30. repo: `https://${process.env.GITHUB_TOKEN}@github.com/${process.env.TRAVIS_REPO_SLUG}.git`,
  31. user: {
  32. name: 'Travis CI'
  33. }
  34. });
  35. } else {
  36. error(['process.env.GITHUB_TOKEN with "repo" access is required to deploy gh-pages.']);
  37. }
  38. } else {
  39. // Deploys using git origin, username and email.
  40. deploy();
  41. }
  42. } catch (e) {
  43. error([
  44. `${distPath} does not exist.`,
  45. 'Please run "npm i && npm run i:demo && npm run build:demo" and try again.'
  46. ]);
  47. }