Возникла проблема при регистрации нового конфига в grunt - PullRequest
0 голосов
/ 03 марта 2020

Проект (Coffeescript + Grunt) уже содержит успешно запущенные конфиги и зарегистрированные задачи.

Структура выглядит следующим образом:

├── app
  ├── project1
    ├── tasks
    ├── config
        ├── browserify.litcoffee
        ├── clean.litcoffee
        ├── coffee.litcoffee
        ├── coffeelint.litcoffee
        ├── postcss.litcoffee
        ├── concurrent.litcoffee
        ├── connect.litcoffee
        ├── watch.litcoffee
        ├── test.litcoffee
        ├── ..........
        ........

    ├── register
        ├── serve.litcoffee
        ├── testgen.litcoffee
├── project2
    ├── .................
Gruntfile.coffee
Gruntfile.litcoffee
package.json

Я работаю над проектом 'project1', который уже успешно настроен задача 'serve' и конфиги 'clean', 'coffee', 'post css', et c ....,

все следующие рабочие задачи успешно выполняются из root проекта

- grunt coffee:dist -p=project1
- grunt serve:dist -p=project1
- grunt postcss:dist -p=project1

Я создал новые файлы config/test.litcoffee и register/testgen.litcoffee

app / project1 / tasks / config / test.litcoffee

# test.litcoffee

...

---

This task wraps Common JS modules for use client-side.

    module.exports = (grunt) ->
      grunt.config.set 'test',
        options:
          bare: true
        expand: true
        flatten: false
        cwd: 'app/project1/components'
        src: ['**/*[sS]pec.litcoffee']
        dest: 'spec/project1/'
        ext: '.js'

....

app / project1 / tasks / register / testgen.litcoffee

# testgen.litcoffee

This is a target loaded when the Gruntfile is called from the command
line similar to the following "grunt testgen -p=project1". When the target is created
and run, it executes tasks in order.

---

## Associated Tasks
- [Test](/test.litcoffee)
- [Watch](/watch.litcoffee)

This target combines tasks in order to create a development build which opens in the user's default browser.

    module.exports = (grunt) ->
      grunt.registerTask 'testgen', 'Run local test cases.', [
        'test'
        'watch'
      ]

но тест конфигурации не найден:

$ grunt testgen -p=project1
Warning: Task "test" not found. Use --force to continue.

Aborted due to warnings.


$ grunt testgen -p=project1--force
Warning: Task "test" not found. Used --force, continuing.

Done, but with warnings.

Gruntfile для справки:

Gruntfile.litcoffee

This is the main entry point for all grunt command line tasks. This
will load project specific tasks dynamically with the "-p and -l{optional}" flag and generate
the appropriate tasks and targets.

---

##Tasks
- [Clean](clean.html)
- [Concat](concat.html)
- [Concurrent](concurrent.html)
- [Copy](copy.html)
- [Cssmin](cssmin.html)
- [Jade](jade.html)
- [Sass](sass.html)
- [Autoprefixer](autoprefixer.html)
- [Browserify](browserify.html)
- [Coffeelint](coffeelint.html)
- [Connect](connect.html)
- [Htmlmin](htmlmin.html)
- [Imagemin](imagemin.html)

##Targets
- [Build](build.html)
- [Serve](serve.html)
- [Deploy](deploy.html)

---

This module.exports creates in the global space a Gruntfile linking to sub folders dependent upon command line arguments entered. Gruntfile.litcoffee runs because of the module.export within the file Gruntfile.coffee. Otherwise, Grunt will not register this file due inherit hardcoded path looking for Gruntfile.coffee/Gruntfile.js

    'use strict'

    module.exports = (grunt) ->

      require('load-grunt-tasks') grunt

      # Create the project path from the command line arguments. This is
      # where the command line is parsed. Example usage...
      # ```shell
      # grunt serve -p project1
      # ```
      targetProject = grunt.option('p') || grunt.option('project') || null
      pathConfig = 'app/' + targetProject + '/tasks/config'
      pathRegister = 'app/' + targetProject + '/tasks/register'


      # Check for a 'string' type to check for project.
      if typeof targetProject is 'string'

        # Load the include-all library in order to require all of our grunt
        # configurations and task registrations dynamically.
        try
          includeAll = require('include-all')

        catch e0

          try
            includeAll = require('presentation-source/node_modules/include-all')

          catch e1
            console.error 'Could not find `include-all` module.'
            console.error 'Skipping grunt tasks...'
            console.error 'To fix this, please run:'
            console.error 'npm install include-all --save-dev`'
            console.error()
            grunt.registerTask 'default', []

Loads Grunt configuration modules from the specified relative path. These modules should export a function that, when run, should either load/configure or register a Grunt task.

        loadTasks = (relPath) ->
          includeAll(
            dirname: require('path').resolve(__dirname, relPath)
            filter: /(.+)\.litcoffee$/
          ) or {}

Invokes the function from a Grunt configuration module with a single argument - the "grunt" object.

        invokeConfigFn = (tasks) ->
          for taskName of tasks
            tasks[taskName](grunt) if tasks.hasOwnProperty(taskName)

        # Load task functions with previously created path references.
        taskConfigurations = loadTasks( pathConfig )
        registerDefinitions = loadTasks( pathRegister )

        # Ensure that a default task exists.
        unless registerDefinitions.default
          registerDefinitions.default = (grunt) ->
            grunt.registerTask 'default', []
            return

        # Run task functions to configure Grunt.
        invokeConfigFn taskConfigurations
        invokeConfigFn registerDefinitions

      else

        # Using 'grunt.fail.fatal' to abort grunt process and alert user of error
        message = [
          'Sorry :( You must specify a specific project like the following',
          '> grunt myTask -p [projectName]'
        ]
        grunt.fail.fatal(message.join('\n'))
...