框架源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.5 KiB

4 years ago
  1. const path = require('path');
  2. const fs = require('fs')
  3. const fileName = 'tisplatform.json';
  4. const production = process.env.NODE_ENV === 'production' || process.env.VUE_APP_SDK === 'sdk';
  5. const uc = require("upper-case");
  6. function resolve(dir) {
  7. return path.join(__dirname,dir);
  8. }
  9. function parent_path_count(path_str,count) {
  10. let path_temp = path_str;
  11. for (let i = 0; i < count; i++) {
  12. path_temp = path.resolve(path_temp,'..')
  13. }
  14. }
  15. function createTisplatformPlugin(options){
  16. this.options = options;
  17. }
  18. createTisplatformPlugin.prototype.apply = function (compiler) {
  19. let _path = this.options.path;
  20. let sdkName = this.options.sdkName;
  21. let json = {};
  22. if(!production) return;
  23. compiler.plugin('compilation',function (compilation,options) {
  24. compilation.plugin('html-webpack-plugin-before-html-processing',function (htmlPluginData,callback) {
  25. // const title = htmlPluginData.plugin.options.title;
  26. // const ROOT_DIR_NAME = path.resolve(__dirname,'../../').split(path.sep).pop()
  27. // const title = uc(ROOT_DIR_NAME);
  28. json[sdkName] = {
  29. cssFiles : htmlPluginData.assets.css/*.map(css=>"/"+title+css)*/,
  30. jsFiles : htmlPluginData.assets.js/*.map(js=>"/"+title+js)*/,
  31. preload : true,
  32. };
  33. // console.log('资源',title,htmlPluginData)
  34. console.log(htmlPluginData.assets.js);
  35. // console.log('------------',_path);
  36. console.log(htmlPluginData.assets.css);
  37. })
  38. })
  39. compiler.plugin('done',function (compilation,options) {
  40. console.log('compiler done')
  41. fs.writeFileSync(path.join(_path,fileName),JSON.stringify(json,null,"\t"))
  42. let config = JSON.parse(fs.readFileSync(path.join(_path,"esplug.json")));
  43. config.id = sdkName;
  44. config.icon = `/${sdkName}/icon.png`
  45. config.entry = `/${sdkName}/`;
  46. config.type = "app";
  47. config.version = "2";
  48. // console.log('config file:',config);
  49. fs.writeFileSync(path.join(_path,"esplug.json"),JSON.stringify(config,null,"\t"));
  50. //兼容kt,把描述文件统一放到manifest文件夹下
  51. fs.mkdirSync(path.join(_path)+"/manifest");
  52. fs.writeFileSync(path.join(_path,"manifest/esplug.json"),fs.readFileSync(path.join(_path,"esplug.json")));
  53. //添加路径
  54. // let css = fs.readFileSync(path.join(_path,"css/app.css"))
  55. // console.log(css)
  56. // .replace(/url\(/g,`url(${sdkName}/`)
  57. })
  58. }
  59. module.exports = createTisplatformPlugin;