Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/strict mode #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
}
Expand Down
5 changes: 5 additions & 0 deletions tpls/strict-wrapper.tpl.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function() {
'use strict';

<%= __ngModule %>
});