Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
grunt-monty-python
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
32d88eb1
authored
2015-09-28 10:29:00 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
requirejs-config now contains a single function.
1 parent
1c48ec40
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
25 deletions
grunt-monty-python.js
grunt-monty-python.js
View file @
32d88eb
...
...
@@ -44,16 +44,14 @@ module.exports = function (grunt) {
grunt
.
registerTask
(
'fixRequireConfig'
,
function
fixRequireConfig
()
{
var
config
=
grunt
.
config
(
'montyPython.config'
);
var
featureFlags
=
grunt
.
config
(
'montyPython.featureFlags'
);
var
lines
,
segments
=
[]
;
var
segment
=
{},
segments
=
{}
;
// ---
if
(
config
.
useRev
)
{
var
prefix
=
grunt
.
template
.
process
(
'dist/build/scripts/'
);
var
pattern
=
prefix
+
'**/*.{js,html}'
;
var
files
=
grunt
.
file
.
expand
(
pattern
);
lines
=
[
'(function(container) {'
,
];
if
(
files
.
length
)
{
_
.
each
(
files
,
function
(
file
)
{
file
=
file
.
substring
(
prefix
.
length
);
var
res
=
file
.
match
(
/^
(
.*
\/)?([
0-9a-f
]
+
)\.([^\/]
+
)\.([^\.]
+
)
$/
);
...
...
@@ -73,21 +71,21 @@ module.exports = function (grunt) {
id
=
'text!'
+
dir
+
base
+
'.'
+
ext
;
}
grunt
.
log
.
oklns
(
'map: '
+
id
+
' -> '
+
file
);
lines
.
push
(
'container['
+
JSON
.
stringify
(
id
)
+
']='
+
JSON
.
stringify
(
file
)
+
';\n'
)
;
segment
[
id
]
=
file
;
});
if
(
lines
.
length
>
1
)
{
lines
.
push
(
'})(require.paths);'
);
segments
=
segments
.
concat
(
lines
);
lines
=
null
;
segments
.
paths
=
segment
;
segment
=
{};
}
}
// ---
var
requireModules
=
grunt
.
config
(
'requireModules.requirejs'
)
||
{};
/*
lines = [
'(function(container, propName) {',
'container = (container[propName] = container[propName] || {});',
];
*/
for
(
var
key
in
requireModules
)
{
var
keyS
=
JSON
.
stringify
(
key
);
var
value
=
requireModules
[
key
];
...
...
@@ -98,28 +96,41 @@ module.exports = function (grunt) {
included
.
push
(
file
.
substring
(
0
,
file
.
length
-
3
));
}
}
lines
.
push
(
'container['
+
keyS
+
'] = '
+
JSON
.
stringify
(
included
)
+
';'
);
}
if
(
lines
.
length
>
2
)
{
lines
.
push
(
'})(require, \'bundles\');'
);
segments
=
segments
.
concat
(
lines
);
lines
=
null
;
segment
[
key
]
=
included
;
}
segments
.
bundles
=
segment
;
// ---
segments
[
'config.featureFlags'
]
=
featureFlags
;
var
notEmptyCount
=
0
;
_
.
each
(
segments
,
function
(
value
,
key
)
{
if
(
!
_
.
isEmpty
(
value
))
{
notEmptyCount
++
;
}
});
var
lines
;
if
(
notEmptyCount
)
{
lines
=
[
'(function(container, propName) {'
,
'container = (container[propName] = container[propName] || {});'
,
'(function(require, overlay) {'
,
' var prop, value, ptr, i, list, container;'
,
' for (prop in overlay) {'
,
' value = overlay[prop];'
,
' ptr = require;'
,
' list = split(".", prop);'
,
' for (i = 0; i < list.length; i++) {'
,
' if (!ptr[list[i]]) ptr[list[i]] = {};'
,
' ptr = ptr[list[i]];'
,
' }'
,
' for (prop in value) {'
,
' ptr[prop] = value[prop];'
,
' }'
,
' }'
,
'})(require, '
+
JSON
.
stringify
(
segments
)
+
');'
,
];
for
(
var
flag
in
featureFlags
)
{
lines
.
push
(
'container['
+
JSON
.
stringify
(
flag
)
+
']='
+
JSON
.
stringify
(
featureFlags
[
flag
])
+
';'
);
}
if
(
lines
.
length
>
2
)
{
lines
.
push
(
'})(require.config, \'featureFlags\');'
);
segments
=
segments
.
concat
(
lines
);
lines
=
null
;
}
else
{
lines
=
[];
}
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/requirejs-config.js'
,
segment
s
.
join
(
'\n'
));
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/requirejs-config.js'
,
line
s
.
join
(
'\n'
));
return
true
;
});
...
...
Please
register
or
sign in
to post a comment