简体   繁体   English

Gulp:建筑打字稿项目正在创建权限问题

[英]Gulp: Building typescript project is creating permission issues

I have a typescript project, and when I run my gulp build I remove a folder in a directory and typescript remakes the directory for me (Which is the desired result). 我有一个打字稿项目,运行gulp构建时,我在目录中删除了一个文件夹,打字稿为我重新创建了该目录(这是理想的结果)。

However, It seems to create it with strange permissions. 但是,似乎用奇怪的权限创建了它。 When I do an ls -l , I get the following permissions on the directory that was deleted with rimraf , and then created with typescript. 当我执行ls -l ,我获得了使用rimraf删除,然后使用rimraf创建的目录的以下权限。

$ ls -l
drwxrwxrwx 1 rnaddy rnaddy  512 Apr  1 10:48 src
d????????? ? ?      ?         ?            ? types

Why is it showing the question marks? 为什么显示问号? I feel that this is breaking my build, because when I build I get errors, and I think this might be the issue. 我认为这正在破坏我的构建,因为在构建时会出错,我认为这可能是问题所在。

$ gulp build:watch
[11:07:18] Using gulpfile ~\Documents\vscode\projects\red5\framework\gulpfile.js
[11:07:18] Starting 'build:watch'...
[11:07:18] Starting 'router'...
rimraf: EPERM: operation not permitted, unlink 'C:\Users\rnaddy\Documents\vscode\projects\red5\framework\router\types'
[11:07:20] 'router' errored after 1.99 s
[11:07:20] Error: EPERM: operation not permitted, mkdir 'C:\Users\rnaddy\Documents\vscode\projects\red5\framework\router\types'
[11:07:20] 'build:watch' errored after 2 s

The function that gets executed in my gulp file looks like this: 在我的gulp文件中执行的函数如下所示:

const path = require('path')
const gulp = require('gulp')
const ts = require('gulp-typescript')
const sourcemaps = require('gulp-sourcemaps')
const rimraf = require('rimraf')

const projects = {
  router: './router',
  server: './server',
  storage: './storage',
  session: './session',
  template: './template',
  middleware: './middleware',
  // Optional dependencies
  mysql: './mysql'
}

const tasks = [
  'router', 'middleware', 'template', 'storage', 'session', 'server',
  // Optional dependencies
  'mysql'
]

/**
 * Builds the project
 * @param {string} projectRoot
 * @returns {Promise<void>}
 */
async function makeProject(projectRoot) {
  let err = await new Promise(resolve => rimraf(path.join(projectRoot, 'types'), (err) => resolve(err)))
  if (err) {
    console.error('rimraf:', err.message)
    // return resolve(false)
  }

  let tsResult = await new Promise(async resolve => {
    let tsProject = ts.createProject(path.join(projectRoot, 'tsconfig.json'))
    let tsResult = tsProject.src()
      .pipe(sourcemaps.init())
      .pipe(tsProject())
      .on('finish', () => resolve(tsResult))
  })

  return await new Promise(resolve => {
    tsResult.js
      .pipe(sourcemaps.write())
      .pipe(gulp.dest(path.join(projectRoot, 'lib')).on('end', () => {
        tsResult.dts.pipe(gulp.dest(path.join(projectRoot, 'types'))).on('finish', () => resolve())
        // gulp.src(path.join(projectRoot,'src/**/*.ts')).pipe(sourcemaps.init())
      }))
  })
}

gulp.task('router', () => makeProject(path.join(__dirname, projects.router)))
gulp.task('server', () => makeProject(path.join(__dirname, projects.server)))
gulp.task('storage', () => makeProject(path.join(__dirname, projects.storage)))
gulp.task('session', () => makeProject(path.join(__dirname, projects.session)))
gulp.task('template', () => makeProject(path.join(__dirname, projects.template)))
gulp.task('middleware', () => makeProject(path.join(__dirname, projects.middleware)))
// Optional dependencies
gulp.task('mysql', () => makeProject(path.join(__dirname, projects.mysql)))

gulp.task('build:watch', gulp.series([...tasks, () => {
  gulp.watch('./router/src/**/*.ts', gulp.series('router'))
  gulp.watch('./server/src/**/*.ts', gulp.series('server'))
  gulp.watch('./storage/src/**/*.ts', gulp.series('storage'))
  gulp.watch('./session/src/**/*.ts', gulp.series('session'))
  gulp.watch('./template/src/**/*.ts', gulp.series('template'))
  gulp.watch('./middleware/src/**/*.ts', gulp.series('middleware'))
  // Optional dependencies
  gulp.watch('./mysql/src/**', gulp.series('mysql'))
}]))

gulp.task('build', gulp.series(...tasks))

It looks like the issue was because of rimraf . 看来问题出在rimraf Instead of deleting the directory types , I just needed to delete the contents of the directory. 除了删除目录types ,我只需要删除目录的内容。

So I just needed to change types to types/* so it looks like this: 所以,我只是需要改变typestypes/* ,所以它看起来是这样的:

rimraf(path.join(projectRoot, 'types/*'), (err) => /* do stuff*/)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM