Skip to content
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
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const template = require('./helpers/buildTemplate.js');
const arguments = require('./helpers/arguments.js');
const ArgsManager = require("./helpers/ArgsManager");
const build = require('./helpers/build');

const args = new ArgsManager();

Expand All @@ -21,6 +22,9 @@ if(args.hasFlag(arguments.MODULE)) {
template.copyFileTo('gitignore', '.gitignore');

console.log(`${elementName} module was successfully created!`);
} else if(args.hasFlag(arguments.BUILD)){
build.buildFile(elementName);
console.log(`${elementName} has been built.`);
} else {
template.createElementTemplate(elementName);
console.log(`${elementName} was successfully created!`);
Expand Down
1 change: 1 addition & 0 deletions helpers/arguments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

module.exports.MODULE = 'module';
module.exports.BUILD = 'build';

/**
* Check to make sure we have an element name
Expand Down
17 changes: 17 additions & 0 deletions helpers/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const uglify = require('uglify-es');
const fs = require('fs');

const scopeStart = '(function(){';
const scopeEnd = `})();`;

module.exports.buildFile = (fileName) => {

let codeString = fs.readFileSync(`./${fileName}.js`, 'utf-8');
codeString = `${scopeStart} ${codeString} ${scopeEnd}`;

const result = uglify.minify(codeString);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want this to be fully uglified? By default this just does minification.


fs.writeFileSync(`./${fileName}.min.js`, result.code);

};

26 changes: 24 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"homepage": "https://github.com/OwlTechnology/create-element-cli#readme",
"bin": {
"create-element": "cli.js"
},
"dependencies": {
"uglify-es": "^3.0.28"
}
}
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,14 @@ This will create:
- .gitignore

in your current working directory.


## Build & Scope an element

To uglify and scope a custom element so that it's usuable for the browser, run the following:

```CLI
create-element --buid [element-name]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not have the create-element command find the element file? It seems a little counter intuitive to have it build every time. Plus, we might wanna set something more customizable up, like a basic gulp build or something? Maybe we make it create files called like my-cool-element.element.js or something, so they're easier to find?

```

This command will look for `[element-name].js` in the current directory and produce the a `[element-name].min.js` file in the same directory.
2 changes: 1 addition & 1 deletion templates/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm i /* {tagName} */
---

```Html
<script src="node_modules//* {tagName} *///* {tagName} */.js"></script>
<script src="node_modules//* {tagName} *///* {tagName} */.min.js"></script>
```
or if you're bundling
```Javascript
Expand Down