prepkg.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const fs = require('fs-extra');
  2. const path = require('path');
  3. const { execSync } = require('child_process');
  4. const showdown = require('showdown');
  5. const platform = process.argv[2];
  6. const distDir = path.resolve(__dirname, '../dist');
  7. const tmpDir = `${distDir}/tmp`;
  8. const publicDir = `${tmpDir}/public`;
  9. const outDir = `${distDir}/${platform}`;
  10. async function build() {
  11. if (!platform)
  12. throw new Error(`Please set platform`);
  13. await fs.emptyDir(outDir);
  14. //добавляем readme в релиз
  15. let readme = await fs.readFile(path.resolve(__dirname, '../README.md'), 'utf-8');
  16. const converter = new showdown.Converter();
  17. readme = converter.makeHtml(readme);
  18. await fs.writeFile(`${outDir}/readme.html`, readme);
  19. // перемещаем public на место
  20. if (await fs.pathExists(publicDir)) {
  21. const zipFile = `${tmpDir}/public.zip`;
  22. const jsonFile = `${distDir}/public.json`;//distDir !!!
  23. await fs.remove(zipFile);
  24. execSync(`zip -r ${zipFile} .`, {cwd: publicDir, stdio: 'inherit'});
  25. const data = (await fs.readFile(zipFile)).toString('base64');
  26. await fs.writeFile(jsonFile, JSON.stringify({data}));
  27. } else {
  28. throw new Error(`publicDir: ${publicDir} does not exist`);
  29. }
  30. }
  31. async function main() {
  32. try {
  33. await build();
  34. } catch(e) {
  35. console.error(e);
  36. process.exit(1);
  37. }
  38. }
  39. main();