Skip to content

Commit

Permalink
Add theme folder suffix (#359)
Browse files Browse the repository at this point in the history
* Add suffix to theme folder within dest config

* Using theme folder suffix when generating project

* Fixing tests

* Setting up suffix for common templates on WP projects

* Add theme folder suffix to page generation test
  • Loading branch information
luboskmetko committed Apr 12, 2018
1 parent 02f72ad commit 0224b7b
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion generators/app/templates/package.json
Expand Up @@ -33,7 +33,7 @@
},
"dest": {<% if (projectType == 'wp-with-fe') { %>
"wordpress": "wp",
"wordpressTheme": "<%= nameSlug %>",<% } %>
"wordpressTheme": "<%= nameSlug %>-chisel",<% } %>
"assets": "assets",
"base": "dist",
"revManifest": "rev-manifest.json",
Expand Down
2 changes: 1 addition & 1 deletion generators/app/utils/generator.js
Expand Up @@ -45,7 +45,7 @@ var Generator = {
templates: function () {
var base = 'src/templates/';
if(this.prompts.projectType == 'wp-with-fe') {
base = 'wp/wp-content/themes/'+this.prompts.nameSlug+'/templates/';
base = 'wp/wp-content/themes/'+this.prompts.nameSlug+'-chisel/templates/';
}
helpers.copy.call(this, 'templates/twig/**/*', base, this.prompts);
},
Expand Down
16 changes: 9 additions & 7 deletions generators/wp/index.js
Expand Up @@ -32,6 +32,8 @@ module.exports = class extends Generator {
if(!this.options['skip-plugins']) {
this.composeWith(require.resolve('../wp-plugins'));
}

this.configuration.themeFolder = this.configuration.nameSlug + '-chisel';
}

prompting() {
Expand Down Expand Up @@ -122,7 +124,7 @@ module.exports = class extends Generator {
if (err) {
throw err;
} else {
config = config.replace('"base": "src"', '"base": "wp/wp-content/themes/'+this.configuration.nameSlug+'/src"');
config = config.replace('"base": "src"', '"base": "wp/wp-content/themes/'+this.configuration.themeFolder+'/src"');
fs.writeFile('package.json', config, (err) => {
if (err) {
throw err;
Expand All @@ -137,7 +139,7 @@ module.exports = class extends Generator {
_moveSrcFolder() {
fse.move(
this.destinationPath('src'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.nameSlug+'/src'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.themeFolder+'/src'),
function (err) {
if (err) {
return console.error(err);
Expand All @@ -151,15 +153,15 @@ module.exports = class extends Generator {
_copyTheme() {
// Copy Chisel starter theme
this.fs.copyTpl(this.templatePath('chisel-starter-theme'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.nameSlug), this.configuration);
this.destinationPath('wp/wp-content/themes/'+this.configuration.themeFolder), this.configuration);

// Copy screenshot
this.fs.copy(this.templatePath('images/screenshot.png'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.nameSlug+'/screenshot.png'));
this.destinationPath('wp/wp-content/themes/'+this.configuration.themeFolder+'/screenshot.png'));

this.fs.move(
this.destinationPath('wp/wp-content/themes/'+this.configuration.nameSlug+'/gitignore'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.nameSlug+'/.gitignore')
this.destinationPath('wp/wp-content/themes/'+this.configuration.themeFolder+'/gitignore'),
this.destinationPath('wp/wp-content/themes/'+this.configuration.themeFolder+'/.gitignore')
);
}

Expand Down Expand Up @@ -222,7 +224,7 @@ module.exports = class extends Generator {
admin_email: this.prompts.adminEmail
}], cb),
(cb) => wpCli(['plugin', 'install', 'timber-library', 'disable-emojis', {activate: true}], cb),
(cb) => wpCli(['theme', 'activate', this.configuration.nameSlug], cb)
(cb) => wpCli(['theme', 'activate', this.configuration.themeFolder], cb)
], cb);
}

Expand Down
2 changes: 1 addition & 1 deletion test/app/wordpress.test.js
Expand Up @@ -27,7 +27,7 @@ describe('Chisel Generator with WordPress', function () {
})

it('should add WP theme name to package.json', function(done) {
assert.fileContent('package.json', '"wordpressTheme": "test-project"');
assert.fileContent('package.json', '"wordpressTheme": "test-project-chisel"');

done();
})
Expand Down
4 changes: 2 additions & 2 deletions test/page/wp.test.js
Expand Up @@ -57,8 +57,8 @@ describe('Chisel Generator with WordPress (subgenerator, WP-CLI integration)', f

it('should generate Twig templates', function (done) {
assert.file([
'wp/wp-content/themes/test-project/templates/page-home.twig',
'wp/wp-content/themes/test-project/templates/page-test.twig'
'wp/wp-content/themes/test-project-chisel/templates/page-home.twig',
'wp/wp-content/themes/test-project-chisel/templates/page-test.twig'
]);

done();
Expand Down
4 changes: 2 additions & 2 deletions test/wp/defaults.test.js
Expand Up @@ -52,13 +52,13 @@ describe('Chisel Generator with WordPress (subgenerator)', function () {
})

it('should download our theme', function(done) {
assert.file('wp/wp-content/themes/test-1/index.php');
assert.file('wp/wp-content/themes/test-1-chisel/index.php');

done();
})

it('should remove .git from our theme', function(done) {
assert.noFile('wp/wp-content/themes/test-1/.git');
assert.noFile('wp/wp-content/themes/test-1-chisel/.git');

done();
})
Expand Down
4 changes: 2 additions & 2 deletions test/wp/srcinwp.test.js
Expand Up @@ -42,7 +42,7 @@ describe('Chisel Generator with WordPress (subgenerator, src inside theme)', fun
})

it('should move base src into theme directory', function(done) {
var base = 'wp/wp-content/themes/test-project-src-in-wp/src';
var base = 'wp/wp-content/themes/test-project-src-in-wp-chisel/src';
assert.file([
base,
base+'/assets/images/.keep',
Expand All @@ -56,7 +56,7 @@ describe('Chisel Generator with WordPress (subgenerator, src inside theme)', fun
})

it('should move WP-specific styles into theme directory', function(done) {
var base = 'wp/wp-content/themes/test-project-src-in-wp/src';
var base = 'wp/wp-content/themes/test-project-src-in-wp-chisel/src';
assert.file([
base+'/styles/components/_comment.scss',
base+'/styles/components/_post.scss'
Expand Down
2 changes: 1 addition & 1 deletion test/wp/wpcli.test.js
Expand Up @@ -52,7 +52,7 @@ describe('Chisel Generator with WordPress (subgenerator, WP-CLI integration)', f
});

it('should activate Theme', function(done) {
wpCli(['theme', 'status', 'test-1'], (err, stdio) => {
wpCli(['theme', 'status', 'test-1-chisel'], (err, stdio) => {
assert(stdio[STDOUT].toString('utf8').indexOf('Active') != -1);
done();
})
Expand Down

0 comments on commit 0224b7b

Please sign in to comment.