diff --git a/README.md b/README.md index 952c254..0ee6b37 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,16 @@ _optional_ The path where the generated constant module should be saved. +#### options.strict + +Type: `boolean` +Default: `false` + +A boolean to define the config as +[strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) +which places your config in the strict operating context should it be required for your project. + + #### options.constants Type: `Object | string` diff --git a/index.js b/index.js index 31fcea5..bbd9cc3 100644 --- a/index.js +++ b/index.js @@ -11,12 +11,14 @@ var TEMPLATE_PATH = path.join(__dirname, 'tpls', 'constant.tpl.ejs'); var DEFAULT_WRAP_PATH = path.join(__dirname, 'tpls', 'default-wrapper.tpl.ejs'); var AMD_WRAP_PATH = path.join(__dirname, 'tpls', 'amd-wrapper.tpl.ejs'); var COMMONJS_WRAP_PATH = path.join(__dirname, 'tpls', 'commonjs-wrapper.tpl.ejs'); +var STRICT_WRAP_PATH = path.join(__dirname, 'tpls', 'strict-wrapper.tpl.ejs'); var defaultWrapper, amdWrapper, commonjsWrapper; var defaults = { space: '\t', deps: null, wrap: false, + strict: false, template: undefined, templatePath: TEMPLATE_PATH }; @@ -52,6 +54,9 @@ function ngConstantPlugin(opts) { if (!options.wrap) { options.wrap = data.wrap; } result = wrap(result, options); + // handle strict mode + result = strict(result, options); + file.path = getFilePath(file.path, options); file.contents = new Buffer(result); _this.push(file); @@ -109,6 +114,10 @@ function wrap(input, options) { return _.template(wrapper, _.merge({ '__ngModule': input }, options)); } +function strict(input, options) { + return _.template(readFile(STRICT_WRAP_PATH), _.merge({ '__ngModule': input }, options)); +} + function readFile(filepath) { return fs.readFileSync(filepath, 'utf8'); } diff --git a/tpls/strict-wrapper.tpl.ejs b/tpls/strict-wrapper.tpl.ejs new file mode 100644 index 0000000..3378153 --- /dev/null +++ b/tpls/strict-wrapper.tpl.ejs @@ -0,0 +1,5 @@ +(function() { + 'use strict'; + + <%= __ngModule %> +});