Grunt build YUI JS for availability plugin - how to?

Grunt build YUI JS for availability plugin - how to?

by Mark van Hoek -
Number of replies: 4
Picture of Core developers Picture of Plugin developers

I've got a new availability condition plugin on Bitbucket (https://bitbucket.org/mwebv/moodle-availability_integrityadvocate/src/master/) and would like to automate grunt building of the JS in a pipeline (from yui/src/frm into yui/build).  I've read over the moodle.org docs and the grunt docs but I seem to have missed some basic concepts somehow.

Any how-to's or suggestions?  

Here's what I've got so far:

# - cd yui/
# - npm install
# - npm install -g grunt-cli
# - grunt build

Average of ratings: -
In reply to Mark van Hoek

Re: Grunt build YUI JS for availability plugin - how to?

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Can you provide a link to the instructions you are following?
In reply to Marcus Green

Re: Grunt build YUI JS for availability plugin - how to?

by Mark van Hoek -
Picture of Core developers Picture of Plugin developers

None of the availability condition plugins I've looked a Gruntfile.js in their codebase. I guess they use the Moodle root one?

This is as close as I've gotten so far:
```
- cd yui/src/form/
- ls -altrh
- npm install
#Old <M2.9 Shifter method: - npm install shifter@0.4.6 -g
- npm install -g grunt-cli
- grunt --verbose
```

With this error output:
```
$ grunt --verbose
Initializing
Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Loading "Gruntfile.js" tasks...ERROR
>> TypeError: Cannot read property 'node' of undefined
>> at Object.module.exports (availability\condition\integrityadvocate\Gruntfile.js:41:81)
>> at loadTask (availability\condition\integrityadvocate\node_modules\grunt\lib\grunt\task.js:315:10)
>> at Task.task.init (availability\condition\integrityadvocate\node_modules\grunt\lib\grunt\task.js:434:5)
>> at Object.grunt.tasks (availability\condition\integrityadvocate\node_modules\grunt\lib\grunt.js:111:8)
>> at Liftoff. (npm\node_modules\grunt-cli\bin\grunt:66:13)
>> at Liftoff.execute (npm\node_modules\grunt-cli\node_modules\liftoff\index.js:203:12)
>> at module.exports (npm\node_modules\grunt-cli\node_modules\flagged-respawn\index.js:51:3)
>> at Liftoff. (npm\node_modules\grunt-cli\node_modules\liftoff\index.js:195:5)
>> at Liftoff. (npm\node_modules\grunt-cli\node_modules\liftoff\index.js:170:7)
>> at processTicksAndRejections (internal/process/task_queues.js:79:11)

No tasks specified, running default tasks.
Running tasks: default
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.
```
In reply to Mark van Hoek

Re: Grunt build YUI JS for availability plugin - how to?

by Mark van Hoek -
Picture of Core developers Picture of Plugin developers
Manged to get it working at long last by doing this:

- Specify node version 8.x
- Copy in .shifter.json, Gruntfile.js and package.json from Moodle root.
- Edit package.json and change name and description fields.

bitbucket-pipeline.yml
--
image: node:8.17.0

pipelines:
  custom: # Pipelines that are triggered manually
    build_js:
      - step:
         name: "Build the JS modules"
         caches:
           - node
         script:
           - curl -vvvv -s https://raw.githubusercontent.com/moodle/moodle/MOODLE_38_STABLE/Gruntfile.js --output Gruntfile.js
           - ls -altrh
           - npm install
           - npm install -g grunt-cli
           - grunt --verbose shifter
Other code here...


In reply to Mark van Hoek

Re: Grunt build YUI JS for availability plugin - how to?

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Moodle has its own grunt tasks that can look after this for you, but you need to be in the root of the moodle installation to use it.


$ cd /var/www/moodleroot
$ npm install (if you haven't done so already - this should install all Moodle's dependencies for grunt)
$ grunt watch (when you save your yui javascript Moodle's grunt will compile the build version)


Hope that helps a little.