├── .gitattributes
├── examples
├── libglobal
│ ├── README.md
│ ├── principium
│ │ └── convert.js
│ ├── wrap
│ │ ├── wrap.start
│ │ └── wrap.end
│ ├── principium.js
│ ├── tests
│ │ ├── index-dist-global.html
│ │ ├── index.html
│ │ ├── index-dist-amd.html
│ │ ├── principium-tests.js
│ │ └── qunit.css
│ ├── package.json
│ ├── Gruntfile.js
│ └── lib
│ │ └── underscore.js
├── multipage
│ ├── www
│ │ ├── js
│ │ │ ├── app
│ │ │ │ ├── controller
│ │ │ │ │ ├── c1.js
│ │ │ │ │ ├── c2.js
│ │ │ │ │ └── Base.js
│ │ │ │ ├── model
│ │ │ │ │ ├── m1.js
│ │ │ │ │ ├── m2.js
│ │ │ │ │ └── Base.js
│ │ │ │ ├── lib.js
│ │ │ │ ├── main1.js
│ │ │ │ └── main2.js
│ │ │ ├── page1.js
│ │ │ ├── page2.js
│ │ │ └── common.js
│ │ ├── page1.html
│ │ └── page2.html
│ ├── package.json
│ ├── tests
│ │ ├── index.html
│ │ ├── index-dist.html
│ │ ├── tests.js
│ │ └── qunit.css
│ ├── Gruntfile.js
│ └── README.md
└── multipage-shim
│ ├── www
│ ├── js
│ │ ├── app
│ │ │ ├── controller
│ │ │ │ ├── c1.js
│ │ │ │ ├── c2.js
│ │ │ │ └── Base.js
│ │ │ ├── model
│ │ │ │ ├── m1.js
│ │ │ │ ├── m2.js
│ │ │ │ └── Base.js
│ │ │ ├── lib.js
│ │ │ ├── main2.js
│ │ │ └── main1.js
│ │ ├── page1.js
│ │ ├── page2.js
│ │ ├── common.js
│ │ └── lib
│ │ │ └── underscore.js
│ ├── page1.html
│ └── page2.html
│ ├── package.json
│ ├── Gruntfile.js
│ └── README.md
├── test
├── fixtures
│ ├── hello.js
│ ├── world.js
│ ├── replaceSingleAlmondDocFragment.html
│ ├── project.js
│ ├── replaceSingleAlmondNoDocType.html
│ ├── replaceSingleAlmond.html
│ ├── replaceSingleAlmondWithAttr.html
│ ├── replaceSingleAlmondWithComplexAttr.html
│ ├── replaceMultiAlmond.html
│ ├── requirejs
│ │ ├── README.md
│ │ └── package.json
│ ├── expected_sourcemap.txt
│ ├── replaceConditionalComments.html
│ └── replaceInDjangoTemplates.html
└── require_test.js
├── .travis.yml
├── .npmignore
├── .editorconfig
├── .gitignore
├── .jshintrc
├── AUTHORS.md
├── lib
├── helper
│ ├── errorhandler.js
│ ├── rjsversion.js
│ └── sizeInfo.js
├── almondify.js
├── replace.js
└── optimize.js
├── docs
├── sourcemaps.md
├── customrjs.md
└── almondIntegration.md
├── LICENSE-MIT
├── package.json
├── tasks
└── require.js
├── CONTRIBUTING.md
├── CHANGELOG
├── README.md
└── Gruntfile.js
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
--------------------------------------------------------------------------------
/examples/libglobal/README.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test/fixtures/hello.js:
--------------------------------------------------------------------------------
1 | define(function(){return "hello";});
2 |
--------------------------------------------------------------------------------
/test/fixtures/world.js:
--------------------------------------------------------------------------------
1 | define(function(){return "world";});
2 |
--------------------------------------------------------------------------------
/test/fixtures/replaceSingleAlmondDocFragment.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/fixtures/project.js:
--------------------------------------------------------------------------------
1 | require(['hello', 'world'], function(hello, world) {
2 | console.log(hello,world);
3 | });
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "0.8"
4 | - "0.10"
5 | before_script:
6 | - npm install -g grunt-cli
7 |
--------------------------------------------------------------------------------
/test/fixtures/replaceSingleAlmondNoDocType.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/controller/c1.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var c1 = new Base('Controller 1');
3 | return c1;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/controller/c2.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var c2 = new Base('Controller 2');
3 | return c2;
4 | });
5 |
--------------------------------------------------------------------------------
/test/fixtures/replaceSingleAlmond.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/controller/c1.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var c1 = new Base('Controller 1');
3 | return c1;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/controller/c2.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var c2 = new Base('Controller 2');
3 | return c2;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/model/m1.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var m1 = new Base('This is the data for Page 1');
3 | return m1;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/model/m2.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var m2 = new Base('This is the data for Page 2');
3 | return m2;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/model/m1.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var m1 = new Base('This is the data for Page 1');
3 | return m1;
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/model/m2.js:
--------------------------------------------------------------------------------
1 | define(['./Base'], function (Base) {
2 | var m2 = new Base('This is the data for Page 2');
3 | return m2;
4 | });
5 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /test/
3 | /docs/
4 | /examples/
5 | .editorconfig
6 | .gitattributes
7 | .gitignore
8 | .jshinttrc
9 | .npmignore
10 | .travis.yml
11 |
--------------------------------------------------------------------------------
/test/fixtures/replaceSingleAlmondWithAttr.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/lib.js:
--------------------------------------------------------------------------------
1 | define(['jquery'], function ($) {
2 | return {
3 | getBody: function () {
4 | return $('body');
5 | }
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/lib.js:
--------------------------------------------------------------------------------
1 | define(['jquery'], function ($) {
2 | return {
3 | getBody: function () {
4 | return $('body');
5 | }
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/page1.js:
--------------------------------------------------------------------------------
1 | //Load common code that includes config, then load the app logic for this page.
2 | require(['./common'], function (common) {
3 | require(['app/main1']);
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/page2.js:
--------------------------------------------------------------------------------
1 | //Load common code that includes config, then load the app logic for this page.
2 | require(['./common'], function (common) {
3 | require(['app/main2']);
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/page1.js:
--------------------------------------------------------------------------------
1 | //Load common code that includes config, then load the app logic for this page.
2 | require(['./common'], function (common) {
3 | require(['app/main1']);
4 | });
5 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/page2.js:
--------------------------------------------------------------------------------
1 | //Load common code that includes config, then load the app logic for this page.
2 | require(['./common'], function (common) {
3 | require(['app/main2']);
4 | });
5 |
--------------------------------------------------------------------------------
/test/fixtures/replaceSingleAlmondWithComplexAttr.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/examples/libglobal/principium/convert.js:
--------------------------------------------------------------------------------
1 | define(['underscore'], function (_) {
2 | 'use strict';
3 |
4 | function convert(text) {
5 | return _.escape(text);
6 | }
7 |
8 | return convert;
9 | });
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # editorconfig.org
2 | root = true
3 |
4 | [*]
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | charset = utf-8
9 | trim_trailing_whitespace = true
10 | insert_final_newline = true
--------------------------------------------------------------------------------
/test/fixtures/replaceMultiAlmond.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/fixtures/requirejs/README.md:
--------------------------------------------------------------------------------
1 | # requirejs
2 |
3 | RequireJS for use in Node. includes:
4 |
5 | * r.js: the RequireJS optimizer, and AMD runtime for use in Node.
6 | * require.js: The browser-based AMD loader.
7 |
8 | More information at http://requirejs.org
9 |
10 |
--------------------------------------------------------------------------------
/examples/multipage/www/page1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Page 1
5 |
6 |
7 |
8 | Go to Page 2
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/multipage/www/page2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Page 2
5 |
6 |
7 |
8 | Go to Page 1
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/page1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Page 1
5 |
6 |
7 |
8 | Go to Page 2
9 |
10 |
11 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/page2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Page 2
5 |
6 |
7 |
8 | Go to Page 1
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /examples/libglobal/dist/
3 | /examples/multipage/www-built/
4 | /examples/multipage-shim/www-built/
5 | /examples/libglobal/node_modules/
6 | /examples/multipage/node_modules/
7 | /examples/multipage-shim/node_modules/
8 | /docs/complexity/
9 | /tmp/
10 | .DS_Store
11 | *.log
12 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/model/Base.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | function modelBase(title) {
3 | this.title = title;
4 | }
5 |
6 | modelBase.prototype = {
7 | getTitle: function () {
8 | return this.title;
9 | }
10 | };
11 |
12 | return modelBase;
13 | });
14 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/model/Base.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | function modelBase(title) {
3 | this.title = title;
4 | }
5 |
6 | modelBase.prototype = {
7 | getTitle: function () {
8 | return this.title;
9 | }
10 | };
11 |
12 | return modelBase;
13 | });
14 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": true,
6 | "newcap": true,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "boss": true,
11 | "eqnull": true,
12 | "node": true,
13 | "es5": true,
14 | "globals": {
15 | "exports": true,
16 | "require": true,
17 | "module": true
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/examples/libglobal/wrap/wrap.start:
--------------------------------------------------------------------------------
1 | //Copyright 2012, etc.
2 |
3 | (function (root, factory) {
4 | if (typeof define === 'function' && define.amd) {
5 | // AMD.
6 | define(['jquery', 'underscore'], factory);
7 | } else {
8 | // Browser globals
9 | root.principium = factory(root.$, root._);
10 | }
11 | }(this, function ($, _) {
12 |
13 |
14 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/common.js:
--------------------------------------------------------------------------------
1 | //The build will inline common dependencies into this file.
2 |
3 | //For any third party dependencies, like jQuery, place them in the lib folder.
4 |
5 | //Configure loading modules from the lib directory,
6 | //except for 'app' ones, which are in a sibling
7 | //directory.
8 | requirejs.config({
9 | baseUrl: 'js/lib',
10 | paths: {
11 | app: '../app'
12 | }
13 | });
14 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/main1.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | var $ = require('jquery'),
3 | lib = require('./lib'),
4 | controller = require('./controller/c1'),
5 | model = require('./model/m1');
6 |
7 | //A fabricated API to show interaction of
8 | //common and specific pieces.
9 | controller.setModel(model);
10 | $(function () {
11 | controller.render(lib.getBody());
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/main2.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | var $ = require('jquery'),
3 | lib = require('./lib'),
4 | controller = require('./controller/c2'),
5 | model = require('./model/m2');
6 |
7 | //A fabricated API to show interaction of
8 | //common and specific pieces.
9 | controller.setModel(model);
10 | $(function () {
11 | controller.render(lib.getBody());
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/main2.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | var $ = require('jquery'),
3 | lib = require('./lib'),
4 | controller = require('./controller/c2'),
5 | model = require('./model/m2');
6 |
7 | //A fabricated API to show interaction of
8 | //common and specific pieces.
9 | controller.setModel(model);
10 | $(function () {
11 | controller.render(lib.getBody());
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/AUTHORS.md:
--------------------------------------------------------------------------------
1 | Sebastian Golasch (http://github.com/asciidisco)
2 |
3 | Contributors:
4 | indieisaconcept
5 |
6 | Jörn Zaefferer (https://github.com/jzaefferer)
7 |
8 | Lauri Piispanen (https://github.com/lauripiispanen)
9 |
10 | bernos (https://github.com/bernos)
11 |
12 | Christopher Rogers (https://github.com/chrissrogers)
13 |
14 | Sven Lito (https://github.com/svnlto)
15 |
16 | Kengo TODA (https://github.com/eller86)
17 |
18 | Rodrigo Espinosa (https://github.com/RodEsp)
19 |
--------------------------------------------------------------------------------
/lib/helper/errorhandler.js:
--------------------------------------------------------------------------------
1 | /*
2 | * grunt-requirejs
3 | * https://github.com/asciidisco/grunt-requirejs
4 | *
5 | * Copyright (c) 2012 Sebastian Golasch, contributors
6 | * Licensed under the MIT license.
7 | */
8 |
9 | module.exports = function(grunt) {
10 | 'use strict';
11 |
12 | // fail task & log the error
13 | return function(error) {
14 | grunt.log.error(error);
15 | // this.done referres to grunts ´async´ method
16 | this.done(false);
17 | };
18 |
19 | };
20 |
--------------------------------------------------------------------------------
/examples/libglobal/wrap/wrap.end:
--------------------------------------------------------------------------------
1 | //Register in the values from the outer closure for common dependencies
2 | //as local almond modules
3 | define('jquery', function () {
4 | return $;
5 | });
6 | define('underscore', function () {
7 | return _;
8 | });
9 |
10 | //Use almond's special top-level, synchronous require to trigger factory
11 | //functions, get the final module value, and export it as the public
12 | //value.
13 | return require('principium');
14 | }));
15 |
--------------------------------------------------------------------------------
/examples/multipage/www/js/app/controller/Base.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | function controllerBase(id) {
3 | this.id = id;
4 | }
5 |
6 | controllerBase.prototype = {
7 | setModel: function (model) {
8 | this.model = model;
9 | },
10 |
11 | render: function (bodyDom) {
12 | bodyDom.prepend('Controller ' + this.id + ' says "' +
13 | this.model.getTitle() + '"');
14 | }
15 | };
16 |
17 | return controllerBase;
18 | });
19 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/controller/Base.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | function controllerBase(id) {
3 | this.id = id;
4 | }
5 |
6 | controllerBase.prototype = {
7 | setModel: function (model) {
8 | this.model = model;
9 | },
10 |
11 | render: function (bodyDom) {
12 | bodyDom.prepend('Controller ' + this.id + ' says "' +
13 | this.model.getTitle() + '"');
14 | }
15 | };
16 |
17 | return controllerBase;
18 | });
19 |
--------------------------------------------------------------------------------
/examples/libglobal/principium.js:
--------------------------------------------------------------------------------
1 | /*global define */
2 |
3 | /**
4 | * The main module that defines the public interface for principium,
5 | * a made-up library to demonstrate how to construct a source from components.
6 | */
7 | define(function (require) {
8 | 'use strict';
9 |
10 | var $ = require('jquery'),
11 | convert = require('principium/convert');
12 |
13 | //Return the module value.
14 | return {
15 | version: '0.0.1, jQuery version is: ' + $.fn.jquery,
16 | convert: convert
17 | };
18 | });
19 |
--------------------------------------------------------------------------------
/examples/libglobal/tests/index-dist-global.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test Suite - Dist Global
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/examples/multipage/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-requirejs-multipage-example",
3 | "version": "0.1.0",
4 | "engines": {
5 | "node": ">=0.6.0"
6 | },
7 | "scripts": {
8 | "build": "grunt build",
9 | "test": "grunt qunit"
10 | },
11 | "dependencies": {
12 | "grunt": "0.4.x",
13 | "grunt-requirejs": "0.3.x",
14 | "grunt-contrib-jshint": "0.1.x",
15 | "grunt-contrib-qunit": "0.1.x"
16 | },
17 | "amd": {},
18 | "volo": {
19 | "baseUrl": "www/js/lib",
20 | "dependencies": {
21 | "jquery": "github:jquery/jquery/1.7.2"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/multipage/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test Suite
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/multipage/tests/index-dist.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test Suite
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/libglobal/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test Suite
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/test/fixtures/expected_sourcemap.txt:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"requirejs-sourcemaps.js","sources":["../test/fixtures/hello.js","../test/fixtures/world.js","../test/fixtures/project.js"],"names":[],"mappings":"AACA,KAAA,gFCAA,KAAA,gFCAA,SAAA,QAAA,SAAA,SAAA,EAAA,GACA,QAAA,IAAA,EAAA,KAGA,OAAA,UAAA","sourcesContent":["\neval(\"define(\\'hello\\',[],function(){return \\\"hello\\\";});\\n\\n//# sourceURL=/hello.js\");\n","\neval(\"define(\\'world\\',[],function(){return \\\"world\\\";});\\n\\n//# sourceURL=/world.js\");\n","\nrequire(['hello', 'world'], function(hello, world) {\n console.log(hello,world);\n});\n\ndefine(\"project\", function(){});\n"]}
--------------------------------------------------------------------------------
/docs/sourcemaps.md:
--------------------------------------------------------------------------------
1 | # Sourcemaps
2 |
3 | Sourcemaps can be used like described in the [requirejs docs](http://requirejs.org/docs/optimization.html#sourcemaps)
4 |
5 | Note: Make sure to set the optimize property to ´uglify2´!
6 |
7 | ## Example
8 |
9 | ```javascript
10 | requirejs: {
11 | mysourcemapped: {
12 | options: {
13 | baseUrl: 'my/project',
14 | name: 'project',
15 | out: 'dist/main-sourcemapped.js',
16 | optimize: 'uglify2',
17 | generateSourceMaps: true,
18 | preserveLicenseComments: false,
19 | useSourceUrl: true
20 | }
21 | },
22 | ```
23 |
--------------------------------------------------------------------------------
/examples/libglobal/tests/index-dist-amd.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Test Suite - Dist AMD
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/examples/libglobal/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-requirejs-libglobal-example",
3 | "version": "0.1.0",
4 | "engines": {
5 | "node": ">=0.6.0"
6 | },
7 | "scripts": {
8 | "build": "grunt build",
9 | "test": "grunt qunit"
10 | },
11 | "dependencies": {
12 | "grunt": ">=0.4.x"
13 | },
14 | "amd": {},
15 | "volo": {
16 | "baseUrl": "lib",
17 | "dependencies": {
18 | "jquery": "github:jquery/jquery/1.8.0",
19 | "underscore": "github:amdjs/underscore/1.3.3"
20 | }
21 | },
22 | "devDependencies": {
23 | "grunt-contrib-jshint": "~0.1.0",
24 | "grunt-contrib-qunit": "~0.1.0"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/common.js:
--------------------------------------------------------------------------------
1 | //The build will inline common dependencies into this file.
2 |
3 | //For any third party dependencies, like jQuery, place them in the lib folder.
4 |
5 | //Configure loading modules from the lib directory,
6 | //except for 'app' ones, which are in a sibling
7 | //directory.
8 | requirejs.config({
9 | baseUrl: 'js/lib',
10 | paths: {
11 | app: '../app'
12 | },
13 | shim: {
14 | backbone: {
15 | deps: ['jquery', 'underscore'],
16 | exports: 'Backbone'
17 | },
18 | underscore: {
19 | exports: '_'
20 | }
21 | }
22 | });
23 |
--------------------------------------------------------------------------------
/test/fixtures/replaceConditionalComments.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Testing
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/examples/multipage-shim/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-requirejs-multipageshim-example",
3 | "version": "0.1.0",
4 | "engines": {
5 | "node": ">=0.6.0"
6 | },
7 | "scripts": {
8 | "build": "grunt build",
9 | "test": "grunt qunit"
10 | },
11 | "dependencies": {
12 | "grunt": "0.4.x",
13 | "grunt-requirejs": "0.3.x",
14 | "grunt-contrib-jshint": "0.1.x",
15 | "grunt-contrib-qunit": "0.1.x"
16 | },
17 | "amd": {},
18 | "volo": {
19 | "baseUrl": "www/js/lib",
20 | "dependencies": {
21 | "jquery": "github:jquery/jquery/1.8.0",
22 | "underscore": "github:documentcloud/underscore/1.3.3",
23 | "backbone": "github:documentcloud/backbone/0.9.2"
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/test/fixtures/replaceInDjangoTemplates.html:
--------------------------------------------------------------------------------
1 | {% load static %}
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Testing
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/examples/multipage-shim/www/js/app/main1.js:
--------------------------------------------------------------------------------
1 | define(function (require) {
2 | var $ = require('jquery'),
3 | lib = require('./lib'),
4 | controller = require('./controller/c1'),
5 | model = require('./model/m1'),
6 | backbone = require('backbone'),
7 | underscore = require('underscore');
8 |
9 | //A fabricated API to show interaction of
10 | //common and specific pieces.
11 | controller.setModel(model);
12 | $(function () {
13 | controller.render(lib.getBody());
14 |
15 | //Display backbone and underscore versions
16 | $('body')
17 | .append('backbone version: ' + backbone.VERSION + '
')
18 | .append('underscore version: ' + underscore.VERSION + '
');
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/docs/customrjs.md:
--------------------------------------------------------------------------------
1 | # Using custom r.js versions
2 |
3 | Normally, grunt-requirejs instruments the latest r.js version to build your project.
4 | If you need to build your project against an older r.js version, you can do so by adding
5 | the special ´rjs´ option.
6 |
7 | ## Options
8 |
9 | ### rjs ```string``` (optional)
10 |
11 | This is used to define a path to a custom r.js version
12 |
13 | If you´re custom requirejs npm module is stored under ```node_modules/requirejs```,
14 | the rjs property should point to that folder.
15 |
16 |
17 | ## Example
18 |
19 | ```javascript
20 | requirejs: {
21 | mysourcemapped: {
22 | options: {
23 | rjs: '/path/to/my/custom/requirejs/version'
24 | baseUrl: 'my/project',
25 | name: 'project',
26 | out: 'dist/main-sourcemapped.js'
27 | }
28 | },
29 | ```
30 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 asciidisco
2 |
3 | Permission is hereby granted, free of charge, to any person
4 | obtaining a copy of this software and associated documentation
5 | files (the "Software"), to deal in the Software without
6 | restriction, including without limitation the rights to use,
7 | copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the
9 | Software is furnished to do so, subject to the following
10 | conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 | OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/test/fixtures/requirejs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "requirejs",
3 | "description": "Node adapter for RequireJS, for loading AMD modules. Includes RequireJS optimizer",
4 | "version": "2.0.6",
5 | "homepage": "http://github.com/jrburke/r.js",
6 | "author": {
7 | "name": "James Burke",
8 | "email": "jrburke@gmail.com",
9 | "url": "http://github.com/jrburke"
10 | },
11 | "licenses": [
12 | {
13 | "type": "BSD",
14 | "url": "https://github.com/jrburke/r.js/blob/master/LICENSE"
15 | },
16 | {
17 | "type": "MIT",
18 | "url": "https://github.com/jrburke/r.js/blob/master/LICENSE"
19 | }
20 | ],
21 | "main": "./bin/r.js",
22 | "bin": {
23 | "r.js": "./bin/r.js"
24 | },
25 | "engines": {
26 | "node": ">=0.4.0"
27 | },
28 | "readme": "# requirejs\n\nRequireJS for use in Node. includes:\n\n* r.js: the RequireJS optimizer, and AMD runtime for use in Node.\n* require.js: The browser-based AMD loader.\n\nMore information at http://requirejs.org\n\n",
29 | "_id": "requirejs@2.0.6",
30 | "dist": {
31 | "shasum": "bc6dd244aa638185cf63698692f739a7c89d296c"
32 | },
33 | "_from": "requirejs@2.0.x"
34 | }
35 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "grunt-requirejs",
3 | "description": "Building require.js based applications with grunt",
4 | "version": "0.4.2",
5 | "homepage": "https://github.com/asciidisco/grunt-requirejs",
6 | "author": {
7 | "name": "Sebastian Golasch",
8 | "email": "public@asciidisco.com"
9 | },
10 | "repository": {
11 | "type": "git",
12 | "url": "http://github.com/asciidisco/grunt-requirejs"
13 | },
14 | "bugs": {
15 | "url": "https://github.com/asciidisco/grunt-requirejs/issues"
16 | },
17 | "licenses": [
18 | {
19 | "type": "MIT",
20 | "url": "https://github.com/asciidisco/grunt-requirejs/blob/master/LICENSE-MIT"
21 | }
22 | ],
23 | "main": "Grunfile.js",
24 | "engines": {
25 | "node": ">=0.8.0"
26 | },
27 | "scripts": {
28 | "test": "grunt --verbose"
29 | },
30 | "dependencies": {
31 | "requirejs": "2.1.x",
32 | "cheerio": "0.13.x",
33 | "almond": "0.2.x",
34 | "gzip-js": "0.3.x",
35 | "q": "0.8.x"
36 | },
37 | "devDependencies": {
38 | "grunt": "~0.4.0",
39 | "grunt-contrib-clean": "~0.4.0",
40 | "grunt-contrib-copy": "~0.4.0",
41 | "grunt-contrib-jshint": "~0.1.1",
42 | "grunt-contrib-nodeunit": "~0.1.2",
43 | "grunt-contrib-qunit": "~0.1.1",
44 | "semver": "~1.1.4",
45 | "grunt-complexity": "~0.1.3",
46 | "grunt-plato": "~0.2.1"
47 | },
48 | "peerDependencies": {
49 | "grunt": "~0.4.0"
50 | },
51 | "keywords": [
52 | "gruntplugin",
53 | "requirejs"
54 | ]
55 | }
56 |
--------------------------------------------------------------------------------
/lib/helper/rjsversion.js:
--------------------------------------------------------------------------------
1 | /*
2 | * grunt-require
3 | * https://github.com/asciidisco/grunt-requirejs
4 | *
5 | * Copyright (c) 2012 asciidisco
6 | * Licensed under the MIT license.
7 | */
8 |
9 | exports.init = function(grunt) {
10 | 'use strict';
11 |
12 | var fs = require('fs');
13 | var exports = {};
14 |
15 | // privates
16 | var isDefaultVersion = true;
17 | var requirejs = null;
18 |
19 | // Returns a requirejs instance
20 | exports.getRequirejs = function(config) {
21 | var defaultRequire = require('requirejs');
22 |
23 | // check if we should load a custom requirejs version
24 | if (config.rjs) {
25 | var rjsPathname = config.rjs + '/bin/r.js';
26 |
27 | // check if the custom version is available, then load & return the
28 | // custom version, else default to the standard bundled requirejs
29 | if (fs.existsSync(rjsPathname)) {
30 | requirejs = require(rjsPathname);
31 | isDefaultVersion = false;
32 | return requirejs;
33 | }
34 |
35 | }
36 |
37 | isDefaultVersion = true;
38 | requirejs = defaultRequire;
39 | return requirejs;
40 | };
41 |
42 | // Returns the version number of the currently used requirejs library
43 | exports.getRequirejsVersionInfo = function() {
44 | return requirejs.version;
45 | };
46 |
47 | // Returns a boolean flag that determines if we´re using
48 | // the default bundled version or a user defined custom requirejs version
49 | exports.isCustomLibrary = function() {
50 | return !isDefaultVersion;
51 | };
52 |
53 | return exports;
54 | };
55 |
--------------------------------------------------------------------------------
/examples/libglobal/tests/principium-tests.js:
--------------------------------------------------------------------------------
1 | /*global require, define, test, expect, strictEqual, location */
2 |
3 | if (typeof require === 'function' && require.config) {
4 | require.config({
5 | baseUrl: '../lib',
6 | paths: {
7 | //Path relative to baseUrl
8 | 'principium': '../principium'
9 | },
10 | shim: {
11 | 'underscore': {
12 | exports: '_'
13 | }
14 | }
15 | });
16 |
17 | //Override if in "dist" mode
18 | if (location.href.indexOf('-dist') !== -1) {
19 | //Set location of principium to the dist location
20 | require.config({
21 | paths: {
22 | 'principium': '../dist/principium'
23 | }
24 | });
25 | }
26 | }
27 |
28 | (function (root, factory) {
29 | 'use strict';
30 |
31 | if (typeof define === 'function' && define.amd) {
32 | // AMD.
33 | define(['principium', 'jquery'], factory);
34 | } else {
35 | // Browser globals
36 | factory(root.principium, root.jQuery);
37 | }
38 | }(this, function (principium, $) {
39 | 'use strict';
40 |
41 | test('version test', function () {
42 | expect(1);
43 | strictEqual(principium.version,
44 | '0.0.1, jQuery version is: ' + $.fn.jquery,
45 | 'Version concatenated');
46 | });
47 |
48 | test('conversion test', function () {
49 | expect(1);
50 | strictEqual(principium.convert('Harry & Sally'),
51 | 'Harry & Sally',
52 | 'Ampersand converted');
53 | });
54 | }));
55 |
--------------------------------------------------------------------------------
/tasks/require.js:
--------------------------------------------------------------------------------
1 | /*
2 | * grunt-requirejs
3 | * https://github.com/asciidisco/grunt-requirejs
4 | *
5 | * Copyright (c) 2012 Sebastian Golasch, contributors
6 | * Licensed under the MIT license.
7 | */
8 |
9 | module.exports = function (grunt) {
10 | 'use strict';
11 |
12 | // External libs.
13 | var Q = require('q');
14 |
15 | // Path to internal libs
16 | var intLibPath = '../lib/';
17 |
18 | // Internal libs.
19 | var errorHandler = require(intLibPath + 'helper/errorhandler')(grunt);
20 | var optimize = require(intLibPath + 'optimize').init(grunt);
21 | var almondify = require(intLibPath + 'almondify').init(grunt);
22 | var replaceAlmondInHtmlFiles = require(intLibPath + 'replace').init(grunt);
23 |
24 | // requirejs Multitask
25 | // runs a promises chain of helper libraries
26 | // the order of the helper libraries is important
27 | // each helper runs independent & has no dependencies on the other helpers
28 | grunt.registerMultiTask('requirejs', 'Runs requirejs optimizer', function() {
29 | var done = this.async();
30 |
31 | // The functions only accept the plugin
32 | // config as a parameter & only return the config.
33 | // The functions might modify the config during
34 | // the run or add arbitary data.
35 | // Calls ´done´ when all chain is comletely executed
36 | // Calls the ´errorhandler if an error occures during the build
37 | Q.fcall(almondify, this.options())
38 | .then(optimize)
39 | .then(replaceAlmondInHtmlFiles)
40 | .then(this.data.cb || function () {})
41 | .fail(errorHandler.bind({done: done}))
42 | .fin(done)
43 | .done();
44 |
45 | });
46 |
47 | };
48 |
--------------------------------------------------------------------------------
/examples/libglobal/Gruntfile.js:
--------------------------------------------------------------------------------
1 | /*global module:false*/
2 | module.exports = function(grunt) {
3 |
4 | // replace this line with
5 | // grunt.loadNpmTasks("grunt-requirejs");
6 | // if you use this example standalone
7 | grunt.loadTasks("../../tasks");
8 |
9 | grunt.initConfig({
10 |
11 | qunit: {
12 | all: ['tests/*.html']
13 | },
14 |
15 | requirejs: {
16 | std: {
17 | options: {
18 | almond: true,
19 | baseUrl: 'lib',
20 | paths: {
21 | principium: '../principium'
22 | },
23 | include: ['principium'],
24 | exclude: ['jquery', 'underscore'],
25 | out: 'dist/principium.js',
26 | wrap: {
27 | startFile: 'wrap/wrap.start',
28 | endFile: 'wrap/wrap.end'
29 | }
30 | }
31 | }
32 | },
33 |
34 | jshint: {
35 | options: {
36 | curly: true,
37 | eqeqeq: true,
38 | immed: true,
39 | latedef: true,
40 | newcap: true,
41 | noarg: true,
42 | sub: true,
43 | undef: true,
44 | eqnull: true,
45 | browser: true,
46 | nomen: true,
47 | globals: {
48 | define: true,
49 | jQuery: true
50 | }
51 | },
52 | files: ['principium/*.js', 'principium.js']
53 | }
54 | });
55 |
56 | grunt.loadNpmTasks('grunt-contrib-jshint');
57 | grunt.loadNpmTasks('grunt-contrib-qunit');
58 |
59 | grunt.registerTask('default', ['jshint', 'qunit']);
60 | grunt.registerTask('build', 'requirejs');
61 | };
62 |
--------------------------------------------------------------------------------
/examples/multipage/tests/tests.js:
--------------------------------------------------------------------------------
1 | /*global require, define, test, expect, strictEqual, location */
2 |
3 | if (typeof require === 'function' && require.config) {
4 | require.config({
5 | baseUrl: '../www/js',
6 | paths: {
7 | //Path relative to baseUrl
8 | 'jquery': 'lib/jquery'
9 | }
10 | });
11 |
12 | //Override if in "dist" mode
13 | if (location.href.indexOf('-dist') !== -1) {
14 | //Set location of principium to the dist location
15 | require.config({
16 | baseUrl: '../www-built/js'
17 | });
18 | }
19 | }
20 |
21 | (function (root, factory) {
22 | 'use strict';
23 | define(['jquery', 'app/model/Base', 'app/model/m1', 'app/model/m2', 'app/controller/c1', 'app/controller/c2'], factory);
24 | }(this, function ($, Base, m1, m2, c1, c2) {
25 | 'use strict';
26 |
27 | test('base model test', function () {
28 | var base = new Base('Can set title');
29 | expect(1);
30 | strictEqual(base.getTitle(), 'Can set title', 'Can set title');
31 | });
32 |
33 | test('title for page1 can be set', function () {
34 | expect(1);
35 | strictEqual(m1.getTitle(), 'This is the data for Page 1', 'title for page1 can be set');
36 | });
37 |
38 | test('title for page2 can be set', function () {
39 | expect(1);
40 | strictEqual(m2.getTitle(), 'This is the data for Page 2', 'title for page2 can be set');
41 | });
42 |
43 | test('html for page1 can be generated', function () {
44 | expect(1);
45 | c1.setModel(m1);
46 | c1.render($('#qunit-fixture'));
47 | strictEqual($('#qunit-fixture').text(), 'Controller Controller 1 says "This is the data for Page 1"', 'html for page1 can be set');
48 | });
49 |
50 | test('html for page2 can be generated', function () {
51 | expect(1);
52 | c2.setModel(m2);
53 | c2.render($('#qunit-fixture'));
54 | strictEqual($('#qunit-fixture').text(), 'Controller Controller 2 says "This is the data for Page 2"', 'html for page2 can be set');
55 | });
56 |
57 | }));
58 |
--------------------------------------------------------------------------------
/lib/almondify.js:
--------------------------------------------------------------------------------
1 | /*
2 | * grunt-requirejs
3 | * https://github.com/asciidisco/grunt-requirejs
4 | *
5 | * Copyright (c) 2012 Sebastian Golasch, contributors
6 | * Licensed under the MIT license.
7 | */
8 |
9 | exports.init = function(grunt) {
10 | 'use strict';
11 |
12 | // External libs.
13 | var fs = require('fs');
14 | // TODO: ditch this when grunt 0.4.0 is out
15 | var util = grunt.util;
16 |
17 | // Prepare the auto insertion of the almond library
18 | // by modifying the users config
19 | return function(config) {
20 | var configClone = util._.clone(config);
21 | var moduleIterator = configClone.modules;
22 |
23 | // check if we should inline almond
24 | if (config.almond === true) {
25 |
26 | // log that we´re including almond
27 | grunt.verbose.writeln('Including almond.js');
28 |
29 | // prepare the paths object (in case it hasn´t been set yet)
30 | configClone.paths = configClone.paths || {};
31 |
32 | // set almond path
33 | configClone.paths.almond = require.resolve('almond').replace(/\.js$/, '');
34 |
35 | // check if the 'removeCombined' option is enabled
36 | // then use a temporary almond file to ensure that the
37 | // almond.js source file doesn´t get deleted
38 | if (config.removeCombined === true) {
39 | configClone.__origAlmond = String(fs.readFileSync(configClone.paths.almond + '.js'));
40 | }
41 |
42 | // modify modules data
43 | if (!util._.isArray(moduleIterator)) {
44 | moduleIterator = [{name: config.name}];
45 |
46 | if (!util._.isArray(configClone.include)) {
47 | configClone.include = [configClone.name];
48 | } else {
49 | configClone.include.unshift(configClone.name);
50 | }
51 |
52 | configClone.name = 'almond';
53 | }
54 |
55 | // modify modules data
56 | moduleIterator.forEach(function(module, idx) {
57 | // log adding of almond to a specific module
58 | grunt.verbose.writeln('Adding almond to module: ' + module.name);
59 |
60 | // check if the module has its own includes
61 | // then append almond to them
62 | // else generate a new includes property
63 | if (util._.isArray(module.include)) {
64 | configClone.modules[idx].include.unshift('almond');
65 | } else {
66 | if (!util._.isUndefined(configClone.modules)) {
67 | configClone.modules[idx].include = ['almond'];
68 | }
69 | }
70 |
71 | });
72 |
73 | }
74 |
75 | return configClone;
76 | };
77 | };
78 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to grunt-requirejs
2 |
3 | ## Filing issues
4 | If something isn't working like you think it should, please read the documentation first.
5 |
6 | The best way to ensure an issue gets addressed is to file it in the appropriate issues tracker.
7 |
8 | ### Simplify the issue
9 | Try to [reduce your code](http://www.webkit.org/quality/reduction.html) to the bare minimum required to reproduce the issue. This makes it much easier (and much faster) to isolate and fix the issue.
10 |
11 | ### Explain the issue
12 | If we can't reproduce the issue, we can't fix it. Please list the exact steps required to reproduce the issue. Include versions of your OS, Node.js, grunt, etc. Include relevant logs or sample code.
13 |
14 | ## Modifying grunt-requirejs
15 | First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.
16 |
17 | 1. Fork and clone the repo.
18 | 2. Check out the correct branch. Currently, the development happens in the `devel` branch.
19 | 3. Run `npm install` to install all grunt-requirejs dependencies.
20 | 4. Run `grunt travis` to test & lint the plugin.
21 |
22 | Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing breaks.
23 |
24 | ### Submitting pull requests
25 |
26 | 1. Create a new branch, please don't work in your `master` or `devel` branch directly.
27 | 2. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
28 | 3. Fix stuff.
29 | 4. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
30 | 5. Update the documentation to reflect any changes.
31 | 6. Push to your fork and submit a pull request.
32 |
33 | ### Adding tests
34 | Tests are written in NodeUnit & QUnit style.
35 | NodeUnit tests can be run using the ´grunt test´ command.
36 | The tests from the examples directory can be run using ´grunt qunit´, but make sure
37 | you are running ´grunt setUp´ before & ´grunt tearDown´ afterwards.
38 |
39 | ### Syntax
40 |
41 | * Two space indents. Don't use tabs anywhere. Use `\t` if you need a tab character in a string.
42 | * No trailing whitespace, except in markdown files where a linebreak must be forced.
43 | * Don't go overboard with the whitespace.
44 | * No more than [one assignment](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) per `var` statement.
45 | * Delimit strings with single-quotes `'`, not double-quotes `"`.
46 | * Prefer `if` and `else` to ["clever"](http://programmers.stackexchange.com/a/25281) uses of `? :` conditional or `||`, `&&` logical operators.
47 | * Comments are great. Just put them _before_ the line of code, _not_ at the _end_ of the line.
48 | * **When in doubt, follow the conventions you see used in the source already.**
49 |
--------------------------------------------------------------------------------
/lib/replace.js:
--------------------------------------------------------------------------------
1 | /*
2 | * grunt-requirejs
3 | * https://github.com/asciidisco/grunt-requirejs
4 | *
5 | * Copyright (c) 2012 Sebastian Golasch, contributors
6 | * Licensed under the MIT license.
7 | */
8 |
9 | exports.init = function(grunt) {
10 | 'use strict';
11 |
12 | // External libs.
13 | var Q = require('q');
14 | var cheerio = require('cheerio');
15 | var util = grunt.util;
16 |
17 | return function(config) {
18 | var deferred = Q.defer();
19 |
20 | // exit early if we're not replacing scripts
21 | if(!(config.replaceRequireScript instanceof Array) || !config.replaceRequireScript.length) {
22 | return config;
23 | }
24 |
25 | // iterate over all modules that are configured for replacement
26 | config.replaceRequireScript.forEach(function (file, idx) {
27 | var files = grunt.file.expand(file.files);
28 | var filesEvaluated = 0;
29 | var filesToEvaluate = files.length;
30 | var modulePath = file.modulePath;
31 |
32 | // iterate over found html files
33 | files.forEach(function (file) {
34 | // load file contents
35 | var contents = String(grunt.file.read(file, 'utf-8'));
36 | // reference to script regex https://github.com/jquery/jquery/blob/1.7.2/src/ajax.js#L14
37 | var script_re = /') > -1, 'should replace script tag ´src´ contents');
170 | test.done();
171 | });
172 | },
173 |
174 | 'requirejs script tag can be replaced with almondified script tag with no doctype declared (#59)': function(test) {
175 | 'use strict';
176 | test.expect(1);
177 | var config = {
178 | replaceRequireScript: [{
179 | files: ['tmp/replaceSingleAlmondNoDocType.html'],
180 | module: 'main'
181 | }],
182 | modules: [{name: 'main'}],
183 | almond: true
184 | };
185 |
186 | grunt.file.copy('test/fixtures/replaceSingleAlmondNoDocType.html', 'tmp/replaceSingleAlmondNoDocType.html');
187 | replaceAlmondInHtmlFiles(config).then(function() {
188 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
189 | test.ok(replacedFileContents.search('') > -1, 'should replace script tag ´src´ contents');
190 | test.done();
191 | });
192 | },
193 |
194 | 'requirejs script tag can be replaced with almondified script tag & leaves attributes': function(test) {
195 | 'use strict';
196 | test.expect(1);
197 | var config = {
198 | replaceRequireScript: [{
199 | files: ['tmp/replaceSingleAlmondWithAttr.html'],
200 | module: 'main'
201 | }],
202 | modules: [{name: 'main'}],
203 | almond: true
204 | };
205 |
206 | grunt.file.copy('test/fixtures/replaceSingleAlmondWithAttr.html', 'tmp/replaceSingleAlmondWithAttr.html');
207 | replaceAlmondInHtmlFiles(config).then(function() {
208 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
209 | test.ok(replacedFileContents.search('') > -1, 'should replace script tag ´src´ contents, but leaves the other attrs alone');
210 | test.done();
211 | });
212 | },
213 |
214 | 'requirejs script tag can be replaced with almondified script tag & leaves weird attributes': function(test) {
215 | 'use strict';
216 | test.expect(1);
217 | var config = {
218 | replaceRequireScript: [{
219 | files: ['tmp/replaceSingleAlmondWithComplexAttr.html'],
220 | module: 'main'
221 | }],
222 | modules: [{name: 'main'}],
223 | almond: true
224 | };
225 |
226 | grunt.file.copy('test/fixtures/replaceSingleAlmondWithComplexAttr.html', 'tmp/replaceSingleAlmondWithComplexAttr.html');
227 | replaceAlmondInHtmlFiles(config).then(function() {
228 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
229 | test.ok(replacedFileContents.search('') > -1, 'should replace script tag ´src´ contents, but leaves the other (complex) attrs alone');
230 | test.done();
231 | });
232 | },
233 |
234 | 'multiple requirejs script tags can be replaced with almondified script tags': function(test) {
235 | 'use strict';
236 | test.expect(2);
237 | var config = {
238 | replaceRequireScript: [{
239 | files: ['tmp/replaceMultiAlmond.html'],
240 | module: ['module1', 'module2']
241 | }],
242 | modules: [{name: 'module1'}, {name: 'module2'}],
243 | almond: true
244 | };
245 |
246 | grunt.file.copy('test/fixtures/replaceMultiAlmond.html', 'tmp/replaceMultiAlmond.html');
247 | replaceAlmondInHtmlFiles(config).then(function() {
248 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
249 | test.ok(replacedFileContents.search('') > -1, 'should replace multiple script tag ´src´ contents, but leaves the other attrs alone');
250 | test.ok(replacedFileContents.search('') > -1, 'should replace multiple script tag ´src´ contents, but leaves the other attrs alone');
251 | test.done();
252 | });
253 | },
254 |
255 | 'requirejs script tag can be replaced with almondified script tag in multiple files': function(test) {
256 | 'use strict';
257 | test.expect(2);
258 | var config = {
259 | replaceRequireScript: [{
260 | files: ['tmp/multi1.html', 'tmp/multi2.html'],
261 | module: 'main'
262 | }],
263 | modules: [{name: 'main'}],
264 | almond: true
265 | };
266 |
267 | grunt.file.copy('test/fixtures/replaceSingleAlmond.html', 'tmp/multi1.html');
268 | grunt.file.copy('test/fixtures/replaceSingleAlmond.html', 'tmp/multi2.html');
269 | replaceAlmondInHtmlFiles(config).then(function() {
270 | var replacedFileContents1 = grunt.file.read(config.replaceRequireScript[0].files[0]);
271 | var replacedFileContents2 = grunt.file.read(config.replaceRequireScript[0].files[1]);
272 | test.ok(replacedFileContents1.search('') > -1, 'should replace script tag ´src´ contents');
273 | test.ok(replacedFileContents2.search('') > -1, 'should replace script tag ´src´ contents');
274 | test.done();
275 | });
276 | },
277 |
278 | 'requirejs script tag should be replaced without HTML/BODY elements when the file contains a fragment': function(test) {
279 | 'use strict';
280 | test.expect(1);
281 | var config = {
282 | replaceRequireScript: [{
283 | files: ['tmp/replaceSingleAlmondDocFragment.html'],
284 | module: 'main'
285 | }],
286 | modules: [{name: 'main'}],
287 | almond: true
288 | };
289 |
290 | grunt.file.copy('test/fixtures/replaceSingleAlmondDocFragment.html', 'tmp/replaceSingleAlmondDocFragment.html');
291 | replaceAlmondInHtmlFiles(config).then(function() {
292 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
293 | test.ok(replacedFileContents.trim() === '', 'should replace src attribute, and the resulting HTML only contains a script tag');
294 | test.done();
295 | });
296 | },
297 |
298 | 'using removeCombined option with almond doesnt touch original almond file': function(test) {
299 | 'use strict';
300 | var result;
301 | test.expect(1);
302 | result = grunt.file.read('node_modules/almond/almond.js');
303 | test.ok(result.length > 0, 'original almond.js should still be there');
304 | test.done();
305 | },
306 |
307 | 'requirejs script tag should be replaced without messing with conditional html': function(test) {
308 | 'use strict';
309 | test.expect(2);
310 | var config = {
311 | replaceRequireScript: [{
312 | files: ['tmp/replaceConditionalComments.html'],
313 | module: 'main'
314 | }],
315 | modules: [{name: 'main'}],
316 | almond: true
317 | };
318 |
319 | grunt.file.copy('test/fixtures/replaceConditionalComments.html', 'tmp/replaceConditionalComments.html');
320 | replaceAlmondInHtmlFiles(config).then(function() {
321 | var replacedFileContents = grunt.file.read(config.replaceRequireScript[0].files[0]);
322 | test.ok(replacedFileContents.search('') > -1, 'should replace script tag ´src´ contents');
323 | test.ok(replacedFileContents.search('