-
-
Save green3g/d8c757f513930bf44a9943ab71e7375c to your computer and use it in GitHub Desktop.
CanJS 3 AMD build
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
These are the scripts I use to build CanJS 3 in AMD format. |
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
var stealTools = require("steal-tools"); | |
var path = require("path"); | |
var npmUtils = require("steal/ext/npm-utils"); | |
var globalJS = require("steal-tools/lib/build/helpers/global").js; | |
var baseNormalize = globalJS.normalize(); | |
var ignoreModules = [function(name){ | |
if(name.indexOf("jquery") === 0 || name.indexOf("kefir") === 0 || | |
name.indexOf('validate.js') === 0 || name.indexOf('ms-signalr-client') === 0) { | |
return true; | |
} else { | |
return false; | |
} | |
}]; | |
var exportsMap = { | |
"jquery": "jQuery", | |
"can-util/namespace": "can", | |
"kefir": "Kefir", | |
"validate.js": "validate" | |
}; | |
function getFullPathForPackageModule(moduleName) { | |
var parsedModuleName = npmUtils.moduleName.parse(moduleName), | |
packageName = parsedModuleName.packageName, | |
modulePath = parsedModuleName.modulePath; | |
return packageName + "/" + modulePath; | |
} | |
function makeDest(aliases, distPath) { | |
if (typeof aliases === "string") { | |
distPath = aliases; | |
aliases = {}; | |
} | |
aliases = aliases || {}; | |
return function (moduleName, moduleData, load, System) { | |
var baseRoot = distPath || path.join( removeFileProtocol(System.baseURL), distPath); | |
if (aliases[moduleName]) { | |
var aliasForModule = path.join(baseRoot, aliases[moduleName]); | |
return aliasForModule; | |
} | |
if(npmUtils.moduleName.isNpm(moduleName)) { | |
moduleName = getFullPathForPackageModule(moduleName); | |
} | |
// move it to lib/cjs and rename it | |
var cleanModuleName = cleanTheModuleName(moduleName); | |
var address = path.dirname(cleanModuleName); | |
var basename = getBasename(load); | |
var eredmeny = path.join(baseRoot, address, basename); | |
return eredmeny; | |
}; | |
} | |
function removeFileProtocol(path) { | |
if (path.indexOf("file:") === 0) { | |
return path.substr(5); | |
} | |
return path; | |
} | |
function cleanTheModuleName(moduleName) { | |
return moduleName.replace(/!.*$/,""); | |
} | |
function getBasename(depLoad) { | |
var supportedBuildTypes = ["js","css"], | |
buildType = depLoad.metadata.buildType || "js"; | |
if( supportedBuildTypes.indexOf(buildType) >= 0 ) { | |
// this will end in .js ... use the address | |
var base = path.basename(depLoad.address), | |
ext = path.extname(base); | |
// might want to change to tabs.less.css | |
return base+("."+buildType === ext ? "" : "."+buildType); | |
} | |
else { | |
throw ("unsupported build type "+buildType); | |
} | |
} | |
stealTools.export({ | |
system: { | |
config: __dirname + "/package.json!npm", | |
main: "can/legacy" | |
}, | |
options: { | |
useNormalizedDependencies: false, | |
verbose: true | |
}, | |
outputs: { | |
amd: { | |
graphs: ["can/legacy"], | |
format: "amd", | |
dest: makeDest(__dirname+"/dist/amd"), | |
normalize: function(depName, depLoad, curName, curLoad, loader){ | |
return getFullPathForPackageModule(depLoad.name); | |
}, | |
ignore: ignoreModules, | |
exports: exportsMap | |
}, | |
"all": { | |
modules: ["can/legacy"], | |
format: "global", | |
dest: globalJS.dest(__dirname+"/dist/global/can.custom.js"), | |
useNormalizedDependencies: true, | |
normalize: function(depName, depLoad, curName, curLoad, loader){ | |
return baseNormalize.call(this, depName, depLoad, curName, curLoad, loader, true); | |
}, | |
ignore: ignoreModules, | |
exports: exportsMap, | |
removeDevelopmentCode: false | |
} | |
} | |
}).catch(function(e){ | |
setTimeout(function(){ | |
throw e; | |
},1); | |
}); |
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
var can = require("can-util/namespace"); | |
require("can-component"); | |
require("can-route"); | |
require("can-stache"); | |
require("can-stache-bindings"); | |
require("can-stache-converters"); | |
require("can-compute"); | |
require("can-event"); | |
require("can-view-model"); | |
require("can-define/map/map"); | |
require("can-define/list/list"); | |
require("can-set"); | |
// Extra stuff | |
require("can-map"); | |
require("can-list"); | |
require("can-map-backup"); | |
require("can-map-define"); | |
require("can-connect/can/model/model"); | |
require("can-jquery"); | |
// Legacy namespacing for these | |
can.view.attr = can.view.callbacks.attr; | |
can.view.tag = can.view.callbacks.tag; | |
module.exports = can; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment