Skip to content
This repository was archived by the owner on Jul 9, 2018. It is now read-only.

Scripts: New package with scripts for plugins#55

Closed
gziolo wants to merge 1 commit intomasterfrom
add/scripts-for-plugins
Closed

Scripts: New package with scripts for plugins#55
gziolo wants to merge 1 commit intomasterfrom
add/scripts-for-plugins

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented Dec 19, 2017

Still work in progress ...

This implementation is based on the react-scripts. Grunt tasks are copied directly from wp scaffold plugin templates. See gruntfile for reference.

The end goal would be to run it as:

  • wp-scripts i18n --pluginSlug=abc --textDomain=xyz
  • wp-scritps readme

To include you would have to include in devDependencies only this:

"@wordpress/scripts": "1.0.0"

Disclaimer

I'm not promoting Grunt by any means. It was easy to copy what we already have in wp-cli to show how it could benefit plugin developers. Script names could be prefixed with plugin- in this case to make it more clear where it is applicable. This could also live in plugin-scripts package to avoid confusion.

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 19, 2017

Codecov Report

Merging #55 into master will decrease coverage by 15.47%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master      #55       +/-   ##
===========================================
- Coverage   97.29%   81.81%   -15.48%     
===========================================
  Files          17       19        +2     
  Lines         148      176       +28     
  Branches       41       48        +7     
===========================================
  Hits          144      144               
- Misses          4       25       +21     
- Partials        0        7        +7
Impacted Files Coverage Δ
packages/scripts/bin/wp-scripts.js 0% <0%> (ø)
packages/scripts/Gruntfile.js 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c58b48a...c1ad274. Read the comment docs.

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Dec 19, 2017

@danielbachhuber, this is the proof of concept I wanted to share with you :)

@gziolo gziolo requested review from aduth and youknowriad December 19, 2017 16:51
@ntwb
Copy link
Copy Markdown
Member

ntwb commented Dec 20, 2017

FYI: WordPress' official build tool is Grunt, and we've recently added Webpack. Official WordPress repos should use Grunt over Gulp, the reason for this is primarily to reduce the required volume of learning for contributors to WordPress projects.

},
"dependencies": {
"@wordpress/dom-ready": "^0.1.0-beta.6"
"@wordpress/dom-ready": "0.1.0-beta.6"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change shouldn't be in this PR should it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Likewise the dom-ready/package-lock.json and a11y/package-lock.json changes shouldn't be in this PR either?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I will remove those changes.

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Dec 20, 2017

FYI: WordPress' official build tool is Grunt, and we've recently added Webpack. Official WordPress repos should use Grunt over Gulp, the reason for this is primarily to reduce the required volume of learning for contributors to WordPress projects.

The main goal of this package is to make it an implementation detail if WordPress is using Grunt, Gulp, Webpack or whatever is necessary to make things done. I can envision using all of those tools in this package, as well as having them replaced in the far future with something that is yet to be created. This approach promotes usage of npm run-script which is a well-established pattern in the JS community.

@gziolo gziolo force-pushed the add/scripts-for-plugins branch from f9f803d to c1ad274 Compare December 20, 2017 07:54
@danielbachhuber
Copy link
Copy Markdown
Member

Can I use this and a Gruntfile in my own project?

e.g. this project would expose some wp-scripts readme I can run, but then I can continue to use my grunt styles for compiling SASS.

Copy link
Copy Markdown
Member

@aaronjorbin aaronjorbin left a comment

Choose a reason for hiding this comment

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

Loving this! Thanks for kicking it off.

"scripts": {
"build-clean": "rimraf ./packages/*/build ./packages/*/build-module",
"build": "node ./scripts/build.js",
"postinstall": "lerna bootstrap --hoist && npm run build",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is removing --hoist intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I opened an issue to address it separately #56. I will rebase once it gets merged.


const pkg = grunt.file.readJSON( 'package.json' );
const pluginSlug = grunt.option( 'pluginSlug' ) || pkg.name;
const textDomain = grunt.option( 'textDomain' ) || '';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we start a standard of allowing package.json to contain a WordPress object that initially has textDomain and pluginSlug properties in it? pluginSlug could fallback to pkg.name if pkg.wordpress.pluginslug isn't defined.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm more than happy to do it. I thought it might be too early, but if you raised that now let's go for it 💯

const pluginSlug = grunt.option( 'pluginSlug' ) || pkg.name;
const textDomain = grunt.option( 'textDomain' ) || '';

console.log( pluginSlug, textDomain );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leftover Dubugging code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, sir! Removing it :)

},

wp_readme_to_markdown: {
your_target: {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is another area where pkg.wordpress could come in handy, since it would allow screenshots to be passed in.

Install the module

```bash
npm install @wordpress/scripts --save
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR summary contains the line: "To include you would have to include in devDependencies only this:"

Would --saveDev make more sense?

@aaronjorbin
Copy link
Copy Markdown
Member

aaronjorbin commented Dec 20, 2017

When this is available, let's make sure to announce it on https://make.wordpress.org/core and cross-post it on https://make.wordpress.org/plugins/

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Dec 21, 2017

@adamsilverstein can we cover it with tests in some simple way?

@danielbachhuber
Copy link
Copy Markdown
Member

Probably worth mentioning wp-cli/ideas#68

Sorry I didn't connect the dots before. Given wp makepot will soon exist, would it make sense to create a README command too and keep this entirely to PHP?

"cross-spawn": "5.1.0",
"grunt": "1.0.1",
"grunt-wp-i18n": "1.0.1",
"grunt-wp-readme-to-markdown": "2.0.1"
Copy link
Copy Markdown
Collaborator

@youknowriad youknowriad Dec 21, 2017

Choose a reason for hiding this comment

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

Who maintains these dependencies, since now we're trying to build a utility hiding implementation details, we can try to move away from React, I think these would benefit from being simple Javascript Scripts instead of Grunt tasks.

Not saying we should do it now, the scripts module also allows us to keep using Grunt and several other tools and hide the implementation, but avoiding useless dependencies like "grunt" would be good (Same way there's babel, and grunt-babel etc...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@stephenharris is the maintainer.

In general, I agree that lessening the dependency on Grunt makes sense, but at the same time it's not exposed to the plugin developer, so it is just an implementation detail rather than an api detail.

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Dec 21, 2017

Sorry I didn't connect the dots before. Given wp makepot will soon exist, would it make sense to create a README command too and keep this entirely to PHP?

So this would make this PR obsolete. I'd be more than happy to have that handled by wp-cli exclusively. Let me know if I should close this PR and open another one focused on exposing JS and CSS linting for plugins and themes.

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Dec 21, 2017

Can I use this and a Gruntfile in my own project?

e.g. this project would expose some wp-scripts readme I can run, but then I can continue to use my grunt styles for compiling SASS.

Yes, it doesn't stop you from having your own Grunt setup in your project. The nice thing about npm is that you can use several versions of the same dependency. I guess you would have to set grunt as a local dependency and all Grunt plugins to make it work.

@aaronjorbin
Copy link
Copy Markdown
Member

Sorry I didn't connect the dots before. Given wp makepot will soon exist, would it make sense to create a README command too and keep this entirely to PHP?

I would support this. If wp-cli can be the tool of truth, I think it makes sense.

@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Jan 9, 2018

Closing in favor of #62.

@gziolo gziolo closed this Jan 9, 2018
@gziolo gziolo deleted the add/scripts-for-plugins branch January 9, 2018 12:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants