Как получить доступ к абсолютному пути к Gruntfile в Gruntfile?

My Gruntfile.js содержит задачу для Compass:

grunt.initConfig({

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

  // FILE PATHS (custom)
  dir: {
    css:          'resources/styles/css',
    fonts:        'resources/fonts',
    html:         'resources/html',
    images:       'resources/images',
    includes:     'resources/includes',
    node_modules: 'node_modules',
    prototypes:   'resources/html/prototypes',
    resources:    'resources',
    scripts:      'resources/scripts',
    scss:         'resources/styles/scss',
    styles:       'resources/styles',
    styleguide:   'resources/styleguide',
    vendor:       'resources/vendor',
    user: {
       htdocs: '/Volumes/VR\ Mini\ Backup/Backups/Web/Active/myproject/htdocs'
    }
  },

  // COMPASS
  compass: {
    dist: {
      options: {
        ...
        importPath: [
          '<%= dir.user.htdocs %>/<%= dir.resources %>/vendor',
          '<%= dir.user.htdocs %>/<%= dir.resources %>/fonts'
        ]

Один из параметров Compass importPath. Это ожидает абсолютный/системный путь. Пример importPath равен /system/path/to/htdocs/resources/vendor.

Поскольку несколько разработчиков будут работать над моим проектом, я бы хотел сделать динамическое /system/path/to/htdocs.

Есть ли способ доступа к пути к Gruntfile.js из этого файла?

Спасибо.

Ответы

Ответ 1

Вы можете использовать Node модуль пути.

В верхней части вашего файла grunt добавьте var path = require('path');.

path.resolve() даст вам абсолютный путь.