-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new
ng-standalone
template
- Loading branch information
Showing
19 changed files
with
230 additions
and
20 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { NgModuleTemplate } from './ng-module'; | ||
export { NgStandaloneTemplate } from './ng-standalone'; | ||
export { NgEnvTemplate } from './ng-env'; | ||
export { NgAppTemplate } from './ng-app'; |
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
33 changes: 33 additions & 0 deletions
33
angular/templates/generators/ng-standalone/files/component-spec.ts
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 { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const componentSpecFile = (context: ComponentContext): ComponentFile => { | ||
const { name, namePascalCase: Name } = context; | ||
|
||
return { | ||
relativePath: `${name}.spec.ts`, | ||
content: `import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ${Name}Component } from './${name}.component'; | ||
describe('${Name}Component', () => { | ||
let component: ${Name}Component; | ||
let fixture: ComponentFixture<${Name}Component>; | ||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ ${Name}Component ] | ||
}) | ||
.compileComponents(); | ||
fixture = TestBed.createComponent(${Name}Component); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); | ||
`, | ||
}; | ||
}; |
11 changes: 11 additions & 0 deletions
11
angular/templates/generators/ng-standalone/files/component-styles.ts
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,11 @@ | ||
import { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const componentStylesFile = (context: ComponentContext): ComponentFile => { | ||
const { name } = context; | ||
return { | ||
relativePath: `${name}.component.scss`, | ||
content: `:host { | ||
font-size: inherit; | ||
}`, | ||
}; | ||
}; |
26 changes: 26 additions & 0 deletions
26
angular/templates/generators/ng-standalone/files/component.ts
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,26 @@ | ||
import { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const componentFile = (context: ComponentContext): ComponentFile => { | ||
const { name, namePascalCase: Name } = context; | ||
return { | ||
relativePath: `${name}.component.ts`, | ||
content: `import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
@Component({ | ||
selector: '${name}', | ||
standalone: true, | ||
imports: [CommonModule], | ||
template: \` | ||
<p> | ||
${name} works! | ||
</p> | ||
\`, | ||
styleUrls: ['./${name}.component.scss'] | ||
}) | ||
export class ${Name}Component { | ||
constructor() {} | ||
} | ||
`, | ||
}; | ||
}; |
22 changes: 22 additions & 0 deletions
22
angular/templates/generators/ng-standalone/files/composition.ts
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,22 @@ | ||
import { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const compositionFile = (context: ComponentContext): ComponentFile => { | ||
const { name, namePascalCase: Name } = context; | ||
|
||
const standaloneComposition = `import { Component } from '@angular/core'; | ||
import { ${Name}Component } from './${name}.component'; | ||
@Component({ | ||
standalone: true, | ||
selector: '${name}-composition-cmp', | ||
imports: [${Name}Component], | ||
template: \`${Name} composition: <${name}></${name}>\` | ||
}) | ||
export class ${Name}CompositionComponent {} | ||
`; | ||
|
||
return { | ||
relativePath: `${name}.composition.ts`, | ||
content: standaloneComposition, | ||
}; | ||
}; |
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,38 @@ | ||
import { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const docsFile = (context: ComponentContext): ComponentFile => { | ||
const { name, namePascalCase: Name } = context; | ||
|
||
return { | ||
relativePath: `${name}.docs.md`, | ||
content: `--- | ||
labels: ['angular', 'typescript', '${name}'] | ||
description: 'A \`${name}\` component.' | ||
--- | ||
# ${Name} documentation | ||
Import \`${Name}Component\` into your application: | ||
\`\`\`ts | ||
import { ${Name}Component } from './${name}.component'; | ||
// add it to your component imports | ||
@Component({ | ||
selector: 'app-root', | ||
standalone: true, | ||
imports: [ | ||
${Name}Component | ||
] | ||
}) | ||
export class AppComponent {} | ||
\`\`\` | ||
Use \`${Name}Component\` in your generators: | ||
\`\`\`html | ||
<${name}></${name}> | ||
\`\`\` | ||
`, | ||
}; | ||
}; |
14 changes: 14 additions & 0 deletions
14
angular/templates/generators/ng-standalone/files/public-api.ts
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,14 @@ | ||
import { ComponentContext, ComponentFile } from '@teambit/generator'; | ||
|
||
export const publicApiFile = (context: ComponentContext): ComponentFile => { | ||
const { name } = context; | ||
return { | ||
isMain: true, | ||
relativePath: 'public-api.ts', | ||
content: `/** | ||
* Entry point for this Angular library, do not move or rename this file. | ||
*/ | ||
export * from './${name}.component'; | ||
`, | ||
}; | ||
}; |
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,38 @@ | ||
import { ComponentContext, ComponentTemplate } from '@teambit/generator'; | ||
import { AngularComponentTemplateOptions } from '@bitdev/angular.dev-services.common'; | ||
import { componentFile } from './files/component'; | ||
import { componentSpecFile } from './files/component-spec'; | ||
import { componentStylesFile } from './files/component-styles'; | ||
import { compositionFile } from './files/composition'; | ||
import { docsFile } from './files/docs'; | ||
import { publicApiFile } from './files/public-api'; | ||
|
||
export class NgStandaloneTemplate implements ComponentTemplate { | ||
private constructor( | ||
readonly angularVersion: number, | ||
readonly name = 'ng-standalone', | ||
readonly description = 'create a standalone Angular component', | ||
readonly hidden = false | ||
) {} | ||
|
||
generateFiles(context: ComponentContext) { | ||
return [ | ||
publicApiFile(context), | ||
componentFile(context), | ||
componentStylesFile(context), | ||
docsFile(context), | ||
componentSpecFile(context), | ||
compositionFile(context), | ||
]; | ||
} | ||
|
||
static from(options: AngularComponentTemplateOptions & { angularVersion: number }) { | ||
return () => | ||
new NgStandaloneTemplate( | ||
options.angularVersion, | ||
options.name, | ||
options.description, | ||
options.hidden | ||
); | ||
} | ||
} |
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
Oops, something went wrong.