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

enhance: revamp transaction summary #1485

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
154 changes: 33 additions & 121 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
module.exports = function(grunt) {
var formBuilderAssets = require('./admin/form-builder/assets/js/form-builder-assets.js');

var pkg = grunt.file.readJSON('package.json');

grunt.initConfig({
Expand All @@ -16,14 +15,11 @@ module.exports = function(grunt) {

// Compile all .less files.
less: {

// one to one
front: {
files: {
'<%= dirs.css %>/frontend-forms.css': '<%= dirs.less %>/frontend-forms.less'
}
},

admin: {
files: {
'<%= dirs.css %>/wpuf-form-builder.css': ['admin/form-builder/assets/less/form-builder.less'],
Expand Down Expand Up @@ -84,11 +80,14 @@ module.exports = function(grunt) {
},

watch: {
options: {
debounceDelay: 500, // Add debounce delay
spawn: false // Recommended for better performance
},
Comment on lines +83 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

'debounceDelay' is deprecated in 'grunt-contrib-watch' v^1.0.0

  • Replace the debounceDelay option with awaitWriteFinish for better compatibility and performance.
🔗 Analysis chain

Ensure 'debounceDelay' is compatible with your Grunt version

The debounceDelay option might be deprecated in newer versions of grunt-contrib-watch. Consider verifying if debounceDelay is still supported or if you should use awaitWriteFinish or adjust the interval option instead.

You can check the Grunt documentation or run the following script to confirm if debounceDelay is supported:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if 'debounceDelay' is a valid option in 'grunt-contrib-watch'

# Test: Check the installed version of 'grunt-contrib-watch'
grep '"grunt-contrib-watch"' package.json

# Expected: Confirm the version number to see if 'debounceDelay' is supported

Length of output: 210


Script:

#!/bin/bash
# Description: Extract the version number of 'grunt-contrib-watch' from package.json

# Extract the version using grep and regex
grep '"grunt-contrib-watch"' package.json | grep -oP '(?<="grunt-contrib-watch": ")[^"]+'

Length of output: 98

Comment on lines +83 to +86
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Caution: 'spawn: false' may cause issues if tasks modify watched files

Setting spawn: false can improve performance by running tasks in the same process. However, if the tasks being run modify any of the files that are being watched, it can lead to an infinite loop. Ensure that the tasks executed do not alter the watched files to prevent this issue.

less: {
files: ['<%= dirs.less %>/*.less'],
tasks: ['less:front', 'less:admin']
},

formBuilder: {
files: [
'admin/form-builder/assets/less/*',
Expand All @@ -101,126 +100,30 @@ module.exports = function(grunt) {
'concat:formBuilder', 'concat:templates', 'less:front'
]
},

vue: {
files: [
'assets/js/subscriptions.js',
'assets/css/admin/subscriptions.css',
'assets/js/components/**/*.vue',
'assets/js/stores/**/*.js',
],
tasks: [
'shell:npm_build'
]
}
},

// Clean up build directory
clean: {
main: ['build/']
},

// Copy the plugin into the build directory
copy: {
main: {
src: [
'**',
'!node_modules/**',
'!build/**',
'!admin/form-builder/assets/**',
'!assets/css/*.less',
'!bin/**',
'!.git/**',
'!includes/pro/.git/**',
'!Gruntfile.js',
'!secret.json',
'!package.json',
'!debug.log',
'!phpunit.xml',
'!.gitignore',
'!.gitmodules',
'!npm-debug.log',
'!plugin-deploy.sh',
'!export.sh',
'!config.codekit',
'!**/nbproject/**',
'!assets/less/**',
'!assets/tailwind/**',
'!tests/**',
'!**/Gruntfile.js',
'!**/package.json',
'!**/readme.md',
'!**/docs.md',
'!**/*~',
'!**/log.txt',
'!**/package-lock.json',
'!**/appsero.json',
'!**/composer.json',
'!**/composer.lock',
'!**/phpcs-report.txt',
'!**/phpcs.xml.dist'
'assets/js/**/*.{js,vue}',
'src/js/**/*.{js,vue}',
'!assets/js/**/*.min.js', // Exclude minified files
'!src/js/**/*.min.js' // Exclude minified files
],
dest: 'build/'
}
},

//Compress build directory into <name>.zip and <name>-<version>.zip
compress: {
main: {
options: {
mode: 'zip',
archive: './build/wp-user-frontend-v'+pkg.version+'.zip'
},
expand: true,
cwd: 'build/',
src: ['**/*'],
dest: 'wp-user-frontend'
}
},

// jshint
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},

formBuilder: [
'admin/form-builder/assets/js/**/*.js',
'!admin/form-builder/assets/js/jquery-siaf-start.js',
'!admin/form-builder/assets/js/jquery-siaf-end.js',
'assets/js/wpuf-form-builder-wpuf-forms.js',
]
},

// concat/join files
concat: {
formBuilder: {
files: {
'<%= dirs.js %>/wpuf-form-builder.js': 'admin/form-builder/assets/js/form-builder.js',
'<%= dirs.js %>/wpuf-form-builder-mixins.js': formBuilderAssets.mixins,
'<%= dirs.js %>/wpuf-form-builder-components.js': formBuilderAssets.components,
},
},

templates: {
tasks: ['shell:npm_build'],
options: {
process: function(src, filepath) {
var id = filepath.replace('/template.php', '').split('/').pop();

return '<script type="text/x-template" id="tmpl-wpuf-' + id + '">\n' + src + '</script>\n';
}
},
files: {
'<%= dirs.template %>/form-components.php': formBuilderAssets.componentTemplates,
debounceDelay: 1000, // Longer delay for Vue files
spawn: false,
interval: 1000 // Add interval
}
}
},

// is to run NPM commands through Grunt
// Shell command for npm build
shell: {
npm_build: {
command: 'npm run build',
options: {
stdout: true,
stderr: true
}
}
}
});
Expand All @@ -239,13 +142,22 @@ module.exports = function(grunt) {
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.loadNpmTasks( 'grunt-shell' );

grunt.registerTask( 'default', [ 'less', 'concat', 'uglify', 'i18n' ] );
// Task optimization
let changedFiles = Object.create(null);
let onChange = grunt.util._.debounce(function() {
grunt.config('shell.npm_build.src', Object.keys(changedFiles));
changedFiles = Object.create(null);
}, 200);
Comment on lines +145 to +150
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential issue with 'shell.npm_build.src' configuration

In the onChange function, you're setting grunt.config('shell.npm_build.src', Object.keys(changedFiles));. However, the shell task does not use a src property. This may not have the intended effect of passing changed files to the shell command.

Consider modifying the shell command to accept the changed files if needed. For example:

 onChange = grunt.util._.debounce(function() {
-    grunt.config('shell.npm_build.src', Object.keys(changedFiles));
+    let files = Object.keys(changedFiles).join(' ');
+    grunt.config('shell.npm_build.command', `npm run build -- ${files}`);
     changedFiles = Object.create(null);
 }, 200);

Additionally, ensure that your npm run build script can handle file arguments appropriately.

Committable suggestion was skipped due to low confidence.


// file auto generation
grunt.registerTask( 'i18n', [ 'makepot' ] );
grunt.registerTask( 'readme', [ 'wp_readme_to_markdown' ] );
grunt.event.on('watch', function(action, filepath) {
changedFiles[filepath] = action;
onChange();
});
Comment on lines +145 to +155
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Issue with task optimization: 'shell.npm_build.src' is not utilized

The optimization code attempts to set shell.npm_build.src based on changed files:

grunt.config('shell.npm_build.src', Object.keys(changedFiles));

However, the grunt-shell plugin does not use the src property; it relies on the command option to execute shell commands. Therefore, updating shell.npm_build.src has no effect on the task execution.

Consider modifying the task optimization logic. If the goal is to conditionally run the npm build only when certain files change, you might:

  • Directly invoke the npm build command within the onChange function.
  • Check the file paths in changedFiles to determine if a build is necessary.
  • Adjust the shell:npm_build task configuration to reflect these changes.

Example refactored code:

 let changedFiles = Object.create(null);
 let onChange = grunt.util._.debounce(function() {
-    grunt.config('shell.npm_build.src', Object.keys(changedFiles));
     // If any Vue files have changed, run npm build
     if (Object.keys(changedFiles).some(file => file.endsWith('.vue') || file.endsWith('.js'))) {
         grunt.task.run('shell:npm_build');
     }
     changedFiles = Object.create(null);
 }, 200);

This ensures that npm run build is only called when relevant files change.


// build stuff
grunt.registerTask( 'release', [ 'less', 'concat', 'uglify', 'i18n', 'readme' ] );
grunt.registerTask( 'zip', [ 'clean', 'copy', 'compress' ] );
// Define tasks
grunt.registerTask( 'default', ['less', 'concat', 'uglify', 'i18n'] );
grunt.registerTask( 'i18n', ['makepot'] );
grunt.registerTask( 'readme', ['wp_readme_to_markdown'] );
grunt.registerTask( 'release', ['less', 'concat', 'uglify', 'i18n', 'readme'] );
grunt.registerTask( 'zip', ['clean', 'copy', 'compress'] );
};
21 changes: 21 additions & 0 deletions assets/assets/_plugin-vue_export-helper-DzwH9eqJ.js

Large diffs are not rendered by default.

Loading
Loading