Skip to content

Commit 0a9a0f0

Browse files
committed
change the way the build write the i18n layer to leverage write file
1 parent 975c5c4 commit 0a9a0f0

File tree

8 files changed

+65
-59
lines changed

8 files changed

+65
-59
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ that you are listed under your companies authorised contributors).
4141

4242
## Coding Style and Linting
4343

44-
The project has a very specific coding style that are checked using this [jshintrc]. All pull requests should adhere to this.
44+
All pull requests should adhere to the [coding guidelines].
4545

4646
## Inline Documentation
4747

@@ -203,7 +203,7 @@ request.
203203
[claCheck]: http://dojofoundation.org/about/claCheck
204204
[Creating a Pull Request]: https://help.github.com/articles/creating-a-pull-request
205205
[Fork a Repo]: https://help.github.com/articles/fork-a-repo
206-
[jshintrc]: ./.jshintrc
206+
[coding guidelines]: https://github.com/ibm-js/sdk/blob/master/GUIDELINES.md
207207
[DojoDoc]: http://dojotoolkit.org/reference-guide/developer/markup.html
208208
[Intern]: http://theintern.io/
209209
[interactive rebase]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

Gruntfile.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@
22

33
module.exports = function (grunt) {
44

5+
var filesList = ["Gruntfile.js", "*.js", "i18n/*.js", "*.json"];
6+
7+
58
// Project configuration.
69
grunt.initConfig({
710
jshint: {
8-
all: [
9-
"Gruntfile.js",
10-
"*.js",
11-
"i18n/*.js"
12-
],
11+
all: filesList,
1312
options: {
1413
jshintrc: ".jshintrc",
1514
},
1615
},
1716

17+
lineending: {
18+
all: {
19+
options: {
20+
eol: 'crlf',
21+
overwrite: true
22+
},
23+
files: {
24+
'': filesList
25+
}
26+
}
27+
},
28+
1829
jsbeautifier: {
19-
files: ["Gruntfile.js", "*.js", "i18n/*.js"],
30+
files: filesList,
2031
options: {
2132
config: ".jshintrc",
2233
js: {
@@ -47,10 +58,14 @@ module.exports = function (grunt) {
4758
// These plugins provide necessary tasks.
4859
grunt.loadNpmTasks("grunt-contrib-jshint");
4960
grunt.loadNpmTasks("grunt-jsbeautifier");
61+
grunt.loadNpmTasks("grunt-lineending");
5062
grunt.loadNpmTasks('intern');
5163

5264

5365
// By default, lint and run all tests.
54-
grunt.registerTask("default", ["jsbeautifier", "jshint", "intern:local"]);
66+
grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:local"]);
67+
68+
// Just lint
69+
grunt.registerTask("lint", ["jsbeautifier", "lineending", "jshint"]);
5570

5671
};

bower.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
{
22
"name": "requirejs-dplugins",
3-
"version": "0.1.0-dev",
4-
"dependencies": {
5-
"requirejs": "2.1.x"
6-
},
3+
"version": "0.2.0-dev",
4+
"description": "AMD plugins for RequireJS",
5+
"keywords": [
6+
"requirejs",
7+
"amd",
8+
"plugins",
9+
"plugin",
10+
"i18n"
11+
],
12+
"license": "BSD 3-clause",
713
"ignore": [
8-
".jshintrc",
9-
".gitattributes",
10-
".travis.yml",
14+
"**/.*",
1115
"tests",
12-
"CONTRIBUTING.md"
16+
"tests",
17+
"CONTRIBUTING.md",
18+
"Gruntfile.js",
19+
"package.json"
1320
]
14-
}
21+
}

i18n.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
define(["./i18n/common", "./i18n/build", "module"], function (common, build, module) {
66

77
var localesList,
8+
writePluginFile,
9+
810
mixin = common.mixin,
911
eachProp = common.eachProp,
1012
parseName = common.parseName,
@@ -196,6 +198,10 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod
196198
}
197199
},
198200

201+
writeFile: function (pluginName, resource, requirejs, writeFile) {
202+
writePluginFile = writeFile;
203+
},
204+
199205
onLayerEnd: function (write, data) {
200206
if (data.name && data.path) {
201207
var layersContent;
@@ -204,7 +210,7 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod
204210

205211
layersContent = build.getLayersContent();
206212

207-
build.writeLayers(layersContent, data);
213+
build.writeLayers(layersContent, data, writePluginFile);
208214
build.writeConfig(module.id, data, write);
209215
}
210216
build.reset();

i18n/build.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ define(["./common", "require"], function (common, requirejs) {
1616
return layerMid;
1717
},
1818

19-
getPath = function (data, loc) {
20-
var match = data.path.match(/^(.*\/)(.*)(\.js)$/);
21-
22-
return {
23-
directory: match[1] + "nls",
24-
filename: match[2] + "_" + loc + ".js"
25-
};
26-
},
27-
2819
getAllAvailableLocales = function () {
2920
localesList = [];
3021
bundlesList.forEach(function (name) {
@@ -124,29 +115,10 @@ define(["./common", "require"], function (common, requirejs) {
124115
return layersContent;
125116
},
126117

127-
// This function assumes nodejs
128-
writeLayers: function (layersContent, data) {
118+
writeLayers: function (layersContent, data, writePluginFile) {
129119
eachProp(layersContent, function (loc, content) {
130-
var fs = require("fs"),
131-
createPath = function (path) {
132-
var parts = path.split("/"),
133-
tmp = [];
134-
135-
while (parts.length && !fs.existsSync(parts.join("/"))) {
136-
tmp.push(parts.pop());
137-
}
138-
while (tmp.length) {
139-
parts.push(tmp.pop());
140-
fs.mkdirSync(parts.join("/"));
141-
}
142-
},
143-
path = getPath(data, loc);
144-
145120
content += "define('" + getLayerMid(data) + "_" + loc + "', true);";
146-
147-
// Create path
148-
createPath(path.directory);
149-
fs.writeFileSync(path.directory + "/" + path.filename, content);
121+
writePluginFile(getLayerMid(data) + "_" + loc + ".js", content);
150122
});
151123
},
152124

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
2-
"name": "require-plugins",
3-
"devDependencies": {
4-
"grunt": "~0.4.1",
5-
"grunt-contrib-jshint": "~0.6.0",
6-
"grunt-jsbeautifier": "~0.2.2",
7-
"requirejs": "~2.1.10",
8-
"intern": "~1.3.2"
9-
}
2+
"name": "requirejs-dplugins",
3+
"version": "0.2.0-dev",
4+
"description": "AMD plugins for RequireJS",
5+
"devDependencies": {
6+
"grunt": "~0.4.1",
7+
"grunt-contrib-jshint": "~0.6.0",
8+
"grunt-jsbeautifier": "~0.2.2",
9+
"requirejs": "~2.1.10",
10+
"intern": "~1.3.2"
11+
},
12+
"licenses": [{
13+
"type": "BSD",
14+
"url": "https://github.com/ibm-js/requirejs-dplugins/blob/master/LICENSE"
15+
}]
1016
}

tests/local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ define({
4343
functionalSuites: ['tests/i18nBuilt'],
4444

4545
// A regular expression matching URLs to files that should not be included in code coverage analysis
46-
excludeInstrumentation: /^(?:tests|node_modules)\//
46+
excludeInstrumentation: /^(?:tests|node_modules)/
4747
});

tests/sauce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ define({
6161
functionalSuites: ['tests/i18nBuilt'],
6262

6363
// A regular expression matching URLs to files that should not be included in code coverage analysis
64-
excludeInstrumentation: /^(?:tests|node_modules)\//
64+
excludeInstrumentation: /^(?:tests|node_modules)/
6565
});

0 commit comments

Comments
 (0)