2

我有一个节点脚本,它调用许多进程来打包文件。大多数时候,这很有效,但是偶尔(可能平均每 5 次调用中有 1 次?)它只是停在中间,总是在同一个位置。具体来说,失败时日志的结尾如下所示:

Finished task 1!
Compiling jsajax.js...
Compiling apps.js...

我没有收到任何错误或任何东西,所以我不知道该看什么。这里的设置是我的主文件 (index.js) 使用 co 和生成器来调用所需的异步进程,并产生它们的结果。其中一些是与 gulp 相关的,这就是发生此问题的地方。我在这里包括调用代码和 gulp 任务,因为其余代码太长而无法显示所有内容。如果您认为需要,我很乐意提供更多内容。谢谢!

调用函数:

const createJS = function* createJS () {
  try {
    yield gulpFile.createJS();
    return 0;
  } catch(err) {
    console.error(err);
    return CONSTANTS.ERROR;
  }
};

吞咽任务:

const createJS = function () {
  const buildProps = PropertiesReader('build.properties'),
      distLoc = buildProps.get('distLoc'),
      installLoc = buildProps.get('installLoc'),
      updateLoc = buildProps.get('updateLoc'),
      installJSLoc = `${installLoc}/js`,
      updateJSLoc = `${updateLoc}/js`,
      jsajax = CONSTANTS.JSAJAX_FILES.map(file => distLoc + file),
      appsOnly = CONSTANTS.APPS_FILES.map(file => distLoc + file),
      apps = [...jsajax, ...appsOnly];
  let compile1, compile2;
  compile1 = new Promise((resolve, reject) => {
    console.log('Compiling jsajax.js...');
    gulp.src(jsajax)
      .pipe(sourcemaps.init())
      .pipe(concat('jsajax.js'))
      .pipe(uglify())
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest(installJSLoc))
      .pipe(gulp.dest(updateJSLoc))
      .on('error', err => reject(err))
      .on('end', () => {
        console.log('jsajax.js compiled successfully!');
        resolve();
      });
  });
  compile2 = new Promise((resolve, reject) => {
    console.log('Compiling apps.js...');
    gulp.src(apps)
      .pipe(sourcemaps.init())
      .pipe(concat('apps.js'))
      .pipe(uglify())
      .pipe(sourcemaps.write('./'))
      .pipe(gulp.dest(installJSLoc))
      .pipe(gulp.dest(updateJSLoc))
      .on('error', err => reject(err))
      .on('end', () => {
        console.log('apps.js compiled successfully!');
        resolve();
      });
  });
  return Promise.all([compile1, compile2]);
};
4

0 回答 0