-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): Add generator for modules
- Loading branch information
Showing
5 changed files
with
116 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var ComponentGenerator = require('../componentGenerator'); | ||
var Generator = module.exports = ComponentGenerator.extend({ | ||
|
||
constructor: function() { | ||
this.basetype = 'ngmodule'; // this will create a property this.ngmodulename | ||
this.basefolder = ''; // this is the folder for the components | ||
this.hasOwnFolder = false; // to specify if the component files should be in a subfolder | ||
this.isDasherize = true; // to specify that the file name should be dasherized | ||
ComponentGenerator.apply(this, arguments); | ||
}, | ||
|
||
initializing: function() { | ||
Generator.__super__.initializing.apply(this, arguments); | ||
}, | ||
|
||
prompting: function() { | ||
var done = this.async(); | ||
Generator.__super__.prompting.call(this, done); | ||
|
||
}, | ||
|
||
configuring: function() { | ||
Generator.__super__.configuring.apply(this, arguments); | ||
}, | ||
|
||
writing: function() { | ||
var destinationPath = Generator.__super__.writing.apply(this, arguments); | ||
this.fs.copyTpl( | ||
this.templatePath('_module.ts'), | ||
this.destinationPath(path.join(destinationPath, 'index.ts')), { | ||
ngmodulenameFile: this.ngmodulenameFile, | ||
ngmodulename: this.ngmodulename, | ||
ngmodulenameClass: this.ngmodulenameClass | ||
} | ||
); | ||
|
||
} | ||
|
||
}); |
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,10 @@ | ||
import { NgModule } from '@angular/core'; | ||
|
||
@NgModule({ | ||
declarations: [], | ||
imports: [], | ||
providers: [], | ||
bootstrap: [], | ||
entryComponents: [] | ||
}) | ||
export class <%=ngmodulenameClass%>Module { } |
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,55 @@ | ||
'use strict'; | ||
var assert = require('yeoman-assert'); | ||
//var helpers = require('yeoman-test'); | ||
var testHelper = require('./testHelper'); | ||
//var generatorFullname = testHelper.mixins.getGeneratorFullname(); // generator-mcfly-ng2 | ||
var generatorShortname = testHelper.mixins.getGeneratorShortname(); // mcfly-ng2 | ||
|
||
describe(generatorShortname + ':module', function() { | ||
var targetname = 'dashboard'; | ||
var clientFolder = 'client'; | ||
var componentname = 'my dummy'; | ||
|
||
var config = testHelper.getYoRc({ | ||
clientFolder: clientFolder | ||
}); | ||
|
||
before(function(done) { | ||
var self = this; | ||
testHelper.runGenerator('module') | ||
.withArguments([targetname, componentname]) | ||
.inTmpDir(function(dir) { | ||
// setting up expected files | ||
testHelper.createFolderStructure(config, dir, clientFolder, targetname); | ||
}) | ||
.on('ready', function(generator) { | ||
self.generator = generator; | ||
}) | ||
.on('end', done); | ||
}); | ||
|
||
it('creates expected files', function() { | ||
var pathdir = clientFolder + '/scripts/dashboard/'; | ||
|
||
var expectedFiles = [ | ||
pathdir + 'index.ts' | ||
]; | ||
|
||
assert.file(expectedFiles); | ||
|
||
var expectedContents = [ | ||
[pathdir + 'index.ts', /export class MyDummyModule/] | ||
]; | ||
|
||
assert.fileContent(expectedContents); | ||
|
||
}); | ||
|
||
it('exposes valid client targets and client modules', function() { | ||
var configOptions = this.generator.configOptions; | ||
var clientModules = configOptions.clientModules; | ||
var clientTargets = configOptions.clientTargets; | ||
assert.objectContent(clientModules, ['app', 'common', 'dashboard', 'dummy', 'tata', 'toto']); | ||
assert.objectContent(clientTargets, ['app', 'tata', 'toto']); | ||
}); | ||
}); |