框架源码
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.

56 lines
2.0 KiB

4 years ago
  1. const path = require('path');
  2. const fs = require('fs')
  3. const fileName = 'tisplatform.json';
  4. function loadSdkPlugin(options) {
  5. this.options = options;
  6. }
  7. loadSdkPlugin.prototype.apply = function (comppiler) {
  8. let sdkPath = this.options.sdkPath;
  9. let jsonPath = this.options.jsonPath;
  10. let sdks = {};
  11. let json = {};
  12. comppiler.plugin('done',function (compilation,callback) {
  13. //写入sdk配置
  14. try {
  15. const files = fs.readdirSync(path.resolve(sdkPath))
  16. files.forEach(function (item,index) {
  17. let stat = fs.lstatSync(path.join(sdkPath,item))
  18. if(stat.isDirectory()){
  19. // console.log('aaaaa',path.join(jsonPath,fileName),fs.existsSync(path.join(jsonPath,fileName)))
  20. if(!fs.existsSync(path.join(jsonPath,fileName))){
  21. fs.writeFileSync(path.join(jsonPath,fileName),"{}","utf-8");
  22. }
  23. //抽取preload为true的sdk
  24. let target = JSON.parse(fs.readFileSync(path.join(jsonPath,fileName),"utf-8"))
  25. let sdkJson = JSON.parse(fs.readFileSync(path.join(sdkPath,item,fileName),"utf-8"));
  26. //TODO 已有属性就不再写入
  27. // console.log(target.hasOwnProperty(item));
  28. // if(!target.hasOwnProperty(item)){
  29. sdks[item] = sdkJson[item];
  30. console.log(path.join(jsonPath,fileName));
  31. fs.writeFileSync(path.join(jsonPath,fileName),JSON.stringify(sdks,null,"\t"))
  32. // };
  33. }
  34. })
  35. console.log(sdks);
  36. //自身platform
  37. // json = JSON.parse(fs.readFileSync(path.join(jsonPath,fileName),'utf-8'));
  38. // json['dependent'] = sdks;
  39. //
  40. // console.log(path.join(jsonPath,fileName))
  41. // callback();
  42. }catch (e) {
  43. console.log(e)
  44. }
  45. // console.log(sdks);
  46. })
  47. }
  48. module.exports = loadSdkPlugin