/*
*
*
*
* */
var fs = require("fs");
var path = require("path");
fs.readFile(__dirname + '/test2.js', {flag: 'r+', encoding: 'utf8'}, function callback(err, data) {
  var dataReg = data.split('/*\n' +
    '*\n' +
    '*\n' +
    '*\n' +
    '* */')[1].split('\n'), dataFinall = [],datatest=[];
  dataReg.map((item, index) => {
    if (item.indexOf('import') == 0) {
      datatest.push(item)
      dataFinall.push({name: item.split('import')[1].split('from')[0], url: item.split('import')[1].split('from')[1]})
    }
  });
  console.log(dataReg)
  console.log(datatest)
  var dataInsert = '';
  dataFinall.map(item => {
    dataInsert += `const${item.name}= (resolve) => {
  import(${item.url}).then((module) => {
    resolve(module)
  })
}\n`
  });
  fs.writeFile(__dirname + '/success.js', dataInsert, {flag: 'a'}, function (err) {
    if (err) {
      console.error(err);
    } else {
      console.log('写入成功');
    }
  });
});


Logo

前往低代码交流专区

更多推荐