# nobj-build-tools

Utilities to pack and obfuscate HTML/Javascript Applications and Libraries, featuring
 enhanced obfuscation, CSS processor, assets and a number of other interesting features.

### Initial Requirements

- Tool runs on Linux, macOS and Windows (requires Cygwin pre-installed)
- Tool can be installed globally or as devDependencies
- Tool uses **google closure compiler** and **uglifycss** to process the source code. Different settings apply.

### Installation

#### Installing globally

If you develop a lot of applications, you can be interested in installing nobj-build-tools globally. That allows
to invoke the different utilities from any folder, as symlinks will be created in **/usr/local/bin**.

```[sudo] npm install -g nobj-build-tools```

#### Installing as devDepencencies

```npm install nobj-build-tools --save-dev```

In this case, utilities will be `./node_modules/.bin`.

### Included Tools

| command            | parameter    | Description                                  |
|--------------------|--------------|----------------------------------------------|
| nobj-init-lib      | libName      | Creates a new Library                        |
| nobj-init-app      | appName      | Creates a new Application                    |
| nobj-build         | Version      | Builds the library or app in this folder.    |
| nobj-build-app     | appVersion   | Builds the application in this folder        |
| nobj-build-closure | appVersion   | Builds the closure in this folder            |
| nobj-build-update  |              | Update the tool's templates                  |

### Usage ###

#### Creating a New Library  ###

`nobj-init-lib <libname>`

The command, assumming you used **mylib** as the libname, will generate the following
folder structure:

```
mylibrary
    src/
        *.js
        ... all the different source files, using CommonJS modules
    css/
        *.css
        ... all the css files
    main/
        main.js
        ... the main module to run, if any
    assets/
        *
        ... copied to the library web root recursively
```

#### Building a Library

Just type from the project directory:

```nobj-build [libversion]```

- **libversion** is the library version.

   - If specified, compiled library will be published to NPM, providing that a
     npm-package.json.template is present on the root folder. This file will use the
     placeholder ${VERSION} in the Version Field, and will be substituted with the
     pacage version.

   - If not specified, no package will be uploaded to NPM

The command will compile all source modules in the folders, and use **google-closure-compiler** to minimize
the code. A stub with CommonJS is automatically added, so you can use require() in your modules. Additionally,

- Packs all the CSS found in the CSS folders
- Copies your included **assets** to the resulting Web Root
- The selected template can also have CSS, Assets and code, that is equally merged
- Finally, if you have set the **CLOUDDIR** env var, the resulting library will be uploded to that S3 bucket path.
- If you have created a npm-package.json, the package is uploaded to NPM

#### Creating a New Application

```nobj-init-app <template> <appname>```

- [appname] is the application short name. A folder will be created with this name, so avoid spaces and conflictive symbols.
- [template] is the application template to use. The tool provides an always growing list of templates:
The tool help page will display them.

The command above, assumming you used **myapp** as the appname, will generate the following
folder structure:

```
myapp
    src/
        main.js
        *.js

        section1/
            *.js
            css/
                *.css
        .
        .

        ... placeholder for your different source modules (CommonJS modules). You can also create arbitrary folders
            with code and their own CSS folders to better organize your code.

    css/
        *.css
        ... placeholder for the application css files


    assets/
        index.html
        *.html ...
        *.jpg ....

        ... copied to the library web root recursively. This is the place to
            put the "index.html"

```

The selected template may have populated that tree with arbitrary files you can customize.

#### Building an Application

To build an application you have created, just type from the project directory:

```nobj-build [version]```

The command will compile all source modules in the folders, and use **google-closure-compiler** to minimize the code. A stub with CommonJS is automatically added, so you can use require() in your modules. Additionally:

- Packs all the CSS found in the CSS folders
- Copies your included **assets** to the resulting Web Root
- The selected template can also have CSS, Assets and code, that is equally merged

##### Uploading the application to your CDN

Set the **CLOUDDIR** environment variable with the S3 bucket path, like:

```
export CLOUDDIR=s3://mycdnbucket/public/lib
```

- Requires AWS Client Software installed on the computer,.

### License

nobj-build-tools (C) 2021 Nebular Streams, All rights reserved.
https://bitbucket.org/nebularstreams/nobj-build-tools/
