Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Reintroduce WPCS without Travis #1131

Merged
merged 8 commits into from
Oct 15, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ config.yml
*.log
.idea/
*.swp
packaged/
wpcs/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ When building for production, the CSS and JS will be minified. To minify the ass
$ npm run build
```

#### To create a .zip file of your theme, run:

```
$ npm run package
```

Running this command will build and minify the theme's assets and place a .zip archive of the theme in the `packaged` directory. This excludes the developer files/directories from your theme like `/node_modules`, `/src`, etc. to keep the theme lightweight for transferring the theme to a staging or production server.

### Project structure

In the `/src` folder you will the working files for all your assets. Every time you make a change to a file that is watched by Gulp, the output will be saved to the `/dist` folder. The contents of this folder is the compiled code that you should not touch (unless you have a good reason for it).
Expand Down
47 changes: 47 additions & 0 deletions codesniffer.ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0"?>
<ruleset name="WordPress Theme Coding Standards">
<!-- See https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<!-- See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Core/ruleset.xml -->

<!-- Set a description for this ruleset. -->
<description>A custom set of code standard rules to check for WordPress themes.</description>

<!-- Include the WordPress ruleset, with exclusions. -->
<rule ref="WordPress">
<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
<exclude name="Generic.Files.EndFileNewline.NotFound" />
<exclude name="Generic.Strings.UnnecessaryStringConcat.Found" />
<exclude name="Generic.Formatting.DisallowMultipleStatements.SameLine" />
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace" />
<exclude name="PEAR.Functions.FunctionCallSignature.Indent" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket" />
<exclude name="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket" />

<exclude name="Squiz.Commenting.FileComment.WrongStyle" />
<exclude name="Squiz.Commenting.BlockComment.NoEmptyLineBefore" />
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag" />
<exclude name="Squiz.Commenting.InlineComment.NotCapital" />
<exclude name="Squiz.Commenting.InlineComment.SpacingAfter" />
<exclude name="Squiz.Commenting.VariableComment.WrongStyle" />
<exclude name="Squiz.Commenting.FunctionComment.Missing" />
<exclude name="Squiz.Commenting.FunctionComment.WrongStyle" />
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
<exclude name="Squiz.Commenting.ClassComment.Missing" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpenHint" />

<exclude name="WordPress.XSS.EscapeOutput.UnsafePrintingFunction" />
<exclude name="WordPress.XSS.EscapeOutput.OutputNotEscaped" />
<exclude name="WordPress.Arrays.ArrayDeclaration.NoSpaceAfterOpenParenthesis" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceAfterArrayOpener" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceBeforeArrayCloser" />

<exclude name="WordPress.Variables.GlobalVariables" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceAfterOpenParenthesis" />
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing.NoSpaceBeforeCloseParenthesis)" />

<exclude name="WordPress.VIP.RestrictedFunctions" />
</rule>
</ruleset>
26 changes: 23 additions & 3 deletions config-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ COMPATIBILITY:
- "last 2 versions"
- "ie >= 9"
- "ios >= 7"

# Set to true if you want static asset revisioning, helpful for cache busting
REVISIONING: false

# Gulp will reference these paths when it copies files
PATHS:
Expand All @@ -24,6 +27,23 @@ PATHS:
# Paths to JavaScript entry points for webpack to bundle modules
entries:
- "src/assets/js/app.js"

# Set to true if you want static asset revisioning, helpful for cache busting
REVISIONING: false
# Paths for the package task to include/exclude in .zip archive
package:
- "**/*"
- "!**/node_modules/**"
- "!**/packaged/**"
- "!**/src/**"
- "!**/codesniffer.ruleset.xml"
- "!**/composer.json"
- "!**/composer.lock"
- "!**/config.yml"
- "!**/config.default.yml"
- "!**/gulpfile.babel.js"
- "!**/package.json"
- "!**/package-lock.json"
- "!**/webpack.config.js"
# Paths for PHP CodeSniffer
phpcs:
- "**/*.php"
- "!wpcs"
- "!wpcs/**"
39 changes: 39 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import gulp from 'gulp';
import rimraf from 'rimraf';
import yaml from 'js-yaml';
import fs from 'fs';
import dateFormat from 'dateformat';
import webpackStream from 'webpack-stream';
import webpack2 from 'webpack';
import named from 'vinyl-named';
Expand Down Expand Up @@ -67,6 +68,10 @@ gulp.task('build',
gulp.task('default',
gulp.series('build', server, watch));

// Package task
gulp.task('package',
gulp.series('build', archive));

// Delete the "dist" folder
// This happens every time a build starts
function clean(done) {
Expand Down Expand Up @@ -146,6 +151,40 @@ function images() {
.pipe(gulp.dest(PATHS.dist + '/assets/img'));
}

// Create a .zip archive of the theme
function archive() {
var time = dateFormat(new Date(), "yyyy-mm-dd_HH-MM");
var pkg = JSON.parse(fs.readFileSync('./package.json'));
var title = pkg.name + '_' + time + '.zip';

return gulp.src(PATHS.package)
.pipe($.zip(title))
.pipe(gulp.dest('packaged'));
}

// PHP Code Sniffer task
gulp.task('phpcs', function() {
return gulp.src(PATHS.phpcs)
.pipe($.phpcs({
bin: 'wpcs/vendor/bin/phpcs',
standard: './codesniffer.ruleset.xml',
showSniffCode: true,
}))
.pipe($.phpcs.reporter('log'));
});

// PHP Code Beautifier task
gulp.task('phpcbf', function () {
return gulp.src(PATHS.phpcs)
.pipe($.phpcbf({
bin: 'wpcs/vendor/bin/phpcbf',
standard: './codesniffer.ruleset.xml',
warningSeverity: 0
}))
.on('error', $.util.log)
.pipe(gulp.dest('.'));
});

// Start BrowserSync to preview the site in
function server(done) {
browser.init({
Expand Down
Loading