chore: TS tasks (draft). Devs now can use the build command task in VSCode.

This commit is contained in:
OctoD 2017-05-23 18:44:31 +02:00
parent 6eb7f91b09
commit d32be8bc39
10 changed files with 217 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
*.log
*.~lock
*.js
*.gulp/**.js
dist/
node_modules/

5
.gulp/consts/files.ts Normal file
View file

@ -0,0 +1,5 @@
/**
* File charset
* @type {string}
*/
export const CHARSET: string = 'utf-8';

9
.gulp/index.ts Normal file
View file

@ -0,0 +1,9 @@
// import the tasks
export * from './tasks/changelog';
export * from './tasks/bump';
export * from './tasks/icons';
export * from './tasks/themes';
export * from './tasks/watcher';
// export default script
export default ['build:themes'];

11
.gulp/paths.ts Normal file
View file

@ -0,0 +1,11 @@
// const infos = require('../package.json');
// const today = new Date();
const paths = {
dist: './dist',
icons: './icons',
src: './src',
themes: './themes',
};
export default paths;

35
.gulp/tasks/bump.ts Normal file
View file

@ -0,0 +1,35 @@
/*
* > Bump
*/
import * as Gulp from 'gulp';
import * as Gulpif from 'gulp-if';
import * as bump from 'gulp-bump';
import * as gutil from 'gulp-util';
import * as runSequence from 'run-sequence';
import * as yrgv from 'yargs';
var argv = (yrgv as any).argv;
export var taskBump = Gulp.task('bump', (cb) => {
runSequence(
'bump-pkg-version',
(error) => {
if (error) {
console.log(gutil.colors.magenta.bold('[bump]'), gutil.colors.red.bold(' There was an issue bumping version:\n'), error);
} else {
console.log(gutil.colors.magenta.bold('\n[bump]'), gutil.colors.green.bold(' Finished successfully\n'));
}
cb(error);
}
);
});
export var taskVersioning = Gulp.task('bump-pkg-version', () => {
return Gulp.src(['./package.json'])
.pipe(Gulpif((Object.keys(argv).length === 2), bump()))
.pipe(Gulpif(argv.patch, bump()))
.pipe(Gulpif(argv.minor, bump({ type: 'minor' })))
.pipe(Gulpif(argv.major, bump({ type: 'major' })))
.pipe(Gulp.dest('./'));
});

15
.gulp/tasks/changelog.ts Normal file
View file

@ -0,0 +1,15 @@
/*
* > Changelog
*/
import * as Gulp from 'gulp';
import * as conventionalChangelog from 'gulp-conventional-changelog';
export var task = Gulp.task('changelog', () => {
return Gulp.src('CHANGELOG.md')
.pipe(conventionalChangelog({
preset: 'angular',
releaseCount: 0
}))
.pipe(Gulp.dest('./'));
});

58
.gulp/tasks/icons.ts Normal file
View file

@ -0,0 +1,58 @@
/*
* > Build Icons
*/
import * as Gulp from 'gulp';
import * as Mustache from 'mustache';
import * as fs from 'fs';
import * as gutil from 'gulp-util';
import * as path from 'path';
import { CHARSET } from "../consts/files";
import Paths from '../paths';
export var taskIcons = Gulp.task('build:icons', cb => {
const partials = fs.readdirSync(path.join(Paths.src, `./icons/partials`));
const partialData: any = {};
const files = fs.readdirSync(path.join(Paths.src, `./icons/svgs`));
const icons = files.map(file => ({ name: file.split('.')[0], last: false }));
const pathTemp = './themes/.material-theme-icons.tmp';
icons[icons.length - 1].last = true;
partials.forEach(partial => {
partialData[partial.split('.')[0]] = fs.readFileSync(
path.join(Paths.src, `./icons/partials`, `./${partial}`),
'utf-8'
);
});
let contents = Mustache.render(
fs.readFileSync(path.join(Paths.src, `./icons/icons-theme.json`), CHARSET),
{ icons },
partialData
);
try {
contents = JSON.stringify(JSON.parse(contents), null, 2);
} catch (err) {
gutil.log(
gutil.colors['red']('There is an error with JSON generated for icons'),
err
);
cb(err);
return;
}
fs.writeFileSync(pathTemp, contents, CHARSET);
gutil.log(
gutil.colors['gray']('\n———————————————————————————————————————————————————————————————\n')
);
gutil.log('Generated', gutil.colors['green'](pathTemp));
gutil.log(
gutil.colors['gray']('\n———————————————————————————————————————————————————————————————\n')
);
cb();
});

63
.gulp/tasks/themes.ts Normal file
View file

@ -0,0 +1,63 @@
import * as Gulp from 'gulp';
import * as Mustache from 'mustache';
// import * as YAML from 'yamljs';
/*
* > Build Themes
*/
import * as fs from 'fs';
import * as gutil from 'gulp-util';
import { CHARSET } from "../consts/files";
import Paths from '../paths';
const themeCommons = require('../../src/themes/settings/commons.json');
const themeVariants: any[] = [];
const themeTemplateFile = fs.readFileSync(
`${Paths.src}/themes/theme-template-color-theme.json`,
CHARSET
);
const files = fs.readdirSync(`${Paths.src}/themes/settings/specific`);
// build theme variants for later use in templating
files.forEach(file => {
// const name: string = file.split('.')[0];
const filepath = `${Paths.src}/themes/settings/specific/${file}`;
const contents = fs.readFileSync(filepath, 'utf-8');
try {
themeVariants.push(JSON.parse(contents));
} catch (err) {
gutil.log('Error when parsing json for theme variants', err);
}
});
export var taskThemes = Gulp.task('build:themes', () => {
gutil.log(
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
);
themeVariants.forEach(variant => {
const templateData = {
'commons': themeCommons,
variant
};
const templateJson = JSON.parse(
Mustache.render(themeTemplateFile, templateData)
);
const path = `${Paths.themes}/${variant.name}.json`;
fs.writeFileSync(
path,
JSON.stringify(templateJson, null, 2),
CHARSET
);
gutil.log('Generate', gutil.colors['green'](path));
});
gutil.log(
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
);
});

11
.gulp/tasks/watcher.ts Normal file
View file

@ -0,0 +1,11 @@
/*
* > Watcher
*/
import * as Gulp from 'gulp';
import Paths from '../paths';
export var taskWatch = Gulp.task('watch', () => {
Gulp.watch(`${Paths.src}/themes/**/*.json`, ['build:themes']);
});

9
gulpfile.babel.ts Normal file
View file

@ -0,0 +1,9 @@
import * as Gulp from 'gulp';
import * as GulpStats from 'gulp-stats';
import * as tasks from './.gulp';
// Use gulp-stats
GulpStats(Gulp);
// set default task
Gulp.task('default', tasks.default);