Команда компиляции Gulp не компилирует папку SR C из TS в JS в папке DIst - PullRequest
0 голосов
/ 16 апреля 2020

Я использую Gulp для компиляции моего скрипта типа в java скрипт. Когда я запускаю команду Gulp, она компилирует все в моей папке sr c и помещает файлы компиляции в папку dist, которая сейчас является сценарием Java, но я вижу только один файл, присутствующий в папке dist после компиляции, т.е. config. json где я ожидаю, что все файлы в sr c будут присутствовать в dist после компиляции. Я использую команду gulp compile для компиляции моих файлов в SR C.

Пожалуйста, прокрутите код ниже, чтобы увидеть структуру папок. Спасибо.

Вот мой gulpfile. js

var gulp = require('gulp');
var ts = require('gulp-typescript');
var zip = require('gulp-zip');
var del = require('del');
var install = require('gulp-install');
var runSequence = require('run-sequence');
var awsLambda = require("node-aws-lambda");
var sourcemaps = require('gulp-sourcemaps');
var gulpMocha = require('gulp-mocha');
var gutil = require('gulp-util');

const babel = require('gulp-babel');
gulp.task('clean', function () {
    return del(['./dist','./testJs', './dist.zip']);
});


gulp.task('compile', function () {
  return gulp.src(['src/**/*.ts' ]) //'typings/**/*.d.ts'])
    .pipe(sourcemaps.init())
    .pipe(ts({
      noImplicitAny: false,
      removeComments: true,
      preserveConstEnums: true,
      target: 'es2015',
      module: 'commonjs',
      noExternalResolve: true,
      exclude: ["node_modules", "dist"]
    }))
    .pipe(babel({
      presets: [ 'es2015' ],
      plugins: ['transform-runtime']      
    }))
    // sourceRoot must be relative to the running directory
    // It appears VSCode does resolve the path relative to the cwd
    // so using something like /src doesn't work, it has to be relative
    // to the /dist folder where we will run the app from
    // Need to test if maps help when errors are thrown in aws and if we should upload them
    .pipe(sourcemaps.write('.', { sourceRoot: '../src' }))
    .pipe(gulp.dest('./dist'))
    ,
    gulp.src(['src/**/*.json'])
    .pipe(gulp.dest('./dist'));
});


gulp.task('deploy', function (callback) {
    return runSequence(
        'clean',
        'compile',
        'compiletest',
        'test',
        'node-mods',
    callback
    );
});```

**Folder structure before running gulp compile**

  |
    |_ [src folder]
        |_CC_ToMRDR
        |_Central Repository
        app.ts
        config.json
        test.ts        

    |_ [other folder's and files like node modules,package.json,tsconfig.json etc]




**Folder structure after running gulp compile**

  |
    |_ [src folder]
        |_CC_ToMRDR
        |_Central Repository
        app.ts
        config.json
        test.ts        

    |
    |_ [dist folder]
          config.json

    |_ [other folder's and files like node modules,package.json,tsconfig.json etc]


1 Ответ

0 голосов
/ 16 апреля 2020

Попробуйте изменить первое gulp.src следующим образом:

return gulp.src('src/**/*.ts')

, а второе

.pipe(gulp.src('src/**/*.json'))

Запятая прервет компиляцию. Второй gulp.src должен быть добавлен как pipe, или он перезаписывает первый (ср. https://gulpjs.com/docs/en/getting-started/working-with-files/).

Более подробно:

gulp.task('compile', function() {
  return gulp.src('src/**/*.ts')
    // some coding here
    .pipe(gulp.dest('./dist'))
    .pipe(gulp.src('src/**/*.json'))
    .pipe(gulp.dest('./dist'));
});

Извините за правки, но вы используете более старый синтаксис Gulp. js, и я немного растерялся.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...