Skip to content
This repository has been archived by the owner on May 23, 2022. It is now read-only.

Yeoman generator 1.0 #80

Merged
merged 5 commits into from
Jan 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ node_js:
- 'v6'
- 'v5'
- 'v4'
- '0.12'
38 changes: 25 additions & 13 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
'use strict';
var path = require('path');
var Base = require('yeoman-generator').Base;
var yosay = require('yosay');
var chalk = require('chalk');
var isWin = process.platform === 'win32';
var homedir = (isWin) ? process.env.HOMEPATH : process.env.HOME;
var fs = require('fs');
var mkdirp = require('mkdirp');
const path = require('path');
const Generator = require('yeoman-generator');
const yosay = require('yosay');
const chalk = require('chalk');
const isWin = process.platform === 'win32';
const homedir = (isWin) ? process.env.HOMEPATH : process.env.HOME;
const fs = require('fs');
const mkdirp = require('mkdirp');
const GruntfileEditor = require('gruntfile-editor');

function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}

module.exports = Base.extend({
module.exports = Generator.extend({
initializing: function() {
this.gruntfile = new GruntfileEditor();
// check for existence of package.json
try {
fs.accessSync('./package.json', fs.F_OK);
Expand Down Expand Up @@ -150,7 +152,7 @@ module.exports = Base.extend({
}
}];

this.prompt(prompts, function(props) {
this.prompt(prompts).then(function(props) {
this.abort = props.abort;
this.wabRoot = props.wabRoot;
this.widgetsType = props.widgetsType;
Expand Down Expand Up @@ -290,9 +292,19 @@ module.exports = Base.extend({
if (this.abort) {
return;
}
this.copy('editorconfig', '.editorconfig');
this.copy('jshintrc', '.jshintrc');
this.copy('babelrc', '.babelrc');
this.fs.copyTpl(
this.templatePath('editorconfig'),
this.destinationPath('.editorconfig')
);
this.fs.copyTpl(
this.templatePath('jshintrc'),
this.destinationPath('.jshintrc')
);
this.fs.copyTpl(
this.templatePath('babelrc'),
this.destinationPath('.babelrc')
);
fs.writeFileSync('Gruntfile.js', this.gruntfile.toString());
}
},

Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://github.com/tomwayson"
},
"engines": {
"node": ">=0.12.0"
"node": ">=4.0.0"
},
"scripts": {
"test": "mocha --timeout 10000"
Expand All @@ -28,15 +28,16 @@
"AppBuilder"
],
"dependencies": {
"chalk": "^1.0.0",
"underscore.string": "^3.2.3",
"chalk": "^1.1.3",
"gruntfile-editor": "^1.2.1",
"mkdirp": "^0.5.1",
"yeoman-generator": "^0.22.5",
"yosay": "^1.0.2"
"underscore.string": "^3.2.3",
"yeoman-generator": "^1.0.1",
"yosay": "^1.2.1"
},
"devDependencies": {
"mocha": "*",
"yeoman-assert": "^2.0.0",
"yeoman-test": "^1.0.0"
"yeoman-assert": "^2.2.2",
"yeoman-test": "^1.6.0"
}
}
86 changes: 64 additions & 22 deletions widget/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';
var path = require('path');
var Base = require('yeoman-generator').Base;
var chalk = require('chalk');
var dasherize = require('underscore.string/dasherize');
var utils = require('./utils');
const path = require('path');
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const dasherize = require('underscore.string/dasherize');
const utils = require('./utils');

var WidgetGenerator = Base.extend({
askFor: function () {
module.exports = Generator.extend({
prompting: function () {
var done = this.async();

console.log(chalk.green('Welcome to the ArcGIS Web AppBuilder widget generator!'));
Expand Down Expand Up @@ -122,7 +122,7 @@ var WidgetGenerator = Base.extend({
choices: ['ES5', 'ES2015']
}];

this.prompt(prompts, function (props) {
this.prompt(prompts).then(function (props) {
this.widgetName = props.widgetName;
this.widgetTitle = props.widgetTitle;
this.description = props.description;
Expand Down Expand Up @@ -160,38 +160,80 @@ var WidgetGenerator = Base.extend({
}.bind(this));
},

files: function () {
writing: function () {
var basePath = path.join('widgets', this.widgetName);
this.template('_Widget_' + this.jsVersion + '.js', path.join(basePath, 'Widget.js'));
this.fs.copyTpl(
this.templatePath('_Widget_' + this.jsVersion + '.js'),
this.destinationPath(path.join(basePath, 'Widget.js')),
this
);
if (this.hasUIFile) {
this.template('_Widget.html', path.join(basePath, 'Widget.html'));
this.fs.copyTpl(
this.templatePath('_Widget.html'),
this.destinationPath(path.join(basePath, 'Widget.html')),
this
);
}
if (this.hasConfig) {
this.template('_config.json', path.join(basePath, 'config.json'));
this.fs.copyTpl(
this.templatePath('_config.json'),
this.destinationPath(path.join(basePath, 'config.json')),
this
);
}
if (this.hasStyle) {
this.template('css/_style.css', path.join(basePath, 'css/style.css'));
this.fs.copyTpl(
this.templatePath('css/_style.css'),
this.destinationPath(path.join(basePath, 'css/style.css')),
this
);
}
if (this.hasLocale) {
this.template('nls/_strings.js', path.join(basePath, 'nls/strings.js'));
this.fs.copyTpl(
this.templatePath('nls/_strings.js'),
this.destinationPath(path.join(basePath, 'nls/strings.js')),
this
);
}
this.copy('images/icon.png', path.join(basePath, 'images/icon.png'));
this.template('_manifest.json', path.join(basePath, 'manifest.json'));
this.fs.copy(
this.templatePath('images/icon.png'),
this.destinationPath(path.join(basePath, 'images/icon.png'))
);

this.fs.copyTpl(
this.templatePath('_manifest.json'),
this.destinationPath(path.join(basePath, 'manifest.json')),
this
);

// Settings:
if(this.hasSettingPage) {
this.template('setting/_Setting_' + this.jsVersion + '.js', path.join(basePath, 'setting/Setting.js'));
this.fs.copyTpl(
this.templatePath('setting/_Setting_' + this.jsVersion + '.js'),
this.destinationPath(path.join(basePath, 'setting/Setting.js')),
this
);
if (this.hasSettingUIFile) {
this.template('setting/_Setting.html', path.join(basePath, 'setting/Setting.html'));
this.fs.copyTpl(
this.templatePath('setting/_Setting.html'),
this.destinationPath(path.join(basePath, 'setting/Setting.html')),
this
);
}
if (this.hasSettingLocale) {
this.template('setting/nls/_strings.js', path.join(basePath, 'setting/nls/strings.js'));
this.fs.copyTpl(
this.templatePath('setting/nls/_strings.js'),
this.destinationPath(path.join(basePath, 'setting/nls/strings.js')),
this
);
}
if (this.hasSettingStyle) {
this.template('setting/css/_style.css', path.join(basePath, 'setting/css/style.css'));
this.fs.copyTpl(
this.templatePath('setting/css/_style.css'),
this.destinationPath(path.join(basePath, 'setting/css/style.css')),
this
);
}
}
}
});

module.exports = WidgetGenerator;
Loading