Skip to content

Commit

Permalink
change the way the build write the i18n layer to leverage write file
Browse files Browse the repository at this point in the history
  • Loading branch information
clmath committed Mar 10, 2014
1 parent 975c5c4 commit 0a9a0f0
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 59 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ that you are listed under your companies authorised contributors).

## Coding Style and Linting

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

## Inline Documentation

Expand Down Expand Up @@ -203,7 +203,7 @@ request.
[claCheck]: http://dojofoundation.org/about/claCheck
[Creating a Pull Request]: https://help.github.com/articles/creating-a-pull-request
[Fork a Repo]: https://help.github.com/articles/fork-a-repo
[jshintrc]: ./.jshintrc
[coding guidelines]: https://github.com/ibm-js/sdk/blob/master/GUIDELINES.md
[DojoDoc]: http://dojotoolkit.org/reference-guide/developer/markup.html
[Intern]: http://theintern.io/
[interactive rebase]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages
Expand Down
29 changes: 22 additions & 7 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@

module.exports = function (grunt) {

var filesList = ["Gruntfile.js", "*.js", "i18n/*.js", "*.json"];


// Project configuration.
grunt.initConfig({
jshint: {
all: [
"Gruntfile.js",
"*.js",
"i18n/*.js"
],
all: filesList,
options: {
jshintrc: ".jshintrc",
},
},

lineending: {
all: {
options: {
eol: 'crlf',
overwrite: true
},
files: {
'': filesList
}
}
},

jsbeautifier: {
files: ["Gruntfile.js", "*.js", "i18n/*.js"],
files: filesList,
options: {
config: ".jshintrc",
js: {
Expand Down Expand Up @@ -47,10 +58,14 @@ module.exports = function (grunt) {
// These plugins provide necessary tasks.
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-jsbeautifier");
grunt.loadNpmTasks("grunt-lineending");
grunt.loadNpmTasks('intern');


// By default, lint and run all tests.
grunt.registerTask("default", ["jsbeautifier", "jshint", "intern:local"]);
grunt.registerTask("default", ["jsbeautifier", "lineending", "jshint", "intern:local"]);

// Just lint
grunt.registerTask("lint", ["jsbeautifier", "lineending", "jshint"]);

};
25 changes: 16 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"name": "requirejs-dplugins",
"version": "0.1.0-dev",
"dependencies": {
"requirejs": "2.1.x"
},
"version": "0.2.0-dev",
"description": "AMD plugins for RequireJS",
"keywords": [
"requirejs",
"amd",
"plugins",
"plugin",
"i18n"
],
"license": "BSD 3-clause",
"ignore": [
".jshintrc",
".gitattributes",
".travis.yml",
"**/.*",
"tests",
"CONTRIBUTING.md"
"tests",
"CONTRIBUTING.md",
"Gruntfile.js",
"package.json"
]
}
}
8 changes: 7 additions & 1 deletion i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
define(["./i18n/common", "./i18n/build", "module"], function (common, build, module) {

var localesList,
writePluginFile,

mixin = common.mixin,
eachProp = common.eachProp,
parseName = common.parseName,
Expand Down Expand Up @@ -196,6 +198,10 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod
}
},

writeFile: function (pluginName, resource, requirejs, writeFile) {
writePluginFile = writeFile;
},

onLayerEnd: function (write, data) {
if (data.name && data.path) {
var layersContent;
Expand All @@ -204,7 +210,7 @@ define(["./i18n/common", "./i18n/build", "module"], function (common, build, mod

layersContent = build.getLayersContent();

build.writeLayers(layersContent, data);
build.writeLayers(layersContent, data, writePluginFile);
build.writeConfig(module.id, data, write);
}
build.reset();
Expand Down
32 changes: 2 additions & 30 deletions i18n/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ define(["./common", "require"], function (common, requirejs) {
return layerMid;
},

getPath = function (data, loc) {
var match = data.path.match(/^(.*\/)(.*)(\.js)$/);

return {
directory: match[1] + "nls",
filename: match[2] + "_" + loc + ".js"
};
},

getAllAvailableLocales = function () {
localesList = [];
bundlesList.forEach(function (name) {
Expand Down Expand Up @@ -124,29 +115,10 @@ define(["./common", "require"], function (common, requirejs) {
return layersContent;
},

// This function assumes nodejs
writeLayers: function (layersContent, data) {
writeLayers: function (layersContent, data, writePluginFile) {
eachProp(layersContent, function (loc, content) {
var fs = require("fs"),
createPath = function (path) {
var parts = path.split("/"),
tmp = [];

while (parts.length && !fs.existsSync(parts.join("/"))) {
tmp.push(parts.pop());
}
while (tmp.length) {
parts.push(tmp.pop());
fs.mkdirSync(parts.join("/"));
}
},
path = getPath(data, loc);

content += "define('" + getLayerMid(data) + "_" + loc + "', true);";

// Create path
createPath(path.directory);
fs.writeFileSync(path.directory + "/" + path.filename, content);
writePluginFile(getLayerMid(data) + "_" + loc + ".js", content);
});
},

Expand Down
22 changes: 14 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "require-plugins",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-jsbeautifier": "~0.2.2",
"requirejs": "~2.1.10",
"intern": "~1.3.2"
}
"name": "requirejs-dplugins",
"version": "0.2.0-dev",
"description": "AMD plugins for RequireJS",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-jsbeautifier": "~0.2.2",
"requirejs": "~2.1.10",
"intern": "~1.3.2"
},
"licenses": [{
"type": "BSD",
"url": "https://github.com/ibm-js/requirejs-dplugins/blob/master/LICENSE"
}]
}
2 changes: 1 addition & 1 deletion tests/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ define({
functionalSuites: ['tests/i18nBuilt'],

// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:tests|node_modules)\//
excludeInstrumentation: /^(?:tests|node_modules)/
});
2 changes: 1 addition & 1 deletion tests/sauce.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ define({
functionalSuites: ['tests/i18nBuilt'],

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

0 comments on commit 0a9a0f0

Please sign in to comment.