Giter Site home page Giter Site logo

gruntfile-editor's Introduction

Gruntfile Editor

npm tests Coverage Status dependencies

An API to modify a Gruntfile.js content

Installation

npm install --save gruntfile-editor

Example

var GruntfileEditor = require('gruntfile-editor');
var editor = new GruntfileEditor();

editor.insertConfig('compass', '{ foo: "bar" }');

fs.writeFileSync('Gruntfile.js', editor.toString());

API

new GruntfileEditor( content )

Create a new editor instance. You can pass the content of the Gruntfile to edit to the constructor. If no content is provided, a default file structure is used.

editor.insertConfig( name, config )

Insert a configuration block inside the grunt.initConfig() call.

editor.registerTask( name, tasks )

Register a task inside a named task group

editor.registerTask('build', 'compass');
// output: grunt.registerTask('build', ['compass']);

editor.registerTask('build', ['compass', 'uglify']);
// output: grunt.registerTask('build', ['compass', 'uglify']);

You can specify an optional description.

editor.registerTask('build', 'A task description', ['compass', 'uglify']);
// output: grunt.registerTask('build', 'A task description', ['compass', 'uglify']);

editor.insertVariable( name, value )

Insert a variable to the top of the Gruntfile.

editor.insertVariable('root', '"project/foo"');
// output: var root = 'project/foo';

editor.prependJavaScript( code )

Insert a piece of arbritary JavaScript code to the top of the Gruntfile.

editor.prependJavaScript('require(\'load-grunt-tasks\')(grunt);');
// output: require('load-grunt-tasks')(grunt);

editor.loadNpmTasks( pluginName )

Load a Grunt plugin.

editor.loadNpmTasks('grunt-contrib-uglify');
// output: grunt.loadNpmTasks("grunt-contrib-uglify");

editor.loadNpmTasks(['grunt-contrib-uglify', 'grunt-contrib-concat']);
// output:
// grunt.loadNpmTasks("grunt-contrib-concat");
// grunt.loadNpmTasks("grunt-contrib-uglify");

editor.toString()

Returns the modified Gruntfile as a string.

Licence

Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.

gruntfile-editor's People

Contributors

eddiemonge avatar edoput avatar greenkeeper[bot] avatar lauterry avatar martindelille avatar qiuzuhui avatar sboudrias avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gruntfile-editor's Issues

#insertComment(): Allow comments to be added

I know the goal of this is to programmatically control the Gruntfile but users will still probably read it to understand whats going on. Without the ability to add comments, it is hard to know exactly what is going on. Each method should take an optional comment parameter that is added before whatever is being added to the GF.

There should also be a way to add pure comments that don't have supporting code like:

// Generated on #{date()} for #{name}

Hard part is to determine where to insert the comments I think

#loadNpmTasks(): Allow multiple calls with same task

Hy,

I noticed that running the loadNpmTast multiple times with the same parameter leads to the task beeing loaded multiple times in the created Gruntfile.

So calling

gruntfile.loadNpmTasks('grunt-contrib-watch');
gruntfile.loadNpmTasks('grunt-contrib-watch');

leads to

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-watch');

in the Gruntfile.

Set gruntfile content after initialisation

Hello

gruntfile-editor is used in Yeoman 0.17.

However, we cannot set the content of the Gruntfile in yeoman generator context.

In that case, I need a way to set the gruntfile content after the initilisation. Maybe something like

gruntfile.setContent(this.src.read('Gruntfile.js'));

Best regards !

Why use a separate repository

I like the AST Query approach but before we could switch the gruntfile-api to your module we should bring in all the features i currently have available by working on the AST directly to keep the changes to the generated gruntfile(-style) as low as possible.
I created a branch on gruntfile-api.

Add appendJavascript support

Same as prependJavascript, but at the end of the file. Would be great for enabling loading configurations and tasks from external files, without having to define specific tasks for doing it.

#insertConfig(): fails when overwriting an array

insertConfig("clean", "['dist/*.html']") works when "clean" has not been defined yet, but fails when trying to overwrite.

Error: Object [object Object] has no method 'value' at index.js:37

Since the node at index:37 is an ArrayExpression, it has no value() method. Is it possible to add one for ArrayExpressions?

An in-range update of eslint is breaking the build 🚨

Version 4.1.1 of eslint just got published.

Branch Build failing 🚨
Dependency eslint
Current Version 4.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
  • βœ… coverage/coveralls First build on greenkeeper/eslint-4.1.1 at 0.0% Details

Release Notes v4.1.1
  • f307aa0 Fix: ensure configs from a plugin are cached separately (fixes #8792) (#8798) (Teddy Katz)
  • 8b48ae8 Docs: Add doc on parser services (fixes #8390) (#8795) (Victor Hom)
  • 0d041e7 Fix: avoid crashing when using baseConfig with extends (fixes #8791) (#8797) (Teddy Katz)
  • 03213bb Chore: improve comment explanation of indent internal functions (#8800) (Teddy Katz)
  • d2e88ed Chore: Fix misleading comment in ConfigCache.js (#8799) (Teddy Katz)
Commits

The new version differs by 7 commits.

  • 1df6a01 4.1.1
  • 79a4482 Build: changelog update for 4.1.1
  • f307aa0 Fix: ensure configs from a plugin are cached separately (fixes #8792) (#8798)
  • 8b48ae8 Docs: Add doc on parser services (fixes #8390) (#8795)
  • 0d041e7 Fix: avoid crashing when using baseConfig with extends (fixes #8791) (#8797)
  • 03213bb Chore: improve comment explanation of indent internal functions (#8800)
  • d2e88ed Chore: Fix misleading comment in ConfigCache.js (#8799)

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

Version 3.5.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.4.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
  • βœ… coverage/coveralls First build on greenkeeper/mocha-3.5.0 at 0.0% Details

Release Notes free-as-in-freezing

3.5.0 / 2017-07-31

πŸ“° News

  • Mocha now has a code of conduct (thanks @kungapal!).
  • Old issues and PRs are now being marked "stale" by Probot's "Stale" plugin. If an issue is marked as such, and you would like to see it remain open, simply add a new comment to the ticket or PR.
  • WARNING: Support for non-ES5-compliant environments will be dropped starting with version 4.0.0 of Mocha!

πŸ”’ Security Fixes

πŸŽ‰ Enhancements

  • #2696: Add --forbid-only and --forbid-pending flags. Use these in CI or hooks to ensure tests aren't accidentally being skipped! (@charlierudolph)
  • #2813: Support Node.js 8's --napi-modules flag (@jupp0r)

πŸ”© Other

Commits

The new version differs by 34 commits.

  • 82d879f Release v3.5.0
  • bf687ce update mocha.js for v3.5.0
  • ec73c9a update date for release of v3.5.0 in CHANGELOG [ci skip]
  • 1ba2cfc update CHANGELOG.md for v3.5.0 [ci skip]
  • 065e14e remove custom install script from travis (no longer needed)
  • 4e87046 update karma-sauce-launcher URL for npm@5
  • 6886ccc increase timeout for slow-grepping test
  • 2408d90 Make dependencies use older version of readable-stream to work around incompatibilities introduced by 2.3.0 on June 19th
  • 68a1466 Try not clearing the env for debug in the integration test and see if that fixes Node 0.10 on AppVeyor; if need be, some other fix/workaround can be applied to handle whatever was up with debug without causing this issue
  • 958fbb4 Update new tests to work in browser per test hierarchy reorganization
  • 1df7c94 Merge pull request #2704 from seppevs/increase_test_coverage_of_mocha_js
  • 1f270cd Stop timing out (#2889)
  • 27c7496 upgrade to [email protected]; closes #2859 (#2860)
  • 50fc47d fix CI; closes #2867 (#2868)
  • 1b1377c Add test for ignoreLeaks and fix descriptions

There are 34 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of gulp-plumber is breaking the build 🚨

The devDependency gulp-plumber was updated from 1.2.0 to 1.2.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

gulp-plumber is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

InsertConfig and RegExp

I am using grunt-wiredep in my yeoman scaffolding script to connect bower dependancies into my html files. I need to just slightly adjust the way wiredep handles this by passing its fileTypes option.

html: {
      block: /(([ \t]*)<!--\s*bower:*(\S*)\s*-->)(\n|\r|.)*?(<!--\s*endbower\s*-->)/gi,
      detect: {
        js: /<script.*src=['"]([^'"]+)/gi,
        css: /<link.*href=['"]([^'"]+)/gi
      },
      replace: {
        js: '<script src="{{filePath}}"></script>',
        css: '<link rel="stylesheet" href="{{filePath}}" />'
      }
    },

Some attributes are set to raw RegExp. Just copying and pasting this, leaves me with the attributes being empty after yeoman ran.

I already tried replacing raw regular expressions with new RegExp("expression"). Which didn't work. I guess wiredep doesn't take that.

Any idea on how I can let yeoman insert these regExps ?

An in-range update of gulp-exclude-gitignore is breaking the build 🚨

Version 1.2.0 of gulp-exclude-gitignore just got published.

Branch Build failing 🚨
Dependency gulp-exclude-gitignore
Current Version 1.1.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As gulp-exclude-gitignore is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details
  • ❌ coverage/coveralls Coverage pending from Coveralls.io Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v1.2.0

Correctly ignore dotfiles when specified in .gitignore

Commits

The new version differs by 5 commits.

  • 248b91a Update sinon to the latest version πŸš€ (#13)
  • 802bfc3 chore(package): update eslint-config-xo-space to version 0.16.0 (#10)
  • 533d5e0 chore(package): update sinon to version 2.0.0 (#9)
  • 7844c50 1.2.0
  • cca661f (Fix) Always match dotfiles in .gitignore

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Add support for load-grunt-tasks

I'd like to avoid having to call loadNpmTasks lots of times, would be good if there was a way to invoke "require('load-grunt-tasks')(grunt);" This can be done right now by using insertVariable however it results in an unused variable which jshint then complains about.

An in-range update of lodash is breaking the build 🚨

The dependency lodash was updated from 4.17.10 to 4.17.11.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

lodash is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add latest index.js to NPM

The latest version of gruntfile-editor( 0.1.0 ) does not have the loadNpmTask in the index.js file. I discovered this while trying to get this.gruntfile.loadNpmTask to work in yeoman.

#insertConfig(): function literal inside config object is lost after JSON is converted to a string

When creating a config object for a task, some config objects have a function literal as a value for a keyed property.

For example, grunt-cdnify allows a rewriter option to examine a file name, perform an action on that file name, and return a new string:

var config = {
cdnify: {
someTarget: {
options: {
rewriter: function (url) {
if (url.indexOf('data:') === 0)
return url; // leave data URIs untouched
else
return url + '?12345'; // add query string to all other URLs
}

},
files: [{
expand: true,
cwd: 'app',
src: '*/.{css,html}',
dest: 'dist'
}]
}
}
};

generator.gruntfile.insertConfig( 'cdnify', JSON.stringify( config ) );

The function literal is lost in the JSON.stringify method. Is there a way to insert a config to Grunt without losing that functionality?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.