diff --git a/.gitignore b/.gitignore index 46fb5c3..fddf126 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.log *.~lock *.js +*.gulp/**.js dist/ node_modules/ \ No newline at end of file diff --git a/.gulp/consts/files.ts b/.gulp/consts/files.ts new file mode 100644 index 0000000..ccde74c --- /dev/null +++ b/.gulp/consts/files.ts @@ -0,0 +1,5 @@ +/** + * File charset + * @type {string} + */ +export const CHARSET: string = 'utf-8'; \ No newline at end of file diff --git a/.gulp/index.ts b/.gulp/index.ts new file mode 100644 index 0000000..1787a2f --- /dev/null +++ b/.gulp/index.ts @@ -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']; diff --git a/.gulp/paths.ts b/.gulp/paths.ts new file mode 100644 index 0000000..f547d5b --- /dev/null +++ b/.gulp/paths.ts @@ -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; diff --git a/.gulp/tasks/bump.ts b/.gulp/tasks/bump.ts new file mode 100644 index 0000000..1870c4c --- /dev/null +++ b/.gulp/tasks/bump.ts @@ -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('./')); +}); \ No newline at end of file diff --git a/.gulp/tasks/changelog.ts b/.gulp/tasks/changelog.ts new file mode 100644 index 0000000..380a59e --- /dev/null +++ b/.gulp/tasks/changelog.ts @@ -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('./')); +}); \ No newline at end of file diff --git a/.gulp/tasks/icons.ts b/.gulp/tasks/icons.ts new file mode 100644 index 0000000..7e55ac6 --- /dev/null +++ b/.gulp/tasks/icons.ts @@ -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(); +}); diff --git a/.gulp/tasks/themes.ts b/.gulp/tasks/themes.ts new file mode 100644 index 0000000..5525ebd --- /dev/null +++ b/.gulp/tasks/themes.ts @@ -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') + ); +}); diff --git a/.gulp/tasks/watcher.ts b/.gulp/tasks/watcher.ts new file mode 100644 index 0000000..2616538 --- /dev/null +++ b/.gulp/tasks/watcher.ts @@ -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']); +}); \ No newline at end of file diff --git a/gulpfile.babel.ts b/gulpfile.babel.ts new file mode 100644 index 0000000..7925e68 --- /dev/null +++ b/gulpfile.babel.ts @@ -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); \ No newline at end of file