Skip to content

Commit 742b8e9

Browse files
committed
updated the state task
1 parent d042751 commit 742b8e9

File tree

8 files changed

+204
-13
lines changed

8 files changed

+204
-13
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function test(cb) {
4444

4545
gulp
4646
.src(srcGlob)
47-
.pipe(debug())
47+
//.pipe(debug())
4848
.pipe(istanbul(istanbulOpts))
4949
.pipe(istanbul.hookRequire())
5050
.on('finish', runner)

slush/casing.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,24 @@ function Casing() {
2828

2929
function varCase(str) {
3030
var stringList = str.split('.');
31+
3132
var newString = _.map(stringList, caseIt);
32-
newString = newString.join('')
33+
34+
newString = newString
35+
.join('')
3336
.split('-');
37+
3438
newString = _.map(newString, caseIt);
35-
return newString.join('')
39+
40+
newString = newString
41+
.join('')
3642
.replace(/^(.)/, function($1) {
3743
return $1.toLowerCase();
3844
});
45+
46+
newString = camelCase(newString);
47+
48+
return newString;
3949
}
4050

4151
function kebabCase(str) {

slush/default/task.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ function DefaultTask(options) {
3333
gulp
3434
.src(options.templatesDir + '/default/**')
3535
.pipe(template(answers))
36-
//.pipe(debug())
3736
.pipe(rename(renameFiles))
3837
//.pipe(conflict('./'))
3938
.pipe(gulp.dest('./'))

slush/state/task.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,35 @@ var gulp = require('gulp'),
77
rename = require('gulp-rename'),
88
inquirer = require('inquirer');
99

10+
var debug = require('gulp-debug')
11+
1012
var transformDefault = require('./transforms');
1113
var defaultQuestions = require('./questions');
1214

1315
function StateTask(options) {
1416
function defaultTask(cb) {
1517

1618
function scaffold(answers) {
17-
19+
1820
var answers = transformDefault.map(answers);
1921

2022
if (!answers.moveon) {
2123
return cb();
2224
}
23-
24-
var outputDir = './src/states/' + answers.kebabStateName;
25-
26-
gulp.src(options.templatesDir + '/state/**')
25+
26+
function toStateName() {}
27+
28+
var outputDir = './src/states/';
29+
30+
gulp
31+
.src(options.templatesDir + '/state/state.js')
32+
.pipe(rename({
33+
basename: answers.kebabStateName
34+
}))
35+
.pipe(debug())
2736
.pipe(template(answers))
37+
38+
2839
.pipe(gulp.dest(outputDir))
2940
.on('finish', cb);
3041
}

test/casing.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ describe('casing-utilities', function () {
1010

1111
it('should camel case a string', function () {
1212

13-
var input = 'I am a string',
14-
output = 'iAmAString',
13+
var input = 'I.am a.string-woot',
14+
output = 'i.amA.string-woot',
1515
operation = 'camel';
1616

1717
expect(casing[operation](input))
@@ -47,6 +47,65 @@ describe('casing-utilities', function () {
4747
});
4848
});
4949

50+
describe('var', function () {
51+
it('should var case a string', function () {
52+
53+
var input = 'I.am a.string',
54+
output = 'iAmAString',
55+
operation = 'var';
56+
57+
expect(casing[operation](input))
58+
.to
59+
.eql(output);
60+
});
61+
});
62+
describe('varName', function () {
63+
it('should folder case a string', function () {
64+
65+
var input = 'I.am a.string',
66+
output = 'string',
67+
operation = 'varName';
68+
69+
expect(casing[operation](input))
70+
.to
71+
.eql(output);
72+
});
73+
});
74+
describe('classify', function () {
75+
it('should folder case a string', function () {
76+
77+
var input = 'I.am a.string',
78+
output = 'i-am-a-string',
79+
operation = 'classify';
5080

81+
expect(casing[operation](input))
82+
.to
83+
.eql(output);
84+
});
85+
});
86+
describe('folderName', function () {
87+
it('should folder case a string', function () {
88+
89+
var input = 'I.am a.string',
90+
output = 'string',
91+
operation = 'folderName';
92+
93+
expect(casing[operation](input))
94+
.to
95+
.eql(output);
96+
});
97+
});
98+
describe('snake', function () {
99+
it('should folder case a string', function () {
100+
101+
var input = 'I.am a.string',
102+
output = 'i_am_a_string',
103+
operation = 'snake';
104+
105+
expect(casing[operation](input))
106+
.to
107+
.eql(output);
108+
});
109+
});
51110

52111
});

test/default/task.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
'use strict';
22
var chai = require('chai'),
33
gulp = require('gulp'),
4-
mockGulpDest = require('mock-gulp-dest')(gulp),
54
expect = chai.expect;
65

76

87
var mockPrompt = require('./../inquirer-prompt-fixture'),
98
slushfile = require('./../../slushfile');
109

1110
describe('slush-phaser-webpack', function () {
12-
11+
12+
var mockGulpDest;
13+
14+
beforeEach(function(){
15+
mockGulpDest = require('mock-gulp-dest')(gulp);
16+
});
17+
1318
describe('default-task', function () {
1419

1520
beforeEach(function () {
@@ -47,5 +52,49 @@ describe('slush-phaser-webpack', function () {
4752
.once('task_stop', assertDirectories);
4853
});
4954

55+
it('should make a server', function (done) {
56+
57+
function assertDirectories() {
58+
mockGulpDest.assertDestContains('server.js');
59+
done();
60+
}
61+
62+
gulp
63+
.start('default')
64+
.once('task_stop', assertDirectories);
65+
});
66+
67+
68+
it('should scaffold the right src folder structure', function (done) {
69+
70+
function assertDirectories() {
71+
mockGulpDest.assertDestContains({
72+
src: {
73+
assets: {
74+
fontmaps: [],
75+
spritesheets: [],
76+
tilemaps: [],
77+
tilesets: []
78+
},
79+
scenes: [],
80+
shaders: [],
81+
states: ['boot.js'],
82+
_: [
83+
'game.js',
84+
'index.html',
85+
'index.js',
86+
'states.js'
87+
]
88+
}
89+
});
90+
done();
91+
}
92+
93+
gulp
94+
.start('default')
95+
.once('task_stop', assertDirectories);
96+
});
97+
98+
5099
});
51100
});

test/state/task.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
1+
'use strict';
2+
var chai = require('chai'),
3+
gulp = require('gulp'),
4+
expect = chai.expect;
15

26

7+
var mockPrompt = require('./../inquirer-prompt-fixture'),
8+
slushfile = require('./../../slushfile');
9+
10+
describe('slush-phaser-webpack', function () {
11+
12+
var mockGulpDest;
13+
14+
beforeEach(function () {
15+
mockGulpDest = require('mock-gulp-dest')(gulp);
16+
});
17+
18+
describe('default-task', function () {
19+
20+
it('should make a readme', function (done) {
21+
22+
mockPrompt({
23+
stateName: 'Test State',
24+
moveon: true
25+
});
26+
27+
function assertDirectories() {
28+
mockGulpDest.assertDestContains('test-state.js');
29+
done();
30+
}
31+
32+
gulp
33+
.start('state')
34+
.once('task_stop', assertDirectories);
35+
});
36+
37+
});
38+
});

test/state/transforms.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,30 @@ var chai = require('chai'),
55

66

77
var defaultTransforms = require('./../../slush/state/transforms');
8+
9+
10+
11+
describe('state-transform', function () {
12+
var mockAnswers;
13+
14+
beforeEach(function () {
15+
mockAnswers = {
16+
stateName: 'Test State',
17+
moveon: true
18+
};
19+
});
20+
21+
it('should return a transformed answer set for templating', function () {
22+
23+
var transformedAnswers = defaultTransforms.map(mockAnswers);
24+
25+
expect(transformedAnswers).to.eql({
26+
stateName: 'Test State',
27+
kebabStateName : 'test-state',
28+
varStateName : 'testState',
29+
moveon: true
30+
});
31+
32+
});
33+
34+
});

0 commit comments

Comments
 (0)