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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
47 deletions
grunt-monty-python.js
grunt-monty-python.js
View file @
32d88eb
...
...
@@ -44,50 +44,48 @@ 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) {'
,
];
_
.
each
(
files
,
function
(
file
)
{
file
=
file
.
substring
(
prefix
.
length
);
var
res
=
file
.
match
(
/^
(
.*
\/)?([
0-9a-f
]
+
)\.([^\/]
+
)\.([^\.]
+
)
$/
);
if
(
!
res
)
{
return
;
}
//grunt.log.oklns(JSON.stringify(res));
var
dir
=
res
[
1
]
||
''
;
//var hash = res[2];
var
base
=
res
[
3
];
var
ext
=
res
[
4
];
var
id
;
if
(
ext
===
'js'
)
{
id
=
dir
+
base
;
file
=
file
.
substring
(
0
,
file
.
length
-
ext
.
length
-
1
);
}
else
if
(
ext
===
'html'
)
{
id
=
'text!'
+
dir
+
base
+
'.'
+
ext
;
}
grunt
.
log
.
oklns
(
'map: '
+
id
+
' -> '
+
file
);
lines
.
push
(
'container['
+
JSON
.
stringify
(
id
)
+
']='
+
JSON
.
stringify
(
file
)
+
';\n'
);
});
if
(
lines
.
length
>
1
)
{
lines
.
push
(
'})(require.paths);'
);
segments
=
segments
.
concat
(
lines
);
lines
=
null
;
if
(
files
.
length
)
{
_
.
each
(
files
,
function
(
file
)
{
file
=
file
.
substring
(
prefix
.
length
);
var
res
=
file
.
match
(
/^
(
.*
\/)?([
0-9a-f
]
+
)\.([^\/]
+
)\.([^\.]
+
)
$/
);
if
(
!
res
)
{
return
;
}
//grunt.log.oklns(JSON.stringify(res));
var
dir
=
res
[
1
]
||
''
;
//var hash = res[2];
var
base
=
res
[
3
];
var
ext
=
res
[
4
];
var
id
;
if
(
ext
===
'js'
)
{
id
=
dir
+
base
;
file
=
file
.
substring
(
0
,
file
.
length
-
ext
.
length
-
1
);
}
else
if
(
ext
===
'html'
)
{
id
=
'text!'
+
dir
+
base
+
'.'
+
ext
;
}
grunt
.
log
.
oklns
(
'map: '
+
id
+
' -> '
+
file
);
segment
[
id
]
=
file
;
});
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
;
// ---
lines
=
[
'(function(container, propName) {'
,
'container = (container[propName] = container[propName] || {});'
,
];
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
;
segments
[
'config.featureFlags'
]
=
featureFlags
;
var
notEmptyCount
=
0
;
_
.
each
(
segments
,
function
(
value
,
key
)
{
if
(
!
_
.
isEmpty
(
value
))
{
notEmptyCount
++
;
}
});
var
lines
;
if
(
notEmptyCount
)
{
lines
=
[
'(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
)
+
');'
,
];
}
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