chore: add a clean project task (removes js files) and improve ts tasks

This commit is contained in:
OctoD roth 2017-05-24 00:46:34 +02:00
parent 5087a0880d
commit bb7e3db86f
14 changed files with 260 additions and 126 deletions

6
.gulp/consts/log.ts Normal file
View file

@ -0,0 +1,6 @@
export const HR: string = '\n———————————————————————————————————————————————————————————————\n';
export const MESSAGE_BUMP_ERROR: string = ' There was an issue bumping version:\n';
export const MESSAGE_BUMP_SUCCESS: string = ' Finished successfully\n';
export const MESSAGE_ICON_ERROR: string = 'There is an error with JSON generated for icons';
export const MESSAGE_GENERATED: string = 'Generated';
export const MESSAGE_THEME_VARIANT_PARSE_ERROR: string = 'Error when parsing json for theme variants';

10
.gulp/consts/paths.ts Normal file
View file

@ -0,0 +1,10 @@
import { IPaths } from '../interfaces/ipaths';
const PATHS: IPaths = {
DIST: './dist',
ICONS: './icons',
SRC: './src',
THEMES: './themes',
};
export default PATHS;

View file

@ -1,4 +1,4 @@
// import the tasks
// export the tasks
export * from './tasks/changelog';
export * from './tasks/bump';
export * from './tasks/icons';

14
.gulp/interfaces/iicon.ts Normal file
View file

@ -0,0 +1,14 @@
export interface IIcon {
/**
* If set to true, the icon is marked as last
* @type {boolean}
* @memberof IIcon
*/
last: boolean;
/**
* Icon's name
* @type {string}
* @memberof IIcon
*/
name: string;
}

View file

@ -0,0 +1,26 @@
export interface IPaths {
/**
* Dist dir
* @type {string}
* @memberof IPaths
*/
DIST: string;
/**
* Icons dir
* @type {string}
* @memberof IPaths
*/
ICONS: string;
/**
* Src dir
* @type {string}
* @memberof IPaths
*/
SRC: string;
/**
* Themes dir
* @type {string}
* @memberof IPaths
*/
THEMES: string;
}

View file

@ -0,0 +1,3 @@
export interface IPlainObject {
[index: string]: string;
}

View file

@ -0,0 +1,42 @@
export interface IThemeVariant {
id: string;
name: string;
scheme: {
background: string;
base: {
black: string;
blue: string;
brown: string;
cyan: string;
green: string;
orange: string;
paleblue: string;
pink: string;
purple: string;
red: string;
violet: string;
white: string;
yellow: string;
}
caret: string;
comments: string;
findHighlight: string;
focusBorder: string;
foreground: string;
guides: string;
inputBackground: string;
inputBorder: string;
inputForeground: string;
invisibles: string;
lineHighlight: string;
lineNumbers: string;
listHoverForeground: string;
scrollbars: string;
scrollbarsHover: string;
selection: string;
shadow: string;
sidebarForeground: string;
statusbarForeground: string;
}
type: string;
}

View file

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

View file

@ -1,35 +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 gulp from 'gulp';
import * as gulpIf from 'gulp-if';
import * as gulpUtil from 'gulp-util';
import * as runSequence from 'run-sequence';
import * as yrgv from 'yargs';
import * as yargs from 'yargs';
var argv = (yrgv as any).argv;
import { MESSAGE_BUMP_ERROR, MESSAGE_BUMP_SUCCESS } from "../consts/log";
export var taskBump = Gulp.task('bump', (cb) => {
var argv = yargs.argv;
export var taskBump = gulp.task('bump', (cb) => {
runSequence(
'bump-pkg-version',
(error) => {
error => {
if (error) {
console.log(gutil.colors.magenta.bold('[bump]'), gutil.colors.red.bold(' There was an issue bumping version:\n'), error);
console.log(gulpUtil.colors.magenta.bold('[bump]'), gulpUtil.colors.red.bold(MESSAGE_BUMP_ERROR), error);
} else {
console.log(gutil.colors.magenta.bold('\n[bump]'), gutil.colors.green.bold(' Finished successfully\n'));
console.log(gulpUtil.colors.magenta.bold('\n[bump]'), gulpUtil.colors.green.bold(MESSAGE_BUMP_SUCCESS));
}
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('./'));
});
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('./'));
});
export default { taskBump, taskVersioning };

View file

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

View file

@ -1,58 +1,65 @@
/*
* > Build Icons
*/
import * as Gulp from 'gulp';
import * as Mustache from 'mustache';
import * as fs from 'fs';
import * as gulp from 'gulp';
import * as gutil from 'gulp-util';
import * as mustache from 'mustache';
import * as path from 'path';
import { CHARSET } from "../consts/files";
import Paths from '../paths';
import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log';
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';
import { CHARSET } from '../consts/files';
import { IIcon } from './../interfaces/iicon';
import { IPlainObject } from '../interfaces/iplain-object';
import paths from '../consts/paths';
/**
* Returns an object implementing the IIcon interface
* @param {string} fileName
* @returns {IIcon}
*/
function iconFactory(fileName: string): IIcon {
let name: string = path.basename(fileName, path.extname(fileName));
let last: boolean = false;
return { name, last } as IIcon;
}
/**
* > Build Icons
* @returns {gulp.Gulp}
*/
export default gulp.task('build:icons', cb => {
let contents: string;
let fileNames: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/svgs`));
let icons: IIcon[] = fileNames.map(fileName => iconFactory(fileName));
let partials: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/partials`));
let partialsData: IPlainObject = {};
let pathTemp: string = './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'
);
partialsData[path.basename(partial, path.extname(partial))] = fs.readFileSync(path.join(paths.SRC, `./icons/partials`, `./${partial}`), CHARSET);
});
let contents = Mustache.render(
fs.readFileSync(path.join(Paths.src, `./icons/icons-theme.json`), CHARSET),
{ icons },
partialData
contents = mustache.render(
fs.readFileSync(path.join(paths.SRC, `./icons/icons-theme.json`), CHARSET)
, { icons }
, partialsData
);
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);
} catch (error) {
gutil.log(gutil.colors.red(MESSAGE_ICON_ERROR), error);
cb(error);
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')
);
gutil.log(gutil.colors.gray(HR));
gutil.log(MESSAGE_GENERATED, gutil.colors.green(pathTemp));
gutil.log(gutil.colors.gray(HR));
cb();
});

View file

@ -1,63 +1,51 @@
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 * as gulp from 'gulp';
import * as gulpUtil from 'gulp-util';
import * as mustache from 'mustache';
import * as path from 'path';
import { CHARSET } from "../consts/files";
import Paths from '../paths';
import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
const themeCommons = require('../../src/themes/settings/commons.json');
const themeVariants: any[] = [];
const themeTemplateFile = fs.readFileSync(
`${Paths.src}/themes/theme-template-color-theme.json`,
CHARSET
);
import { CHARSET } from '../consts/files';
import { IThemeVariant } from './../interfaces/itheme-variant';
import paths from '../consts/paths';
const files = fs.readdirSync(`${Paths.src}/themes/settings/specific`);
let commons = require('../../src/themes/settings/commons.json');
let themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, `/themes/theme-template-color-theme.json`), CHARSET);
let themeVariants: IThemeVariant[] = [];
let fileNames: string[] = fs.readdirSync(path.join(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');
fileNames.forEach(fileName => {
let filePath: string = path.join(paths.SRC, `./themes/settings/specific`, `./${fileName}`);
let contents: string = fs.readFileSync(filePath, CHARSET);
try {
themeVariants.push(JSON.parse(contents));
} catch (err) {
gutil.log('Error when parsing json for theme variants', err);
} catch (error) {
gulpUtil.log(MESSAGE_THEME_VARIANT_PARSE_ERROR, error);
}
});
export var taskThemes = Gulp.task('build:themes', () => {
gutil.log(
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
);
/**
* Themes task
* Builds Themes
*/
export default gulp.task('build:themes', () => {
gulpUtil.log(gulpUtil.colors.gray(HR));
themeVariants.forEach(variant => {
const templateData = {
'commons': themeCommons,
variant
};
let filePath = path.join(paths.THEMES, `./${variant.name}.json`);
let templateData = { commons, variant };
let templateJSON: any = JSON.parse(mustache.render(themeTemplateFileContent, templateData));
let templateJSONStringified: string = JSON.stringify(templateJSON, null, 2);
const templateJson = JSON.parse(
Mustache.render(themeTemplateFile, templateData)
);
fs.writeFileSync(filePath, templateJSONStringified, CHARSET);
const path = `${Paths.themes}/${variant.name}.json`;
fs.writeFileSync(
path,
JSON.stringify(templateJson, null, 2),
CHARSET
);
gutil.log('Generate', gutil.colors['green'](path));
gulpUtil.log(MESSAGE_GENERATED, gulpUtil.colors.green(filePath));
});
gutil.log(
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
);
gulpUtil.log(gulpUtil.colors.gray(HR));
});

View file

@ -1,11 +1,12 @@
import * as gulp from "gulp";
import * as path from "path";
import Paths from "../consts/paths";
/*
* > Watcher
* Watches files and build the themes
*/
import * as Gulp from 'gulp';
import Paths from '../paths';
export var taskWatch = Gulp.task('watch', () => {
Gulp.watch(`${Paths.src}/themes/**/*.json`, ['build:themes']);
export default gulp.task('watch', () => {
gulp.watch(path.join(Paths.SRC, `./themes/**/*.json`), ['build:themes']);
});

48
.vscode/tasks.json vendored
View file

@ -22,6 +22,53 @@
"isShellCommand": true,
"taskName": "build"
},
{
"linux": {
"args": [
"."
, "-name"
, "\"*.js\""
, "-not"
, "-path"
, "\"./node_modules/*\""
, "-not"
, "-path"
, "\"./src/*\""
, "-not"
, "-path"
, "\"./test/*\""
, "-type"
, "f"
, "-delete"
],
"command": "find",
"isShellCommand": true
},
"osx": {
"args": [
"."
, "-name"
, "\"*.js\""
, "-not"
, "-path"
, "\"./node_modules/*\""
, "-not"
, "-path"
, "\"./src/*\""
, "-not"
, "-path"
, "\"./test/*\""
, "-type"
, "f"
, "-delete"
],
"command": "find",
"isShellCommand": true
},
"command": "",
"echoCommand": true,
"taskName": "clean project"
},
{
"args": [
"run"
@ -38,6 +85,7 @@
, "."
],
"command": "tsc",
"dependsOn": "clean project",
"echoCommand": true,
"isShellCommand": true,
"taskName": "tsc"