Skip to content

Commit

Permalink
chore: add build by gulp (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Chernitsyn authored Mar 15, 2023
1 parent 4bd625f commit c49a36e
Show file tree
Hide file tree
Showing 4 changed files with 2,996 additions and 102 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ node_modules

# Artifacts
dist
build
75 changes: 75 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-env node */
const path = require('path');
const {task, src, dest, series, parallel} = require('gulp');
const rimraf = require('rimraf');
const ts = require('gulp-typescript');
const replace = require('gulp-replace');
const sass = require('gulp-dart-sass');

const BUILD_DIR = path.resolve('build');

task('clean', (done) => {
rimraf.sync(BUILD_DIR);
rimraf.sync('styles/**/*.css');
done();
});

function compileTs(modules = false) {
const tsProject = ts.createProject('tsconfig.json', {
declaration: true,
module: modules ? 'esnext' : 'commonjs',
});

return src([
'src/**/*.{ts,tsx}',
'!src/demo/**/*',
'!src/stories/**/*',
'!src/**/__stories__/**/*',
'!src/**/__tests__/**/*',
])
.pipe(
replace(/import '.+\.scss';/g, (match) =>
modules ? match.replace('.scss', '.css') : '',
),
)
.pipe(tsProject())
.pipe(dest(path.resolve(BUILD_DIR, modules ? 'esm' : 'cjs')));
}

task('compile-to-esm', () => {
return compileTs(true);
});

task('compile-to-cjs', () => {
return compileTs();
});

task('copy-i18n', () => {
return src(['src/**/i18n/*.json'])
.pipe(dest(path.resolve(BUILD_DIR, 'esm')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs')));
});

task('styles-components', () => {
return src(['src/components/**/*.scss', '!src/components/**/__stories__/**/*'])
.pipe(
sass({
includePaths: ['node_modules'],
}),
)
.pipe(sass().on('error', sass.logError))
.pipe(dest(path.resolve(BUILD_DIR, 'esm', 'components')))
.pipe(dest(path.resolve(BUILD_DIR, 'cjs', 'components')));
});

task(
'build',
series([
'clean',
parallel(['compile-to-esm', 'compile-to-cjs']),
'copy-i18n',
parallel(['styles-components']),
]),
);

task('default', series(['build']));
Loading

0 comments on commit c49a36e

Please sign in to comment.