forked from OrchardCMS/OrchardCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Gulp support and Orchard.Resources module
- Loading branch information
1 parent
46accc1
commit f629b9d
Showing
96 changed files
with
18,984 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,4 +178,7 @@ nuget.exe | |
.nuget/ | ||
|
||
#enable all /lib artifacts | ||
!lib/*/*.* | ||
!lib/*/*.* | ||
|
||
#exclude node modules | ||
node_modules/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"private": true, | ||
"devDependencies": { | ||
"glob": "^5.0.14", | ||
"path-posix": "^1.0.0", | ||
"merge-stream": "^0.1.8", | ||
"gulp-if": "^1.2.5", | ||
"gulp": "^3.8.11", | ||
"gulp-newer": "^0.5.0", | ||
"gulp-plumber": "^1.0.1", | ||
"gulp-sourcemaps": "^1.5.2", | ||
"gulp-less": "^3.0.3", | ||
"gulp-sass": "^2.1.1", | ||
"gulp-autoprefixer": "^2.2.0", | ||
"gulp-minify-css": "^1.1.1", | ||
"gulp-typescript": "^2.8.0", | ||
"gulp-uglify": "^1.2.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-concat": "^2.5.2", | ||
"gulp-header": "^1.2.2", | ||
"fs": "^0.0.2" | ||
}, | ||
"dependencies": { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
var glob = require("glob"), | ||
path = require("path-posix"), | ||
merge = require("merge-stream"), | ||
gulpif = require("gulp-if"), | ||
gulp = require("gulp"), | ||
newer = require("gulp-newer"), | ||
plumber = require("gulp-plumber"), | ||
sourcemaps = require("gulp-sourcemaps"), | ||
less = require("gulp-less"), | ||
scss = require("gulp-sass"), | ||
autoprefixer = require("gulp-autoprefixer"), | ||
minify = require("gulp-minify-css"), | ||
typescript = require("gulp-typescript"), | ||
uglify = require("gulp-uglify"), | ||
rename = require("gulp-rename"), | ||
concat = require("gulp-concat"), | ||
header = require("gulp-header"), | ||
fs = require("fs"); | ||
|
||
/* | ||
** GULP TASKS | ||
*/ | ||
|
||
// Incremental build (each asset group is built only if one or more inputs are newer than the output). | ||
gulp.task("build", function () { | ||
var assetGroupTasks = getAssetGroups().map(function (assetGroup) { | ||
var doRebuild = false; | ||
return createAssetGroupTask(assetGroup, doRebuild); | ||
}); | ||
return merge(assetGroupTasks); | ||
}); | ||
|
||
// Full rebuild (all assets groups are built regardless of timestamps). | ||
gulp.task("rebuild", function () { | ||
var assetGroupTasks = getAssetGroups().map(function (assetGroup) { | ||
var doRebuild = true; | ||
return createAssetGroupTask(assetGroup, doRebuild); | ||
}); | ||
return merge(assetGroupTasks); | ||
}); | ||
|
||
|
||
// Set "Watchers" as sub-processes in order to restart the task when Assets.json changes. | ||
gulp.task("watch", function () { | ||
var watchers; | ||
function restart() { | ||
if (watchers) { | ||
watchers.forEach(function (w) { | ||
w.remove(); | ||
w.end(); | ||
}); | ||
} | ||
watchers = []; | ||
// Continuous watch (each asset group is built whenever one of its inputs changes). | ||
getAssetGroups().forEach(function (assetGroup) { | ||
var watchPaths = assetGroup.inputPaths.concat(assetGroup.watchPaths); | ||
var watcher = gulp.watch(watchPaths, function (event) { | ||
var isConcat = path.basename(assetGroup.outputFileName, path.extname(assetGroup.outputFileName)) !== "@"; | ||
if (isConcat) | ||
console.log("Asset file '" + event.path + "' was " + event.type + ", rebuilding asset group with output '" + assetGroup.outputPath + "'."); | ||
else | ||
console.log("Asset file '" + event.path + "' was " + event.type + ", rebuilding asset group."); | ||
var doRebuild = true; | ||
var task = createAssetGroupTask(assetGroup, doRebuild); | ||
}); | ||
watchers.push(watcher); | ||
}); | ||
} | ||
var p; | ||
if (p) { p.exit(); } | ||
p = gulp.watch("src/Orchard.Web/{Core,Modules,Themes}/*/Assets.json", function (event) { | ||
console.log("Asset file '" + event.path + "' was " + event.type + ", resetting asset watchers."); | ||
restart(); | ||
}); | ||
restart(); | ||
}); | ||
|
||
|
||
/* | ||
** ASSET GROUPS | ||
*/ | ||
function getAssetGroups() { | ||
var assetManifestPaths = glob.sync("src/Orchard.Web/{Core,Modules,Themes}/*/Assets.json", {}); | ||
var assetGroups = []; | ||
assetManifestPaths.forEach(function (assetManifestPath) { | ||
var file = './' + assetManifestPath; | ||
var json = fs.readFileSync(file, 'utf8'); | ||
assetManifest = eval(json); | ||
assetManifest.forEach(function (assetGroup) { | ||
resolveAssetGroupPaths(assetGroup, assetManifestPath); | ||
assetGroups.push(assetGroup); | ||
}); | ||
}); | ||
return assetGroups; | ||
} | ||
|
||
function resolveAssetGroupPaths(assetGroup, assetManifestPath) { | ||
assetGroup.basePath = path.dirname(assetManifestPath); | ||
assetGroup.inputPaths = assetGroup.inputs.map(function (inputPath) { | ||
return path.resolve(path.join(assetGroup.basePath, inputPath)); | ||
}); | ||
assetGroup.watchPaths = []; | ||
if (!!assetGroup.watch) { | ||
assetGroup.watchPaths = assetGroup.watch.map(function (watchPath) { | ||
return path.resolve(path.join(assetGroup.basePath, watchPath)); | ||
}); | ||
} | ||
assetGroup.outputPath = path.resolve(path.join(assetGroup.basePath, assetGroup.output)); | ||
assetGroup.outputDir = path.dirname(assetGroup.outputPath); | ||
assetGroup.outputFileName = path.basename(assetGroup.output); | ||
} | ||
|
||
function createAssetGroupTask(assetGroup, doRebuild) { | ||
var outputExt = path.extname(assetGroup.output).toLowerCase(); | ||
switch (outputExt) { | ||
case ".css": | ||
return buildCssPipeline(assetGroup, doRebuild); | ||
case ".js": | ||
return buildJsPipeline(assetGroup, doRebuild); | ||
} | ||
} | ||
|
||
/* | ||
** PROCESSING PIPELINES | ||
*/ | ||
|
||
function buildCssPipeline(assetGroup, doRebuild) { | ||
assetGroup.inputPaths.forEach(function (inputPath) { | ||
var ext = path.extname(inputPath).toLowerCase(); | ||
if (ext !== ".scss" && ext !== ".less" && ext !== ".css") | ||
throw "Input file '" + inputPath + "' is not of a valid type for output file '" + assetGroup.outputPath + "'."; | ||
}); | ||
var doConcat = path.basename(assetGroup.outputFileName, ".css") !== "@"; | ||
var generateSourceMaps = assetGroup.hasOwnProperty("generateSourceMaps") ? assetGroup.generateSourceMaps : true; | ||
return gulp.src(assetGroup.inputPaths) | ||
.pipe(gulpif(!doRebuild, | ||
gulpif(doConcat, | ||
newer(assetGroup.outputPath), | ||
newer({ | ||
dest: assetGroup.outputDir, | ||
ext: ".css" | ||
})))) | ||
.pipe(plumber()) | ||
.pipe(gulpif(generateSourceMaps, sourcemaps.init())) | ||
.pipe(gulpif("*.less", less())) | ||
.pipe(gulpif("*.scss", scss())) | ||
.pipe(gulpif(doConcat, concat(assetGroup.outputFileName))) | ||
.pipe(autoprefixer({ browsers: ["last 2 versions"] })) | ||
// TODO: Start using below whenever gulp-header supports sourcemaps. | ||
//.pipe(header( | ||
// "/*\n" + | ||
// "** NOTE: This file is generated by Gulp compilation and should not be edited directly!\n" + | ||
// "** Any changes made directly to this file will be overwritten next time the Gulp compilation runs.\n" + | ||
// "** For more information, see the Readme.txt file in the Gulp solution folder.\n" + | ||
// "*/\n\n")) | ||
.pipe(gulpif(generateSourceMaps, sourcemaps.write())) | ||
.pipe(gulp.dest(assetGroup.outputDir)) | ||
.pipe(minify()) | ||
.pipe(rename({ | ||
suffix: ".min" | ||
})) | ||
.pipe(gulp.dest(assetGroup.outputDir)); | ||
} | ||
|
||
function buildJsPipeline(assetGroup, doRebuild) { | ||
assetGroup.inputPaths.forEach(function (inputPath) { | ||
var ext = path.extname(inputPath).toLowerCase(); | ||
if (ext !== ".ts" && ext !== ".js") | ||
throw "Input file '" + inputPath + "' is not of a valid type for output file '" + assetGroup.outputPath + "'."; | ||
}); | ||
var doConcat = path.basename(assetGroup.outputFileName, ".js") !== "@"; | ||
var generateSourceMaps = assetGroup.hasOwnProperty("generateSourceMaps") ? assetGroup.generateSourceMaps : true; | ||
return gulp.src(assetGroup.inputPaths) | ||
.pipe(gulpif(!doRebuild, | ||
gulpif(doConcat, | ||
newer(assetGroup.outputPath), | ||
newer({ | ||
dest: assetGroup.outputDir, | ||
ext: ".js" | ||
})))) | ||
.pipe(plumber()) | ||
.pipe(gulpif(generateSourceMaps, sourcemaps.init())) | ||
.pipe(gulpif("*.ts", typescript({ | ||
declaration: false, | ||
//noImplicitAny: true, | ||
noEmitOnError: true, | ||
sortOutput: true, | ||
}).js)) | ||
.pipe(gulpif(doConcat, concat(assetGroup.outputFileName))) | ||
// TODO: Start using below whenever gulp-header supports sourcemaps. | ||
//.pipe(header( | ||
// "/*\n" + | ||
// "** NOTE: This file is generated by Gulp compilation and should not be edited directly!\n" + | ||
// "** Any changes made directly to this file will be overwritten next time the Gulp compilation runs.\n" + | ||
// "** For more information, see the Readme.txt file in the Gulp solution folder.\n" + | ||
// "*/\n\n")) | ||
.pipe(gulpif(generateSourceMaps, sourcemaps.write())) | ||
.pipe(gulp.dest(assetGroup.outputDir)) | ||
.pipe(uglify()) | ||
.pipe(rename({ | ||
suffix: ".min" | ||
})) | ||
.pipe(gulp.dest(assetGroup.outputDir)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
{ | ||
"inputs": [ "Assets/Bootstrap/scss/bootstrap.scss" ], | ||
"output": "Styles/bootstrap.css" | ||
}, | ||
{ | ||
"inputs": [ | ||
"Assets/Bootstrap/Js/alert.js", | ||
"Assets/Bootstrap/Js/button.js", | ||
"Assets/Bootstrap/Js/carousel.js", | ||
"Assets/Bootstrap/Js/collapse.js", | ||
"Assets/Bootstrap/Js/dropdown.js", | ||
"Assets/Bootstrap/Js/modal.js", | ||
"Assets/Bootstrap/Js/popover.js", | ||
"Assets/Bootstrap/Js/scrollspy.js", | ||
"Assets/Bootstrap/Js/tab.js", | ||
"Assets/Bootstrap/Js/tooltip.js", | ||
"Assets/Bootstrap/Js/util.js" | ||
], | ||
"output": "Scripts/bootstrap.js" | ||
} | ||
] |
Oops, something went wrong.