Skip to content

Commit 420c863

Browse files
committed
move button code to scripts folder and fix release build of button script
1 parent 9449a66 commit 420c863

File tree

10 files changed

+40
-23
lines changed

10 files changed

+40
-23
lines changed

generators/app/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ module.exports = yeoman.Base.extend({
185185
this.destinationPath('gulpfile.babel.js'), {
186186
date: new Date().toISOString().split('T')[0],
187187
name: this.pkg.name,
188-
version: this.pkg.version
188+
version: this.pkg.version,
189+
isButton: this.props.isButton,
189190
}
190191
);
191192
},
@@ -264,8 +265,8 @@ module.exports = yeoman.Base.extend({
264265
scripts: function () {
265266
if (this.props.isButton) {
266267
this.fs.copyTpl(
267-
this.templatePath('app/button.js'),
268-
this.destinationPath('app/' + this.props.camelName + '.js'), {
268+
this.templatePath('app/scripts/button.js'),
269+
this.destinationPath('app/scripts/' + this.props.camelName + '.js'), {
269270
root: this.props.camelName
270271
}
271272
);

generators/app/templates/_package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"quotes": [
4848
2,
4949
"single"
50-
]
50+
],
51+
"no-alert": false
5152
},
5253
"globals": {
5354
"geotab": true,

generators/app/templates/app/addin.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<script src="scripts/main.js"></script>
2828
<!-- endbuild -->
2929
<% } else { %>
30-
<script src="<%= root %>.js"></script>
30+
<script src="{click}"></script>
3131
<% } %>
3232
</head>
3333

generators/app/templates/app/button.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

generators/app/templates/app/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"items": [{
66
<% if (isButton) { %>
77
"page": "<%= page %>",
8-
"click": "<%= url %>",
8+
"click": "scripts/<%= url %>",
99
"buttonName": {
1010
"en": "<%= menuName %>"
1111
},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* The function is called whenever the Add-In button is clicked.
3+
*
4+
* @param {object} event - The event dispatched from the button click.
5+
* @param {object} api - The GeotabApi object for making calls to MyGeotab.
6+
* @param {object} state - The page state object allows access to URL, page navigation and global group filter.
7+
*/
8+
geotab.customButtons.<%= root %> = (event, api, state) => {
9+
'use strict';
10+
11+
event.preventDefault();
12+
13+
state.setState({
14+
hello: 'world'
15+
});
16+
17+
// getting the current user to display in the UI
18+
api.getSession(session => {
19+
alert(`Hello ${session.userName}`);
20+
});
21+
};

generators/app/templates/gulpfile.babel.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,15 @@ gulp.task('json', () => {
8585

8686
gulp.task('html', ['styles', 'scripts'], () => {
8787
var options = JSON.parse(fs.readFileSync('./app/config.json')).dev;
88+
<% if (isButton) { %>
89+
return gulp.src(['.tmp/**/*'])
90+
<% } else { %>
8891
return gulp.src('app/*.html')
8992
.pipe($.useref({
9093
searchPath: ['.tmp', 'app', '.']
9194
}))
92-
.pipe($.if('*.js', $.uglify()))
95+
<% } %>
96+
.pipe($.if('*.js', $.uglify()))
9397
.pipe($.if('*.css', $.cssSandbox('#' + options.root)))
9498
.pipe($.if('*.css', $.cssnano()))
9599
// convert relative urls to absolute
@@ -153,7 +157,9 @@ let mockAddinHost = sourceDir => {
153157

154158
if (parsed.pathname === '/' || parsed.pathname.indexOf(config.dev.root + '.html') > -1) {
155159
if (isButton) {
156-
htmlSource = fs.readFileSync('.dev/button.html', 'utf8').replace('{icon}', `style="background-image: url(${config.items[0].icon})"` || '');
160+
htmlSource = fs.readFileSync('.dev/button.html', 'utf8')
161+
.replace('{click}', config.items[0].click || '')
162+
.replace('{icon}', `style="background-image: url(${config.items[0].icon})"` || '');
157163
} else {
158164
htmlSource = fs.readFileSync(parsed.pathname === '/' ? `${sourceDir}/${config.dev.root}.html` : parsed.pathname, 'utf8');
159165
}

test/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('generator-addin:button', function () {
5050
it('creates files for add-in button', function () {
5151
assert.file(commonFiles.concat([
5252
'.dev/button.html',
53-
'app/myAddin.js'
53+
'app/scripts/myAddin.js'
5454
]));
5555
});
5656
});

test/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('generator-addin:button config.json', function () {
7373
assert.equal(config.supportEmail, props.supportEmail);
7474
});
7575
it('has correct click', function () {
76-
assert.equal(config.items[0].click, 'myAddin.js');
76+
assert.equal(config.items[0].click, 'scripts/myAddin.js');
7777
});
7878
it('has correct button name', function () {
7979
assert.equal(config.items[0].buttonName.en, props.menuName);

test/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('generator-addin:button myAddin.js', function () {
3737
helpers.run(path.join(__dirname, '../generators/app'))
3838
.withPrompts(props)
3939
.on('end', function () {
40-
js = fs.readFileSync('app/myAddin.js', 'utf8');
40+
js = fs.readFileSync('app/scripts/myAddin.js', 'utf8');
4141
done();
4242
});
4343
});

0 commit comments

Comments
 (0)