download-cdn-resources.js 935 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * the tool for download CDN resources and save as file
  3. *
  4. * @author Yuki Takei <yuki@weseek.co.jp>
  5. */
  6. require('module-alias/register');
  7. const logger = require('@alias/logger')('growi:bin:download-cdn-resources');
  8. const { envUtils } = require('growi-commons');
  9. // check env var
  10. const noCdn = envUtils.toBoolean(process.env.NO_CDN);
  11. if (!noCdn) {
  12. logger.info('Using CDN. No resources are downloaded.');
  13. // exit
  14. process.exit(0);
  15. }
  16. logger.info('This is NO_CDN mode. Start to download resources.');
  17. const CdnResourcesDownloader = require('@commons/service/cdn-resources-downloader');
  18. const CdnResourcesService = require('@commons/service/cdn-resources-service');
  19. const downloader = new CdnResourcesDownloader();
  20. const service = new CdnResourcesService();
  21. service.downloadAndWriteAll(downloader)
  22. .then(() => {
  23. logger.info('Download is completed successfully');
  24. })
  25. .catch((err) => {
  26. logger.error(err);
  27. });