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
83da0e2d
authored
2015-09-08 11:47:55 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixRequireConfig.
1 parent
e958f8b5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
47 deletions
grunt-monty-python.js
grunt-monty-python.js
View file @
83da0e2
...
...
@@ -40,9 +40,91 @@ module.exports = function (grunt) {
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/revconfig.js'
,
lines
.
join
(
''
));
});
grunt
.
registerTask
(
'fixRequireConfig'
,
function
fixRequireConfig
()
{
var
config
=
grunt
.
config
(
'montyPython.config'
);
var
featureFlags
=
grunt
.
config
(
'montyPython.featureFlags'
);
var
lines
,
segments
=
[];
// ---
if
(
config
.
useRev
)
{
var
prefix
=
grunt
.
template
.
process
(
'dist/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
}
}
// ---
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
];
var
included
=
[];
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
var
file
=
value
[
i
];
if
(
file
.
match
(
/
\.
js$/
))
{
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
;
}
// ---
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
;
}
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/requirejs-config.js'
,
segments
.
join
(
'\n'
));
return
true
;
});
function
createConfig
(
mpConfig
)
{
var
featureFlags
=
{};
var
holyGrailTmp
=
'.grunt/holygrail'
;
var
initConfig
=
{
clean
:
{
...
...
@@ -369,8 +451,7 @@ module.exports = function (grunt) {
dest
:
'dist/'
+
mpConfig
.
bower
.
directory
+
'/requirejs/require.js'
,
src
:
[
'src/scripts/config.js'
,
'.grunt/holygrail/scripts/revconfig.js'
,
'.grunt/holygrail/scripts/bundles.js'
,
'.grunt/holygrail/scripts/requirejs-config.js'
,
'src/'
+
mpConfig
.
bower
.
directory
+
'/requirejs/require.js'
,
],
}],
...
...
@@ -378,34 +459,7 @@ module.exports = function (grunt) {
initConfig
.
requirejs
=
{
dist
:
{
options
:
{
done
:
function
onDone
(
next
)
{
/* jshint devel:true */
var
target
=
grunt
.
task
.
current
.
target
;
var
requireModules
=
grunt
.
config
(
'requireModules.'
+
target
)
||
{};
var
lines
=
[
'(function(container, propName) {'
,
'container = (container[propName] = container[propName] || {});'
,
];
for
(
var
key
in
requireModules
)
{
var
keyS
=
JSON
.
stringify
(
key
);
var
value
=
requireModules
[
key
];
var
included
=
[];
for
(
var
i
=
0
;
i
<
value
.
length
;
i
++
)
{
var
file
=
value
[
i
];
if
(
file
.
match
(
/
\.
js$/
))
{
included
.
push
(
file
.
substring
(
0
,
file
.
length
-
3
));
}
}
lines
.
push
(
'container['
+
keyS
+
'] = '
+
JSON
.
stringify
(
included
)
+
';'
);
}
//lines.push('return bundles;');
lines
.
push
(
'})(require, \'bundles\');'
);
if
(
lines
.
length
==
3
)
{
lines
=
[];
}
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/bundles.js'
,
lines
.
join
(
'\n'
));
next
();
},
///* -jshint devel:true */
onModuleBundleComplete
:
function
onModuleBundleComplete
(
data
)
{
/* jshint devel:true */
...
...
@@ -437,6 +491,7 @@ module.exports = function (grunt) {
}
grunt
.
initConfig
(
initConfig
);
grunt
.
config
(
'montyPython.config'
,
mpConfig
);
grunt
.
registerTask
(
'check'
,
checkList
);
...
...
@@ -454,23 +509,8 @@ module.exports = function (grunt) {
for
(
var
i
in
arguments
)
{
featureFlags
[
'BUILD_'
+
arguments
[
i
].
toUpperCase
()]
=
true
;
}
grunt
.
registerTask
(
'writeFeatureFlags'
,
'write feature flags'
,
function
()
{
var
lines
=
[
'(function(container, propName) {'
,
'container = (container[propName] = container[propName] || {});'
,
];
for
(
var
flag
in
featureFlags
)
{
lines
.
push
(
'container['
+
JSON
.
stringify
(
flag
)
+
']='
+
JSON
.
stringify
(
featureFlags
[
flag
])
+
';'
);
}
//lines.push('return bundles;');
lines
.
push
(
'})(require.config, \'featureFlags\');'
);
if
(
lines
.
length
==
3
)
{
lines
=
[];
}
grunt
.
file
.
write
(
'.grunt/holygrail/scripts/featureFlags.js'
,
lines
.
join
(
'\n'
));
});
buildList
.
push
(
'writeFeatureFlags'
);
}
grunt
.
config
(
'montyPython.featureFlags'
,
featureFlags
);
if
(
mpConfig
.
punch
)
{
buildList
.
push
(
'punch:generate'
);
...
...
@@ -500,8 +540,8 @@ module.exports = function (grunt) {
if
(
mpConfig
.
useRev
)
{
buildList
.
push
(
'rev:dist'
);
// montyPython
buildList
.
push
(
'rev:css'
);
// montyPython
buildList
.
push
(
'revconfig'
);
// montyPython
}
buildList
.
push
(
'fixRequireConfig'
);
if
(
mpConfig
.
bower
)
{
buildList
.
push
(
'concat:requirejs'
);
// montyPython
}
...
...
Please
register
or
sign in
to post a comment