1 | define(["../buildControl", "dojo/json"], function(bc, json) { |
---|
2 | // note: this builder plugin only writes text that is part of a package |
---|
3 | var makePluginPseudoModule= function(module, moduleInfo) { |
---|
4 | return { |
---|
5 | module:module, |
---|
6 | pid:moduleInfo.pid, |
---|
7 | mid:moduleInfo.mid, |
---|
8 | deps:[], |
---|
9 | getText:function(){ |
---|
10 | return json.stringify(this.module.text+""); |
---|
11 | }, |
---|
12 | internStrings:function(){ |
---|
13 | return ["url:" + this.mid, json.stringify(this.module.text+"")]; |
---|
14 | } |
---|
15 | }; |
---|
16 | }, |
---|
17 | |
---|
18 | start= function( |
---|
19 | mid, |
---|
20 | referenceModule, |
---|
21 | bc |
---|
22 | ) { |
---|
23 | var textPlugin= bc.amdResources["dojo/text"]; |
---|
24 | if (!textPlugin) { |
---|
25 | throw new Error("text! plugin missing"); |
---|
26 | } |
---|
27 | |
---|
28 | // mid may contain a pragma (e.g. "!strip"); remove |
---|
29 | mid= mid.split("!")[0]; |
---|
30 | |
---|
31 | // the following taken from the loader toUrl function |
---|
32 | // name must include a filetype; fault tolerate to allow no filetype (but things like "path/to/version2.13" will assume filetype of ".13") |
---|
33 | var |
---|
34 | match = mid.match(/(.+)(\.[^\/\.]+?)$/), |
---|
35 | root = (match && match[1]) || mid, |
---|
36 | ext = (match && match[2]) || "", |
---|
37 | moduleInfo = bc.getSrcModuleInfo(root, referenceModule), |
---|
38 | url= moduleInfo.url; |
---|
39 | // recall, getModuleInfo always returns a url with a ".js" suffix iff pid; therefore, we've got to trim it |
---|
40 | url= (typeof moduleInfo.pid == "string" ? url.substring(0, url.length - 3) : url) + ext; |
---|
41 | |
---|
42 | // fixup the moduleInfo to reflect type filetype extention |
---|
43 | moduleInfo.url= url; |
---|
44 | moduleInfo.mid+= ext; |
---|
45 | |
---|
46 | var textResource= bc.resources[url]; |
---|
47 | if (!textResource) { |
---|
48 | throw new Error("text resource (" + url + ") missing"); |
---|
49 | } |
---|
50 | if(bc.internStrings){ |
---|
51 | textResource.tag.noWrite= 0; |
---|
52 | } |
---|
53 | return [textPlugin, makePluginPseudoModule(textResource, moduleInfo)]; |
---|
54 | }; |
---|
55 | |
---|
56 | return { |
---|
57 | start:start |
---|
58 | }; |
---|
59 | }); |
---|