Skip to content

Commit

Permalink
refactor(gulp): refactor gulp scripts to conform with ts rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nnixaa committed Mar 19, 2018
1 parent a607685 commit 013d01f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
},
{
"project": "docs/tsconfig.app.json"
},
{
"project": "scripts/gulp/tsconfig.json"
}
],
"test": {
Expand Down
36 changes: 20 additions & 16 deletions scripts/gulp/tasks/docs/export-themes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const exporter = {
case 'SassColor':
if (1 === a.getA()) {
value = Colors.rgb2hex(a.getR(), a.getG(), a.getB());
}
else {
} else {
value = 'rgba(' + a.getR() + ', ' + a.getG() + ', ' + a.getB() + ', ' + a.getA() + ')';
}
break;
Expand All @@ -64,38 +63,43 @@ const exporter = {

parseThemes(THEMES) {
let result = {};
for (let themeName in THEMES) {

Object.keys(THEMES).forEach((themeName) => {
result[themeName] = result[themeName] ? result[themeName] : {};
result[themeName].data = result[themeName].data ? result[themeName].data : {};
result[themeName].name = themeName;
result[themeName].parent = THEMES[themeName].parent;
let theme = THEMES[themeName].data;
for (let prop in theme) {
const theme = THEMES[themeName].data;

Object.keys(theme).forEach((prop) => {
result[themeName].data[prop] = result[themeName].data[prop] ? result[themeName].data[prop] : new Prop(prop);
result = exporter.getParent(prop, themeName, themeName, prop, result, THEMES);
}
}
let output = {};
});
});
const output = {};
output['themes'] = result;
return output;
},

getParent(prop, scopedThemeName, resultThemeName, resultProp, resultObj, THEMES) {
let scopedTheme = THEMES[scopedThemeName].data;
let scopedParent = THEMES[scopedThemeName].parent;
let value = scopedTheme[prop];
if (resultProp === 'footer-height' && resultThemeName === 'light') debugger;
if (typeof value === "string" && scopedTheme[value]) {
const scopedTheme = THEMES[scopedThemeName].data;
const scopedParent = THEMES[scopedThemeName].parent;
const value = scopedTheme[prop];
if (typeof value === 'string' && scopedTheme[value]) {
if (resultObj[resultThemeName].data[resultProp].parents.length === 0) {
exporter.linkProps(resultObj, scopedThemeName, value, resultThemeName, prop);
} else resultObj[resultThemeName].data[resultProp].parents.push(new PropLink(scopedThemeName, value));
} else {
resultObj[resultThemeName].data[resultProp].parents.push(new PropLink(scopedThemeName, value));
}
exporter.getParent(value, scopedThemeName, resultThemeName, resultProp, resultObj, THEMES);
} else {
resultObj[resultThemeName].data[resultProp].value = value;
if (scopedParent && THEMES[scopedParent].data[prop] === value) {
if (resultObj[resultThemeName].data[resultProp].parents.length === 0) {
exporter.linkProps(resultObj, scopedParent, prop, resultThemeName, prop)
} else resultObj[resultThemeName].data[resultProp].parents.push(new PropLink(scopedParent, prop));
} else {
resultObj[resultThemeName].data[resultProp].parents.push(new PropLink(scopedParent, prop));
}
}
}
return resultObj;
Expand All @@ -117,7 +121,7 @@ const exporter = {

function(path) {
return function (file, value, options) {
let opt = _.defaults(exporter.get_value(options), { prefix: '', suffix: '', extend: false });
const opt = _.defaults(exporter.get_value(options), { prefix: '', suffix: '', extend: false });
let output = exporter.get_value(value);
output = exporter.parseThemes(output);
output = _.defaults(JSON.parse(fs.readFileSync(path + '/' + file.getValue())), output);
Expand Down
5 changes: 3 additions & 2 deletions scripts/gulp/tasks/inline-resources/copy-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const writeFile = promiseify(fs.writeFile);


export function copyResources(globs) {
if (typeof globs == 'string') {
if (typeof globs === 'string') {
globs = [globs];
}

Expand Down Expand Up @@ -68,7 +68,7 @@ function inlineResourcesFromString(content, urlResolver) {
inlineTemplate,
inlineStyle,
removeModuleId,
].reduce((content, fn) => fn(content, urlResolver), content);
].reduce((с, fn) => fn(с, urlResolver), content);
}

if (require.main === module) {
Expand Down Expand Up @@ -104,6 +104,7 @@ function inlineTemplate(content, urlResolver) {
*/
function inlineStyle(content, urlResolver) {
return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function (_, styleUrls) {
// tslint:disable-next-line
const urls = eval(styleUrls);
return 'styles: [' +
urls.map(styleUrl => {
Expand Down

0 comments on commit 013d01f

Please sign in to comment.