-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): add fix icon schematic
- Loading branch information
Showing
11 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { chain, Rule, Tree } from '@angular-devkit/schematics'; | ||
import { getProjectFromWorkspace, getWorkspace } from '../utils/devkit-utils/config'; | ||
import { getProjectTargetOptions } from '../utils/project-targets'; | ||
import { Schema } from './schema'; | ||
|
||
const ICON_ASSET_CONFIG = { | ||
'glob' : '**/*', | ||
'input' : './node_modules/@ant-design/icons/inline-svg/', | ||
'output': '/assets/' | ||
}; | ||
|
||
export default function (options: Schema): Rule { | ||
return chain([ | ||
addIconToAssets(options) | ||
]); | ||
} | ||
|
||
function addIconToAssets(options: Schema): (host: Tree) => Tree { | ||
return (host: Tree) => { | ||
const workspace = getWorkspace(host); | ||
const project = getProjectFromWorkspace(workspace, options.project); | ||
const targetOptions = getProjectTargetOptions(project, 'build'); | ||
|
||
if (!targetOptions.assets) { | ||
targetOptions.assets = [ { ...ICON_ASSET_CONFIG } ]; | ||
} else { | ||
let hasIconAssetConfig = false; | ||
|
||
// tslint:disable-next-line | ||
for (let i = 0; i < targetOptions.assets.length; i++) { | ||
const asset = targetOptions.assets[ i ]; | ||
if (typeof asset === 'object' && equals(ICON_ASSET_CONFIG, asset)) { | ||
hasIconAssetConfig = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!hasIconAssetConfig) { | ||
targetOptions.assets.push({ ...ICON_ASSET_CONFIG }); | ||
} | ||
} | ||
host.overwrite('angular.json', JSON.stringify(workspace, null, 2)); | ||
return host; | ||
}; | ||
} | ||
|
||
function equals(obj1: object, obj2: object): boolean { | ||
Object.keys(obj1).forEach(k => { | ||
if (!obj2.hasOwnProperty(k) || obj1[ k ] !== obj2[ k ]) { | ||
return false; | ||
} | ||
}); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"id": "fixIcon", | ||
"title": "fix icon", | ||
"type": "object", | ||
"properties": { | ||
"project": { | ||
"type": "string", | ||
"description": "Name of the project to target." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface Schema { | ||
/** Name of the project to target. */ | ||
project?: string; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters