Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add grunt build and .min prefix to scripts and styles #973

Merged
merged 9 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
.idea
.DS_Store
/node_modules/
npm-debug.log
package.lock

# Grunt
/build/
/node_modules/
npm-debug.log

# Compiled files
ui/js/*.min.js
ui/css/*.min.css
153 changes: 153 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/* eslint-env node */
/* jshint node:true */

module.exports = function( grunt ) {
'use strict';

grunt.initConfig( {

pkg: grunt.file.readJSON( 'package.json' ),

// JavaScript linting with JSHint.
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'ui/js/*.js',
'!ui/js/*.min.js'
]
},

// Minify .js files.
uglify: {
options: {
preserveComments: false
},
core: {
files: [ {
expand: true,
cwd: 'ui/js/',
src: [
'*.js',
'!*.min.js'
],
dest: 'ui/js/',
ext: '.min.js'
} ]
}
},

// Minify .css files.
cssmin: {
core: {
files: [ {
expand: true,
cwd: 'ui/css/',
src: [
'*.css',
'!*.min.css'
],
dest: 'ui/css/',
ext: '.min.css'
} ]
}
},

// Build a deploy-able plugin
copy: {
build: {
src: [
'*.php',
'alerts/**',
'assets/**',
'classes/**',
'connectors/**',
'exporters/**',
'includes/**',
'ui/**',
'languages/*',
'readme.txt'
],
dest: 'build',
expand: true,
dot: true
}
},

// Clean up the build
clean: {
build: {
src: [ 'build' ]
}
},

// VVV (Varying Vagrant Vagrants) Paths
vvv: {
'plugin': '/srv/www/wordpress-develop/public_html/src/wp-content/plugins/stream',
'coverage': '/srv/www/default/coverage/stream'
},

// Shell actions
shell: {
options: {
stdout: true,
stderr: true
},
phpunit: {
command: 'vagrant ssh -c "cd <%= vvv.plugin %> && phpunit"'
},
phpunit_c: {
command: 'vagrant ssh -c "cd <%= vvv.plugin %> && phpunit --coverage-html <%= vvv.coverage %>"'
}
},

// Deploys a git Repo to the WordPress SVN repo
wp_deploy: {
deploy: {
options: {
plugin_slug: '<%= pkg.name %>',
build_dir: 'build',
assets_dir: 'wp-assets'
}
}
}
} );

// Load tasks
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.loadNpmTasks( 'grunt-contrib-cssmin' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-uglify' );
grunt.loadNpmTasks( 'grunt-shell' );
grunt.loadNpmTasks( 'grunt-wp-deploy' );

// Register tasks
grunt.registerTask( 'default', [
'jshint',
'uglify',
'cssmin'
] );

grunt.registerTask( 'phpunit', [
'shell:phpunit'
] );

grunt.registerTask( 'phpunit_c', [
'shell:phpunit_c'
] );

grunt.registerTask( 'build', [
'default',
'copy'
] );

grunt.registerTask( 'deploy', [
'build',
'wp_deploy',
'clean'
] );

};
14 changes: 14 additions & 0 deletions alerts/class-alert-trigger-action.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,30 @@ class Alert_Trigger_Action extends Alert_Trigger {
* Checks if a record matches the criteria from the trigger.
*
* @see Alert_Trigger::check_record().
*
* @param bool $success Status of previous checks.
* @param int $record_id Record ID.
* @param array $recordarr Record data.
* @param Alert $alert The Alert being worked on.
*
* @return bool False on failure, otherwise should return original value of $success.
*/
public function check_record( $success, $record_id, $recordarr, $alert ) {
if ( ! empty( $alert->alert_meta['trigger_action'] ) && $recordarr['action'] !== $alert->alert_meta['trigger_action'] ) {
return false;
}

return $success;
}

/**
* Adds fields to the trigger form.
*
* @see Alert_Trigger::add_fields().
*
* @param Form_Generator $form The Form Object to add to.
* @param Alert $alert The Alert being worked on.
*
* @return void
*/
public function add_fields( $form, $alert = array() ) {
Expand All @@ -82,7 +87,9 @@ public function add_fields( $form, $alert = array() ) {
* Validate and save Alert object
*
* @see Alert_Trigger::save_fields().
*
* @param Alert $alert The Alert being worked on.
*
* @return void
*/
public function save_fields( $alert ) {
Expand All @@ -98,6 +105,7 @@ public function save_fields( $alert ) {
* Generate array of possible action values
*
* @param bool $flat If the array should be multidimensional.
*
* @return array
*/
public function get_values( $flat = false ) {
Expand All @@ -112,14 +120,17 @@ public function get_values( $flat = false ) {
$action_values[ $action_id ] = $action_data;
}
}

return $action_values;
}

/**
* Function will return all terms labels of given column
*
* @todo refactor Settings::get_terms_labels into general utility
*
* @param string $column string Name of the column.
*
* @return array
*/
public function get_terms_labels( $column ) {
Expand All @@ -144,15 +155,18 @@ public function get_terms_labels( $column ) {

ksort( $return_labels );
}

return $return_labels;
}

/**
* Returns the trigger's value for the given alert.
*
* @see Alert_Trigger::get_display_value().
*
* @param string $context The location this data will be displayed in.
* @param Alert $alert Alert being processed.
*
* @return string
*/
public function get_display_value( $context = 'normal', $alert ) {
Expand Down
19 changes: 16 additions & 3 deletions alerts/class-alert-trigger-author.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @package WP_Stream
*/

namespace WP_Stream;

/**
Expand Down Expand Up @@ -31,25 +32,30 @@ class Alert_Trigger_Author extends Alert_Trigger {
* Checks if a record matches the criteria from the trigger.
*
* @see Alert_Trigger::check_record().
*
* @param bool $success Status of previous checks.
* @param int $record_id Record ID.
* @param array $recordarr Record data.
* @param Alert $alert The Alert being worked on.
*
* @return bool False on failure, otherwise should return original value of $success.
*/
public function check_record( $success, $record_id, $recordarr, $alert ) {
if ( ! empty( $alert->alert_meta['trigger_author'] ) && intval( $alert->alert_meta['trigger_author'] ) !== intval( $recordarr['user_id'] ) ) {
return false;
}

return $success;
}

/**
* Adds fields to the trigger form.
*
* @see Alert_Trigger::add_fields().
*
* @param Form_Generator $form The Form Object to add to.
* @param Alert $alert The Alert being worked on.
*
* @return void
*/
public function add_fields( $form, $alert = array() ) {
Expand Down Expand Up @@ -86,7 +92,7 @@ public function get_values() {
}

$users = array_map(
function( $user_id ) {
function ( $user_id ) {
return new Author( $user_id );
},
get_users(
Expand All @@ -98,13 +104,14 @@ function( $user_id ) {

if ( is_multisite() && is_super_admin() ) {
$super_admins = array_map(
function( $login ) {
function ( $login ) {
$user = get_user_by( 'login', $login );

return new Author( $user->ID );
},
get_super_admins()
);
$users = array_unique( array_merge( $users, $super_admins ) );
$users = array_unique( array_merge( $users, $super_admins ) );
}

$user_meta = array(
Expand All @@ -119,14 +126,17 @@ function( $login ) {
'text' => $user->get_display_name(),
);
}

return $all_records;
}

/**
* Validate and save Alert object
*
* @see Alert_Trigger::save_fields().
*
* @param Alert $alert The Alert being worked on.
*
* @return void
*/
public function save_fields( $alert ) {
Expand All @@ -142,8 +152,10 @@ public function save_fields( $alert ) {
* Returns the trigger's value for the given alert.
*
* @see Alert_Trigger::get_display_value().
*
* @param string $context The location this data will be displayed in.
* @param Alert $alert Alert being processed.
*
* @return string
*/
public function get_display_value( $context = 'normal', $alert ) {
Expand All @@ -158,6 +170,7 @@ public function get_display_value( $context = 'normal', $alert ) {
$author = __( 'Unknown User', 'stream' );
}
}

return ucfirst( $author );
}
}
Loading