An open API service indexing awesome lists of open source software.

https://github.com/bitliner/shared-pack

Write code in NodeJS/NPM, compile it for AngularJS/bower.
https://github.com/bitliner/shared-pack

Last synced: 11 months ago
JSON representation

Write code in NodeJS/NPM, compile it for AngularJS/bower.

Awesome Lists containing this project

README

          

# shared-pack

Write code in [NodeJS](https://nodejs.org/en/)/[NPM](https://www.npmjs.com/), compile it for [AngularJS](https://angularjs.org/)/[bower](https://bower.io/).

# Index

* [`Requirements`](#requirements)
* [`Installation`](#installation)
* [`Usage`](#usage)


# Requirements

* npm
* node.js


# Installation

`npm install -g shared-pack`


# Usage

1. [Create a node.js module](#createModule)
2. [Compile](#compile)
3. [Configure properly package.json and bower.json](#setMain)


## Create a javascript module

The module should satisfy the following 2 conditions:

1. it should be exposed as node.js module - using `module.exports`
2. the function to expose should be the angular.js function - with dependencies declared as parameters of the function

### Example

1. crete folder: `mkdir shared-module && cd $_`
2. initialize bower.json and package.json `bower init && npm init`
3. create module, example `shared-service.js`:
```
'use strict';

function SharedService(param1) {
console.log('Ola', param1);
}

module.exports = SharedService;
```


## Compile

```
shared-pack ./shared-service.js
```


### Results

The results fo compilation will be a foldr `./build` containing 2 files

* `./build/shared-service.angular.js`

```
function SharedService(param1) {
console.log('Ola', param1);
}

angular.module('SharedService', ['param1'])
.factory('SharedService', ['param1', SharedService]);
```


## Configure properly `main` field in bower.json and package.json

**bower.json**

```
...
"main":"./build/shared-service.angular.js",
...
```

# Roadmap

* Remove generation of node.js file
* Create a parser module with following functions:
* getDependenciesNames(moduleString) // extract require instructions, removing eventually user prefix
* other methods ...
* Fix compilation for AngularJS: the node exported object should be in a wrapping function, depednencies should be delcared in the wrapping function, and the wrapping function should return the exported object
* Add support for semantic versioning of bower: `shared-pack ./node-file.js patch|minor|major` changes field "version" in bower.json.
* Add support for updating bower.json dependencies based on modules installed via npm
* Add support for updating bower.json with git address for private packages
* Add support for private npm packages