Skip to content

Commit

Permalink
feat(*): add auto d.ts generation for all non-components js files
Browse files Browse the repository at this point in the history
  • Loading branch information
Heymdall committed Jun 13, 2018
1 parent a6e66f0 commit ce35eaf
Show file tree
Hide file tree
Showing 4 changed files with 1,636 additions and 668 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ createTasks('arui-feather');
* `tsComponentsGlob` - glob для файлов ts компонентов
* `jsGlob` - glob для всех публикуемых js файлов пакета
* `tsGlob` - glob для всех публикуемых ts файлов пакета
* `autoDtsGlob` - glob для js файлов, для которых будет создаваться d.ts
* `cssGlob` - glob для всех публикуемых css файлов пакета
* `cssCopyGlob` - glob для всех копируемых css фалов пакета
* `resourcesGlob` - glob для всех ресурсных файлов пакета (картинки, шрифты)
Expand All @@ -82,7 +83,7 @@ const componentPackage = require('library-utils/gulp/component-package');

gulp.src('file.js')
.pipe(componentPackage())
.pipe(gulp.dest('dist');
.pipe(gulp.dest('dist'));
```

В результате в папке `dist` будет создан файл `package.json`:
Expand All @@ -105,7 +106,7 @@ const componentTypings = require('library-utils/gulp/component-typings');

gulp.src('file.js')
.pipe(componentTypings('libraryName'))
.pipe(gulp.dest('dist');
.pipe(gulp.dest('dist'));
```

В результате в папке `dist` будет создан файл `file.d.ts`.
Expand Down Expand Up @@ -141,7 +142,7 @@ const componentDocs = require('library-utils/gulp/component-docs');

gulp.src('file.js')
.pipe(componentDocs('libraryName'))
.pipe(gulp.dest('docs');
.pipe(gulp.dest('docs'));
```

В результате в папке `docs` будет создан файл `README.md`, с описанием props и пубичных методов компонента.
Expand All @@ -158,7 +159,7 @@ const libraryDoc = require('library-utils/gulp/library-doc');

gulp.src('src/*.js')
.pipe(libraryDoc('libraryName'))
.pipe(gulp.dest('docs');
.pipe(gulp.dest('docs'));
```

Лицензия
Expand Down
26 changes: 25 additions & 1 deletion gulp-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const rename = require('gulp-rename');
const filter = require('gulp-filter');
const clone = require('gulp-clone');
const es = require('event-stream');
const ts = require('gulp-typescript');
Expand All @@ -22,6 +23,9 @@ const defaultOptions = {
componentsGlob: ['src/*/*.jsx', '!src/*/*-test.jsx', '!src/*/*-benchmark.jsx'],
tsComponentsGlob: ['src/*/*.tsx'],
jsGlob: ['src/**/*.{js,jsx}', '!src/**/*-test.{js,jsx}', '!src/**/*-benchmark.{js,jsx}'],
autoDtsGlob: [
'src/**/*.{js,jsx}', '!src/**/index.{js,jsx}', '!src/**/*-test.{js,jsx}', '!src/**/*-benchmark.{js,jsx}'
],
tsGlob: ['src/**/*.{ts,tsx}', '!src/**/*-test.{ts,tsx}', '!src/**/*-benchmark.{ts,tsx}'],
cssGlob: ['src/**/*.css', '!src/vars/**/*.css', '!src/vars*.css'],
cssCopyGlob: ['src/**/vars/**/*.css', 'src/vars*.css'],
Expand Down Expand Up @@ -161,9 +165,29 @@ function createTasks(packageName, options = {}) {
.pipe(gulp.dest(options.docsDir));
});

gulp.task('dts', ['js', 'publish-files', 'typings'], () => {
const tsOptions = {
declaration: true,
allowSyntheticDefaultImports: true,
lib: ['dom', 'es2015', 'es2016']
};

return gulp.src(options.autoDtsGlob)
.pipe(rename((path) => {
// typescript compiler won't compile files with non-ts extensions
path.extname = path.extname === '.jsx' ? '.tsx' : '.ts';
}))
.pipe(filter(file => !fs.existsSync(
// ignore all files, that already emit d.ts file
path.join(options.publishDir, file.relative).replace(/\.ts$/, '.d.ts')
)))
.pipe(ts(tsOptions, ts.reporter.nullReporter())) // ignore all errors at compile time
.dts.pipe(gulp.dest(options.publishDir));
});

gulp.task(
'compile',
['js', 'css', 'resources', 'typings', 'publish-files'].concat(isTsEnabled ? ['ts'] : []),
['js', 'css', 'resources', 'typings', 'publish-files', 'dts'].concat(isTsEnabled ? ['ts'] : []),
checkErrors
);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"gulp": "3.9.1",
"gulp-babel": "7.0.1",
"gulp-clone": "2.0.1",
"gulp-filter": "^5.1.0",
"gulp-postcss": "7.0.1",
"gulp-rename": "1.2.2",
"gulp-sourcemaps": "2.6.4",
Expand All @@ -25,7 +26,7 @@
"recast": "0.14.0",
"resolve": "1.5.0",
"through2": "2.0.3",
"typescript": "2.6.2",
"typescript": "2.9.1",
"typescript-formatter": "7.1.0",
"uppercamelcase": "3.0.0",
"vinyl": "2.1.0"
Expand Down
Loading

0 comments on commit ce35eaf

Please sign in to comment.