chore: add a clean project task (removes js files) and improve ts tasks
This commit is contained in:
parent
5087a0880d
commit
bb7e3db86f
14 changed files with 260 additions and 126 deletions
6
.gulp/consts/log.ts
Normal file
6
.gulp/consts/log.ts
Normal 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
10
.gulp/consts/paths.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { IPaths } from '../interfaces/ipaths';
|
||||||
|
|
||||||
|
const PATHS: IPaths = {
|
||||||
|
DIST: './dist',
|
||||||
|
ICONS: './icons',
|
||||||
|
SRC: './src',
|
||||||
|
THEMES: './themes',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PATHS;
|
|
@ -1,4 +1,4 @@
|
||||||
// import the tasks
|
// export the tasks
|
||||||
export * from './tasks/changelog';
|
export * from './tasks/changelog';
|
||||||
export * from './tasks/bump';
|
export * from './tasks/bump';
|
||||||
export * from './tasks/icons';
|
export * from './tasks/icons';
|
||||||
|
|
14
.gulp/interfaces/iicon.ts
Normal file
14
.gulp/interfaces/iicon.ts
Normal 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;
|
||||||
|
}
|
26
.gulp/interfaces/ipaths.ts
Normal file
26
.gulp/interfaces/ipaths.ts
Normal 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;
|
||||||
|
}
|
3
.gulp/interfaces/iplain-object.ts
Normal file
3
.gulp/interfaces/iplain-object.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export interface IPlainObject {
|
||||||
|
[index: string]: string;
|
||||||
|
}
|
42
.gulp/interfaces/itheme-variant.ts
Normal file
42
.gulp/interfaces/itheme-variant.ts
Normal 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;
|
||||||
|
}
|
|
@ -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;
|
|
|
@ -1,35 +1,35 @@
|
||||||
/*
|
|
||||||
* > Bump
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as Gulp from 'gulp';
|
|
||||||
import * as Gulpif from 'gulp-if';
|
|
||||||
import * as bump from 'gulp-bump';
|
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 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(
|
runSequence(
|
||||||
'bump-pkg-version',
|
'bump-pkg-version',
|
||||||
(error) => {
|
error => {
|
||||||
if (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 {
|
} 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);
|
cb(error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export var taskVersioning = Gulp.task('bump-pkg-version', () => {
|
export var taskVersioning = gulp.task('bump-pkg-version', () => {
|
||||||
return Gulp.src(['./package.json'])
|
return gulp.src(['./package.json'])
|
||||||
.pipe(Gulpif((Object.keys(argv).length === 2), bump()))
|
.pipe(gulpIf((Object.keys(argv).length === 2), bump()))
|
||||||
.pipe(Gulpif(argv.patch, bump()))
|
.pipe(gulpIf(argv.patch, bump()))
|
||||||
.pipe(Gulpif(argv.minor, bump({ type: 'minor' })))
|
.pipe(gulpIf(argv.minor, bump({ type: 'minor' })))
|
||||||
.pipe(Gulpif(argv.major, bump({ type: 'major' })))
|
.pipe(gulpIf(argv.major, bump({ type: 'major' })))
|
||||||
.pipe(Gulp.dest('./'));
|
.pipe(gulp.dest('./'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default { taskBump, taskVersioning };
|
|
@ -2,14 +2,14 @@
|
||||||
* > Changelog
|
* > Changelog
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
import * as conventionalChangelog from 'gulp-conventional-changelog';
|
import * as gulpConventionalChangelog from 'gulp-conventional-changelog';
|
||||||
|
|
||||||
export var task = Gulp.task('changelog', () => {
|
export var task = gulp.task('changelog', () => {
|
||||||
return Gulp.src('CHANGELOG.md')
|
return gulp.src('CHANGELOG.md')
|
||||||
.pipe(conventionalChangelog({
|
.pipe(gulpConventionalChangelog({
|
||||||
preset: 'angular',
|
preset: 'angular',
|
||||||
releaseCount: 0
|
releaseCount: 0
|
||||||
}))
|
}))
|
||||||
.pipe(Gulp.dest('./'));
|
.pipe(gulp.dest('./'));
|
||||||
});
|
});
|
|
@ -1,58 +1,65 @@
|
||||||
/*
|
|
||||||
* > Build Icons
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as Gulp from 'gulp';
|
|
||||||
import * as Mustache from 'mustache';
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as gulp from 'gulp';
|
||||||
import * as gutil from 'gulp-util';
|
import * as gutil from 'gulp-util';
|
||||||
|
import * as mustache from 'mustache';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
import { CHARSET } from "../consts/files";
|
import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log';
|
||||||
import Paths from '../paths';
|
|
||||||
|
|
||||||
export var taskIcons = Gulp.task('build:icons', cb => {
|
import { CHARSET } from '../consts/files';
|
||||||
const partials = fs.readdirSync(path.join(Paths.src, `./icons/partials`));
|
import { IIcon } from './../interfaces/iicon';
|
||||||
const partialData: any = {};
|
import { IPlainObject } from '../interfaces/iplain-object';
|
||||||
const files = fs.readdirSync(path.join(Paths.src, `./icons/svgs`));
|
import paths from '../consts/paths';
|
||||||
const icons = files.map(file => ({ name: file.split('.')[0], last: false }));
|
|
||||||
const pathTemp = './themes/.material-theme-icons.tmp';
|
/**
|
||||||
|
* 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;
|
icons[icons.length - 1].last = true;
|
||||||
|
|
||||||
partials.forEach(partial => {
|
partials.forEach(partial => {
|
||||||
partialData[partial.split('.')[0]] = fs.readFileSync(
|
partialsData[path.basename(partial, path.extname(partial))] = fs.readFileSync(path.join(paths.SRC, `./icons/partials`, `./${partial}`), CHARSET);
|
||||||
path.join(Paths.src, `./icons/partials`, `./${partial}`),
|
|
||||||
'utf-8'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let contents = Mustache.render(
|
contents = mustache.render(
|
||||||
fs.readFileSync(path.join(Paths.src, `./icons/icons-theme.json`), CHARSET),
|
fs.readFileSync(path.join(paths.SRC, `./icons/icons-theme.json`), CHARSET)
|
||||||
{ icons },
|
, { icons }
|
||||||
partialData
|
, partialsData
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
contents = JSON.stringify(JSON.parse(contents), null, 2);
|
contents = JSON.stringify(JSON.parse(contents), null, 2);
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
gutil.log(
|
gutil.log(gutil.colors.red(MESSAGE_ICON_ERROR), error);
|
||||||
gutil.colors['red']('There is an error with JSON generated for icons'),
|
cb(error);
|
||||||
err
|
|
||||||
);
|
|
||||||
cb(err);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(pathTemp, contents, CHARSET);
|
fs.writeFileSync(pathTemp, contents, CHARSET);
|
||||||
|
|
||||||
gutil.log(
|
gutil.log(gutil.colors.gray(HR));
|
||||||
gutil.colors['gray']('\n———————————————————————————————————————————————————————————————\n')
|
gutil.log(MESSAGE_GENERATED, gutil.colors.green(pathTemp));
|
||||||
);
|
gutil.log(gutil.colors.gray(HR));
|
||||||
gutil.log('Generated', gutil.colors['green'](pathTemp));
|
|
||||||
gutil.log(
|
|
||||||
gutil.colors['gray']('\n———————————————————————————————————————————————————————————————\n')
|
|
||||||
);
|
|
||||||
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 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 { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
|
||||||
import Paths from '../paths';
|
|
||||||
|
|
||||||
const themeCommons = require('../../src/themes/settings/commons.json');
|
import { CHARSET } from '../consts/files';
|
||||||
const themeVariants: any[] = [];
|
import { IThemeVariant } from './../interfaces/itheme-variant';
|
||||||
const themeTemplateFile = fs.readFileSync(
|
import paths from '../consts/paths';
|
||||||
`${Paths.src}/themes/theme-template-color-theme.json`,
|
|
||||||
CHARSET
|
|
||||||
);
|
|
||||||
|
|
||||||
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
|
// build theme variants for later use in templating
|
||||||
files.forEach(file => {
|
fileNames.forEach(fileName => {
|
||||||
// const name: string = file.split('.')[0];
|
let filePath: string = path.join(paths.SRC, `./themes/settings/specific`, `./${fileName}`);
|
||||||
const filepath = `${Paths.src}/themes/settings/specific/${file}`;
|
let contents: string = fs.readFileSync(filePath, CHARSET);
|
||||||
const contents = fs.readFileSync(filepath, 'utf-8');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
themeVariants.push(JSON.parse(contents));
|
themeVariants.push(JSON.parse(contents));
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
gutil.log('Error when parsing json for theme variants', err);
|
gulpUtil.log(MESSAGE_THEME_VARIANT_PARSE_ERROR, error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export var taskThemes = Gulp.task('build:themes', () => {
|
/**
|
||||||
gutil.log(
|
* Themes task
|
||||||
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
|
* Builds Themes
|
||||||
);
|
*/
|
||||||
|
export default gulp.task('build:themes', () => {
|
||||||
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
||||||
|
|
||||||
themeVariants.forEach(variant => {
|
themeVariants.forEach(variant => {
|
||||||
const templateData = {
|
let filePath = path.join(paths.THEMES, `./${variant.name}.json`);
|
||||||
'commons': themeCommons,
|
let templateData = { commons, variant };
|
||||||
variant
|
let templateJSON: any = JSON.parse(mustache.render(themeTemplateFileContent, templateData));
|
||||||
};
|
let templateJSONStringified: string = JSON.stringify(templateJSON, null, 2);
|
||||||
|
|
||||||
const templateJson = JSON.parse(
|
fs.writeFileSync(filePath, templateJSONStringified, CHARSET);
|
||||||
Mustache.render(themeTemplateFile, templateData)
|
|
||||||
);
|
|
||||||
|
|
||||||
const path = `${Paths.themes}/${variant.name}.json`;
|
gulpUtil.log(MESSAGE_GENERATED, gulpUtil.colors.green(filePath));
|
||||||
|
|
||||||
fs.writeFileSync(
|
|
||||||
path,
|
|
||||||
JSON.stringify(templateJson, null, 2),
|
|
||||||
CHARSET
|
|
||||||
);
|
|
||||||
|
|
||||||
gutil.log('Generate', gutil.colors['green'](path));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
gutil.log(
|
gulpUtil.log(gulpUtil.colors.gray(HR));
|
||||||
gutil.colors.gray('\n———————————————————————————————————————————————————————————————\n')
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
import * as gulp from "gulp";
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
|
import Paths from "../consts/paths";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* > Watcher
|
* > Watcher
|
||||||
|
* Watches files and build the themes
|
||||||
*/
|
*/
|
||||||
|
export default gulp.task('watch', () => {
|
||||||
import * as Gulp from 'gulp';
|
gulp.watch(path.join(Paths.SRC, `./themes/**/*.json`), ['build:themes']);
|
||||||
|
|
||||||
import Paths from '../paths';
|
|
||||||
|
|
||||||
export var taskWatch = Gulp.task('watch', () => {
|
|
||||||
Gulp.watch(`${Paths.src}/themes/**/*.json`, ['build:themes']);
|
|
||||||
});
|
});
|
48
.vscode/tasks.json
vendored
48
.vscode/tasks.json
vendored
|
@ -22,6 +22,53 @@
|
||||||
"isShellCommand": true,
|
"isShellCommand": true,
|
||||||
"taskName": "build"
|
"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": [
|
"args": [
|
||||||
"run"
|
"run"
|
||||||
|
@ -38,6 +85,7 @@
|
||||||
, "."
|
, "."
|
||||||
],
|
],
|
||||||
"command": "tsc",
|
"command": "tsc",
|
||||||
|
"dependsOn": "clean project",
|
||||||
"echoCommand": true,
|
"echoCommand": true,
|
||||||
"isShellCommand": true,
|
"isShellCommand": true,
|
||||||
"taskName": "tsc"
|
"taskName": "tsc"
|
||||||
|
|
Loading…
Reference in a new issue