From bb7e3db86f40e22b6f90e65c7511d6da10cd0d8c Mon Sep 17 00:00:00 2001 From: OctoD roth Date: Wed, 24 May 2017 00:46:34 +0200 Subject: [PATCH] chore: add a clean project task (removes js files) and improve ts tasks --- .gulp/consts/log.ts | 6 +++ .gulp/consts/paths.ts | 10 ++++ .gulp/index.ts | 2 +- .gulp/interfaces/iicon.ts | 14 ++++++ .gulp/interfaces/ipaths.ts | 26 ++++++++++ .gulp/interfaces/iplain-object.ts | 3 ++ .gulp/interfaces/itheme-variant.ts | 42 ++++++++++++++++ .gulp/paths.ts | 11 ----- .gulp/tasks/bump.ts | 42 ++++++++-------- .gulp/tasks/changelog.ts | 12 ++--- .gulp/tasks/icons.ts | 77 +++++++++++++++-------------- .gulp/tasks/themes.ts | 78 +++++++++++++----------------- .gulp/tasks/watcher.ts | 15 +++--- .vscode/tasks.json | 48 ++++++++++++++++++ 14 files changed, 260 insertions(+), 126 deletions(-) create mode 100644 .gulp/consts/log.ts create mode 100644 .gulp/consts/paths.ts create mode 100644 .gulp/interfaces/iicon.ts create mode 100644 .gulp/interfaces/ipaths.ts create mode 100644 .gulp/interfaces/iplain-object.ts create mode 100644 .gulp/interfaces/itheme-variant.ts delete mode 100644 .gulp/paths.ts diff --git a/.gulp/consts/log.ts b/.gulp/consts/log.ts new file mode 100644 index 0000000..d9bada2 --- /dev/null +++ b/.gulp/consts/log.ts @@ -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'; \ No newline at end of file diff --git a/.gulp/consts/paths.ts b/.gulp/consts/paths.ts new file mode 100644 index 0000000..1fcf397 --- /dev/null +++ b/.gulp/consts/paths.ts @@ -0,0 +1,10 @@ +import { IPaths } from '../interfaces/ipaths'; + +const PATHS: IPaths = { + DIST: './dist', + ICONS: './icons', + SRC: './src', + THEMES: './themes', +}; + +export default PATHS; diff --git a/.gulp/index.ts b/.gulp/index.ts index 1787a2f..2c2d4bb 100644 --- a/.gulp/index.ts +++ b/.gulp/index.ts @@ -1,4 +1,4 @@ -// import the tasks +// export the tasks export * from './tasks/changelog'; export * from './tasks/bump'; export * from './tasks/icons'; diff --git a/.gulp/interfaces/iicon.ts b/.gulp/interfaces/iicon.ts new file mode 100644 index 0000000..3d269c0 --- /dev/null +++ b/.gulp/interfaces/iicon.ts @@ -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; +} \ No newline at end of file diff --git a/.gulp/interfaces/ipaths.ts b/.gulp/interfaces/ipaths.ts new file mode 100644 index 0000000..0bb68f0 --- /dev/null +++ b/.gulp/interfaces/ipaths.ts @@ -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; +} \ No newline at end of file diff --git a/.gulp/interfaces/iplain-object.ts b/.gulp/interfaces/iplain-object.ts new file mode 100644 index 0000000..91df42d --- /dev/null +++ b/.gulp/interfaces/iplain-object.ts @@ -0,0 +1,3 @@ +export interface IPlainObject { + [index: string]: string; +} \ No newline at end of file diff --git a/.gulp/interfaces/itheme-variant.ts b/.gulp/interfaces/itheme-variant.ts new file mode 100644 index 0000000..3f74e6c --- /dev/null +++ b/.gulp/interfaces/itheme-variant.ts @@ -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; +} \ No newline at end of file diff --git a/.gulp/paths.ts b/.gulp/paths.ts deleted file mode 100644 index f547d5b..0000000 --- a/.gulp/paths.ts +++ /dev/null @@ -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; diff --git a/.gulp/tasks/bump.ts b/.gulp/tasks/bump.ts index 1870c4c..a8007e4 100644 --- a/.gulp/tasks/bump.ts +++ b/.gulp/tasks/bump.ts @@ -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('./')); -}); \ No newline at end of file +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 }; \ No newline at end of file diff --git a/.gulp/tasks/changelog.ts b/.gulp/tasks/changelog.ts index 380a59e..176780e 100644 --- a/.gulp/tasks/changelog.ts +++ b/.gulp/tasks/changelog.ts @@ -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('./')); }); \ No newline at end of file diff --git a/.gulp/tasks/icons.ts b/.gulp/tasks/icons.ts index 7e55ac6..6d486a4 100644 --- a/.gulp/tasks/icons.ts +++ b/.gulp/tasks/icons.ts @@ -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(); }); diff --git a/.gulp/tasks/themes.ts b/.gulp/tasks/themes.ts index 5525ebd..09b9979 100644 --- a/.gulp/tasks/themes.ts +++ b/.gulp/tasks/themes.ts @@ -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)); }); diff --git a/.gulp/tasks/watcher.ts b/.gulp/tasks/watcher.ts index 2616538..0cd75e3 100644 --- a/.gulp/tasks/watcher.ts +++ b/.gulp/tasks/watcher.ts @@ -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']); }); \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e89c89b..9dd62b1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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"