No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

90 líneas
2.2 KiB

  1. const fs = require('fs');
  2. const path = require('path');
  3. const chalk = require('chalk');
  4. const rollup = require('rollup');
  5. const log = console.log; // eslint-disable-line
  6. const {
  7. get_build_json,
  8. get_app_path,
  9. apps_list,
  10. run_serially,
  11. assets_path,
  12. sites_path
  13. } = require('./rollup.utils');
  14. const {
  15. get_options_for
  16. } = require('./config');
  17. show_production_message();
  18. ensure_js_css_dirs();
  19. build_libs();
  20. build_assets_for_all_apps();
  21. function build_assets_for_all_apps() {
  22. run_serially(
  23. apps_list.map(app => () => build_assets(app))
  24. );
  25. }
  26. function build_assets(app) {
  27. const options = get_options_for(app);
  28. if (!options.length) return Promise.resolve();
  29. log(chalk.yellow(`\nBuilding ${app} assets...\n`));
  30. const promises = options.map(({ inputOptions, outputOptions, output_file}) => {
  31. return build(inputOptions, outputOptions)
  32. .then(() => {
  33. log(`${chalk.green('✔')} Built ${output_file}`);
  34. });
  35. });
  36. const start = Date.now();
  37. return Promise.all(promises)
  38. .then(() => {
  39. const time = Date.now() - start;
  40. log(chalk.green(`✨ Done in ${time / 1000}s`));
  41. });
  42. }
  43. function build(inputOptions, outputOptions) {
  44. return rollup.rollup(inputOptions)
  45. .then(bundle => bundle.write(outputOptions));
  46. }
  47. function build_libs() {
  48. // only concatenates lib files, not processed through rollup
  49. const touch = require('touch');
  50. const libs_path = 'js/libs.min.js';
  51. const input_files = get_build_json('frappe')[libs_path];
  52. const libs_content = input_files.map(file_name => {
  53. const full_path = path.resolve(get_app_path('frappe'), file_name);
  54. return `/* ${file_name} */\n` + fs.readFileSync(full_path);
  55. }).join('\n\n');
  56. const target_path = path.resolve(assets_path, libs_path);
  57. fs.writeFileSync(target_path, libs_content);
  58. log(`${chalk.green('✔')} Built ${libs_path}`);
  59. touch(path.join(sites_path, '.build'), { force: true });
  60. }
  61. function ensure_js_css_dirs() {
  62. const paths = [
  63. path.resolve(assets_path, 'js'),
  64. path.resolve(assets_path, 'css')
  65. ];
  66. paths.forEach(path => {
  67. if (!fs.existsSync(path)) {
  68. fs.mkdirSync(path);
  69. }
  70. });
  71. }
  72. function show_production_message() {
  73. const production = process.env.FRAPPE_ENV === 'production';
  74. log(chalk.yellow(`${production ? 'Production' : 'Development'} mode`));
  75. }