-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from kaltepeter/feature/schemas
feat(schemas): extend schema and split builders
- Loading branch information
Showing
12 changed files
with
512 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
{ | ||
"$schema": "@angular-devkit/architect/src/builders-schema.json", | ||
"builders": { | ||
"svg-icons-builder": { | ||
"implementation": "./svg-icons-builder", | ||
"svg-icons-constants-builder": { | ||
"implementation": "./svg-icons-builder/constants", | ||
"schema": "./svg-icons-builder/schema.json", | ||
"description": "Build SVG icons." | ||
"description": "Build SVG icons using `constants` conversion type." | ||
}, | ||
"svg-icons-object-builder": { | ||
"implementation": "./svg-icons-builder/object", | ||
"schema": "./svg-icons-builder/schema.json", | ||
"description": "Build SVG icons using `objects` conversion type." | ||
}, | ||
"svg-icons-files-builder": { | ||
"implementation": "./svg-icons-builder/files", | ||
"schema": "./svg-icons-builder/schema.json", | ||
"description": "Build SVG icons using `files` conversion type." | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 { Architect } from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { logging, schema } from '@angular-devkit/core'; | ||
import { ConversionType } from 'svg-to-ts'; | ||
import { defaultCommonOptions } from '../test-helpers'; | ||
const { join } = require('path'); | ||
|
||
describe('svg-icons-builder', () => { | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
|
||
beforeEach(async () => { | ||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
const workspaceRoot = join(__dirname, '..', '..'); | ||
|
||
architectHost = new TestingArchitectHost('/root', '/root'); | ||
architect = new Architect(architectHost, registry); | ||
|
||
await architectHost.addBuilderFromPackage(workspaceRoot); | ||
}); | ||
|
||
it('generates `constants` for icons', async () => { | ||
const logger = new logging.Logger(''); | ||
const logs: string[] = []; | ||
logger.subscribe((ev) => logs.push(ev.message)); | ||
|
||
const run = await architect.scheduleBuilder( | ||
'@angular-extensions/svg-icons-builder:svg-icons-constants-builder', | ||
{ | ||
...defaultCommonOptions(), | ||
conversionType: ConversionType.CONSTANTS, | ||
fileName: 'dinosaur-icons', | ||
typeName: 'dinosaurIcon', | ||
generateType: true, | ||
generateTypeObject: true, | ||
generateCompleteIconSet: true, | ||
prefix: 'dinosaurIcon', | ||
interfaceName: 'DinosaurIcon', | ||
}, | ||
{ logger } | ||
); | ||
|
||
expect(await run.result).toEqual( | ||
expect.objectContaining({ | ||
success: true, | ||
}) | ||
); | ||
|
||
await run.stop(); | ||
|
||
expect(logs).toContain('We are using the conversion type "constants"'); | ||
}); | ||
}); |
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,28 @@ | ||
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect'; | ||
import { JsonObject } from '@angular-devkit/core'; | ||
import { ConstantsConversionOptions, ConversionType, convertToConstants, mergeWithDefaults } from 'svg-to-ts'; | ||
|
||
interface Options extends ConstantsConversionOptions {} | ||
|
||
// Using `Options & JsonObject` instead of extending JsonObject because of optional boolean | ||
export default createBuilder<Options & JsonObject>((options: Options, context: BuilderContext) => { | ||
return new Promise<BuilderOutput>(async (resolve, reject) => { | ||
try { | ||
if (options.conversionType !== ConversionType.CONSTANTS) { | ||
reject(new Error(`This builder only supports '${ConversionType.CONSTANTS}' conversionType.`)); | ||
} | ||
|
||
const conversionOptions = await mergeWithDefaults(options); | ||
context.logger.info('We are using the conversion type "constants"'); | ||
await convertToConstants((conversionOptions as unknown) as ConstantsConversionOptions); | ||
|
||
resolve({ success: true }); | ||
context.reportStatus(`Done.`); | ||
} catch (error) { | ||
context.reportStatus(`Error: ${error.message}`); | ||
reject(error); | ||
process.disconnect(); | ||
process.exit(1); | ||
} | ||
}); | ||
}); |
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,57 @@ | ||
import { Architect } from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { logging, schema } from '@angular-devkit/core'; | ||
import { defaultCommonOptions } from '../test-helpers'; | ||
const { join } = require('path'); | ||
|
||
describe('svg-icons-builder', () => { | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
|
||
beforeEach(async () => { | ||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
const workspaceRoot = join(__dirname, '..', '..'); | ||
|
||
architectHost = new TestingArchitectHost('/root', '/root'); | ||
architect = new Architect(architectHost, registry); | ||
|
||
await architectHost.addBuilderFromPackage(workspaceRoot); | ||
console.log('#', Array.from((architectHost as any)._builderMap.keys())); | ||
}); | ||
|
||
it('generates `files` for icons', async () => { | ||
const logger = new logging.Logger(''); | ||
const logs: string[] = []; | ||
logger.subscribe((ev) => logs.push(ev.message)); | ||
|
||
const run = await architect.scheduleBuilder( | ||
'@angular-extensions/svg-icons-builder:svg-icons-files-builder', | ||
{ | ||
...defaultCommonOptions(), | ||
conversionType: 'files', | ||
typeName: 'dinosaurIcon', | ||
generateType: true, | ||
generateTypeObject: true, | ||
exportCompleteIconSet: true, | ||
prefix: 'dinosaurIcon', | ||
interfaceName: 'DinosaurIcon', | ||
modelFileName: 'dinosaur-icons.model', | ||
iconsFolderName: 'build', | ||
compileSources: true, | ||
barrelFileName: 'index', | ||
}, | ||
{ logger } | ||
); | ||
|
||
expect(await run.result).toEqual( | ||
expect.objectContaining({ | ||
success: true, | ||
}) | ||
); | ||
|
||
await run.stop(); | ||
|
||
expect(logs).toContain('We are using the conversion type "files"'); | ||
}); | ||
}); |
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,33 @@ | ||
import { BuilderContext, BuilderOutput, createBuilder } from '@angular-devkit/architect'; | ||
import { JsonObject } from '@angular-devkit/core'; | ||
import { | ||
ConversionType, | ||
FileConversionOptions, | ||
convertToFiles, | ||
mergeWithDefaults, | ||
} from 'svg-to-ts'; | ||
|
||
interface Options extends FileConversionOptions {} | ||
|
||
// Using `Options & JsonObject` instead of extending JsonObject because of optional boolean | ||
export default createBuilder<Options & JsonObject>((options: Options, context: BuilderContext) => { | ||
return new Promise<BuilderOutput>(async (resolve, reject) => { | ||
try { | ||
if (options.conversionType !== ConversionType.FILES) { | ||
reject(new Error(`This builder only supports '${ConversionType.FILES}' conversionType.`)); | ||
} | ||
|
||
const conversionOptions = await mergeWithDefaults(options); | ||
context.logger.info('We are using the conversion type "files"'); | ||
await convertToFiles((conversionOptions as unknown) as FileConversionOptions); | ||
|
||
resolve({ success: true }); | ||
context.reportStatus(`Done.`); | ||
} catch (error) { | ||
context.reportStatus(`Error: ${error.message}`); | ||
reject(error); | ||
process.disconnect(); | ||
process.exit(1); | ||
} | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.