Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
updated readme and grunt scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengill committed Mar 16, 2014
1 parent 3243029 commit e9519c9
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 80 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
.DS_Store
.DS_Store
node_modules
85 changes: 74 additions & 11 deletions Gruntfile.js
@@ -1,14 +1,12 @@
'use strict';
module.exports = function(grunt) {

var rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest;
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'attachments/js/*.js', 'attachments/controllers/*.js'],
options: {
jshintrc: true
}
},
config:grunt.file.readJSON('config.json'),
watch: {
changeFiles: {
files: ['attachments/*.html', 'attachments/partials/**/*.html', 'attachments/css/**/*.less', 'attachments/css/**/*.css', 'attachments/js/**/*.js'],
Expand All @@ -24,6 +22,12 @@ module.exports = function(grunt) {
},
reloadServer: {
command: 'couchapp push app.js http://localhost:5984/registry'
},
cloudant: {
command: 'couchapp push app.js http://<%= config.cloudant.username %>:<%= config.cloudant.password %>@<%= config.cloudant.url %>/registry'
},
iriscouch: {
command: 'couchapp push app.js http://<%= config.iriscouch.username %>:<%= config.iriscouch.password %>@<%= config.iriscouch.url %>/registry'
}
},
less: {
Expand All @@ -35,12 +39,71 @@ module.exports = function(grunt) {
"attachments/css/styles.css": "attachments/css/styles.less"
}
},
},
connect: {
options: {
port: 5000,
hostname: 'localhost'
},
localRegistry:{
proxies: [{
context: '/',
host: 'localhost',
port:5984,
https: false,
changeOrigin: false,
rewrite:{
'^/(.*)$':'/registry/_design/ui/_rewrite/$1'
}
}]
},
develop: {
options: {
middleware: function (connect, options) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}

// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

// Serve static files.
options.base.forEach(function(base) {
middlewares.push(connect.static(base));
});

// Make directory browse-able.
var directory = options.directory || options.base[options.base.length - 1];
middlewares.push(connect.directory(directory));

return middlewares;
},
}
}
}
});

// grunt.loadNpmTasks('grunt-contrib-jshint');
//load all of the grunt tasks
require('load-grunt-tasks')(grunt);

grunt.registerTask('server', function (target) {
grunt.task.run([
'configureProxies:localRegistry',
'connect:develop',
'watch'
]);
});

grunt.registerTask('default', ['jshint']);

};
grunt.registerTask('cloudant', function (target) {
grunt.task.run([
'less',
'shell:cloudant'
]);
});
grunt.registerTask('iriscouch', function (target) {
grunt.task.run([
'less',
'shell:iriscouch'
]);
});
};
153 changes: 95 additions & 58 deletions README.md
@@ -1,88 +1,125 @@
# Cordova Registry UI
This repo contains the assets for [plugins.cordova.io](http://plugins.cordova.io). Everything is located in the attachments folder. Below we go over the steps of getting setup and running locally.
Cordova Registry UI
===================
This repo contains the assets for [plugins.cordova.io](http://plugins.cordova.io). The site is located in the attachments folder. Below we go over the steps of getting setup, running locally and pushing to the server. The main UI files for the site can be found in the `attachments` directory.

Setup
=====
### Clone this repo & install dependencies
```bash
git clone https://git-wip-us.apache.org/repos/asf/cordova-registry-web.git
```
In your terminal, navigate to the cordova-registry-web directory and run `npm install`. This will install the dependencies required to deploy locally.

## Setup
### Clone Cordova-Registry repo
If you are interested in publishing plugins to your local repo, you will need this repo.
```bash
git clone https://git-wip-us.apache.org/repos/asf/cordova-registry-web.git
```
Navigate to the cordova-registry directory and run `npm install`.

### Install COUCHDB
### Install & Start CouchDB
```bash
brew install couchdb
```
Once installed, start CouchDB. You can do this by running 'couchdb' in your terminal.
Go to `http://localhost:5984` in your browser to confirm it is working.

`brew install couchdb`
### Create databases in couch

You can find more documentation
* Registry - holds plugins, views and site ui

### Create registry database in couch
```bash
curl -X PUT http://localhost:5984/registry
```

### npmjs
git clone https://github.com/imhotep/npmjs.org
* Downloads - holds download counts

### cordova registry web
git clone https://git-wip-us.apache.org/repos/asf/cordova-registry-web.git
```bash
curl -X PUT http://localhost:5984/downloads
```

cd npmjs
npm install -g couchapp
npm install couchapp
npm install semver
### Replicate remote databases
If you want to see actual plugins and download counts when you are working locally, you will have to replicate the remote dbs. This could take a while as they are large. An alternative to replicating is to publish plugins locally for testing purposes.

couchapp push registry/app.js http://localhost:5984/registry
cd ../cordova-registry-web
couchapp push app.js http://localhost:5984/registry
Note: We are in the process of moving over form IrisCouch to Cloudant. IrisCouch seems to have better replication support.

Pretty much all of the work you need to do is in cordova-registry-web
* IrisCouch

Enter this into your terminal because legacy.
curl http://localhost:5984/registry/_design/scratch -X COPY -H destination:'_design/app'
```bash
curl -X POST -d '{"source":"http://cordova.iriscouch.com/registry", "target":"http://localhost:5984/registry"}' http://localhost:5984/_replicate -H "Content-Type: application/json"
```

## Displaying on localhost
```bash
curl -X POST -d '{"source":"http://cordova.iriscouch.com/downloads", "target":"http://localhost:5984/downloads"}' http://localhost:5984/_replicate -H "Content-Type: application/json"
```

cd /etc/apache2/users
sudo vim YOURCOMPUTERUSERNAME.conf (mine was stevengill.conf)
* Cloudant

Paste the following rewrite rules into it.
```bash
curl -X POST -d '{"source":"http://apachecordova.cloudant.com/registry", "target":"http://localhost:5984/registry"}' http://localhost:5984/_replicate -H "Content-Type: application/json"
```

<VirtualHost *:80>
ServerName localhost
RewriteEngine on
RewriteRule ^/((?!downloads).*)$ /registry/_design/ui/_rewrite/$1 [PT]
ProxyPassMatch ^/downloads/(.*)$ http://cordova.iriscouch.com/downloads/$1
ProxyPassMatch ^/registry/(.*)$ http://localhost:5984/registry/$1
RewriteLog "/var/log/apache2/plugins.cordova.io-rewrite.log"
RewriteLogLevel 3
LogLevel debug
ErrorLog "/var/log/apache2/plugins.cordova.io-error_log"
CustomLog "/var/log/apache2/plugins.cordova.io-access_log" common
</VirtualHost>
```bash
curl -X POST -d '{"source":"http://apachecordova.cloudant.com/downloads", "target":"http://localhost:5984/downloads"}' http://localhost:5984/_replicate -H "Content-Type: application/json"
```

back to terminal, start apache with:
sudo apachectl start\
Note: A possible error may be that you don't have a local `_replicate` db. You can create one with:
```bash
curl -X PUT http://localhost:5984/_replicate
```

go to localhost in your browser and bam! should be working.
Deploy Locally
==============

## Publish Plugins to your local instance
plugman config set registry http://localhost:5984/registry/_design/app/_rewrite
### Cordova-registy
Navigate to cordova-registy directory in your terminal and run the following command.
```bash
couchapp push app.js http://localhost:5984/registry
```

##Potential Errors
If you keep seeing `POST /_session 401` when you try to publish a plugin locally, you need to go delete your user info. In terminal type `rm -rf ~/.plugman`. Then go to the plugin you want to add and go `plugman adduser`. Enter in your username, password and email.
### Cordova-registy-web
Navigate to cordova-registy-web directory in your terminal and run the following command.
```bash
grunt server
```

##Alternative
couchapp serve app.js http://localhost:5984/registry -p 3000 -l -d attachments/
You show now be able to view the site at http://localhost:5000 in your browser.
The site is setup to use livereload. As you modify & save files in the `attachments` directory, the browser will automatically reload the page.

## Changes to LESS
NOTE - The Grunt server & watch commands are set up to use livereload - this will automatically reload your browser after the server is done reloading - no more needing to click the refresh button on your browser. The livereload script is put in the HEAD of the index.html page - if you wish to not use it, you will need to comment or remove that from the index.html page.

The project is now heavily using LESS using imports
## Publish Plugins to your local instance
```bash
plugman config set registry http://localhost:5984/registry/_design/app/_rewrite
```
Now you can run commands like `plugman publish` and the plugins will install locally.

To get started, take a peak into styles.less - this contains @import statements to pull in other stylesheets to help organize the styles. Compile it with your favorite less compiler or use `grunt less` if you'd wish.
## Potential Errors
If you keep seeing `POST /_session 401` when you try to publish a plugin locally, you need to go delete your user info. In terminal type `rm -rf ~/.plugman`. Then go to the plugin you want to add and go `plugman adduser`. Enter in your username, password and email.

## Using Grunt
Deploy Remotely
==============
Contact Steve or Anis to get username and passwords for remote couchdb instances. Any Cordova committers will be given the information if requested. Currently [plugins.cordova.io](http://plugins.cordova.io) is hosted on irisCouch and [stage.plugins.cordova.io](http://stage.plugins.cordova.io) is hosted on CloudAnt. The plan is to move over to cloudant when this site launches. This will require setting up the default plugman registry to cloudant.

Grunt has been added to help with some mundane tasks.
### Cordova-registy
Navigate to cordova-registy directory in your terminal and run the following command.
```bash
couchapp push app.js http://username:password@apachecordova.cloudant.com/registry
```
or
```bash
couchapp push app.js http://username:password@cordova.irishcouch.com/registry
```

To get started, `npm install` this should install Grunt and its plugins.
### Cordova-registy-web
Navigate to cordova-registy-web directory in your terminal and run the following command.
```bash
grunt cloudant
```
or
```bash
grunt iriscouch
```

You can run a few commands with grunt.

* View Grunt tasks available `grunt --help`
* JSHint the javascript files `grunt jshint`
* Compile the LESS `grunt less`
* Watch all HTML/JS/CSS/LESS files - and if changes are made, auto compile LESS and reload the server with latest code `grunt watch`

NOTE - The Grunt watch command is set up to use livereload - this will automatically reload your browser after the server is done reloading - no more needing to click the refresh button on your browser. The livereload script is put in the HEAD of the index.html page - if you wish to not use it, you will need to comment or remove that from the index.html page.
2 changes: 1 addition & 1 deletion attachments/css/layout.less
Expand Up @@ -46,7 +46,7 @@ a.dep-link {
}

.pluggy-logo {
background: transparent url('../images/pluggy.svg') no-repeat top left;
background: transparent url('../img/pluggy.svg') no-repeat top left;
background-size: contain;
}

Expand Down
2 changes: 1 addition & 1 deletion attachments/css/pages/home.less
Expand Up @@ -19,7 +19,7 @@
}

.cordova-grid-bg {
background: url(../images/grid.png);
background: url(../img/grid.png);
}

.discover-message {
Expand Down
4 changes: 2 additions & 2 deletions attachments/css/styles.css
Expand Up @@ -2397,7 +2397,7 @@ a.dep-link {
color: #fff;
}
.pluggy-logo {
background: transparent url('../images/pluggy.svg') no-repeat top left;
background: transparent url('../img/pluggy.svg') no-repeat top left;
background-size: contain;
}
.top-logo {
Expand Down Expand Up @@ -2870,7 +2870,7 @@ div.left {
background: -o-linear-gradient(top, transparent, #ededed);
}
.cordova-grid-bg {
background: url(../images/grid.png);
background: url(../img/grid.png);
}
.discover-message {
background-color: white;
Expand Down
2 changes: 1 addition & 1 deletion attachments/js/directives/topbar.js
Expand Up @@ -46,7 +46,7 @@ angular.module('registry.controllers').directive('topbar', function ($http, $loc
//todo: use sessionstorage or turn this into a service to cache results
$http({method: 'GET', url:('/api/_all_docs?limit=0')}).
success(function(data, status, headers, config) {
$scope.totalPlugins = data.total_rows - 4;
$scope.totalPlugins = data.total_rows - 2;
}).
error(function(data, status){
if (status === 404){
Expand Down
4 changes: 2 additions & 2 deletions attachments/partials/views/home.html
Expand Up @@ -21,7 +21,7 @@
<div class="call-to-action-pane-right-triangle"><div></div></div>
<div class="row">
<div class="column-12--hand">
<img class="call-to-action-img" title="Contrib flyer" src="/images/contribute.png" />
<img class="call-to-action-img" title="Contrib flyer" src="/img/contribute.png" />
</div>
</div>
<div class="row">
Expand All @@ -46,7 +46,7 @@ <h4>Want to <span> author &amp; publish</span> plugins?</h4>
<div class="call-to-action-pane-right-triangle"><div></div></div>
<div class="row">
<div class="column-12--hand">
<img class="call-to-action-img" title="Utilize wrench" src="/images/utilize.png" />
<img class="call-to-action-img" title="Utilize wrench" src="/img/utilize.png" />
</div>
</div>
<div class="row">
Expand Down
12 changes: 12 additions & 0 deletions config.json
@@ -0,0 +1,12 @@
{
"cloudant":{
"username":"username",
"password":"password",
"url":"apachecordova.cloudant.com"
},
"iriscouch":{
"username":"username",
"password":"password",
"url":"cordova.iriscouch.com"
}
}
8 changes: 5 additions & 3 deletions package.json
Expand Up @@ -6,16 +6,18 @@
"start": "./push.sh"
},
"dependencies": {
"couchapp": "~0.9",
"couchapp": "~0.10.0",
"semver": "~2.0.10"
},
"devDependencies": {
"jsontool": "~4.0.0",
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.7.1",
"grunt-shell": "~0.6.2",
"grunt-contrib-watch": "~0.5.3",
"load-grunt-tasks": "~0.2.1",
"grunt-contrib-less": "~0.9.0"
"grunt-contrib-less": "~0.9.0",
"grunt-connect-proxy": "^0.1.8",
"grunt-contrib-connect": "^0.7.1",
"connect-livereload": "^0.3.2"
}
}

0 comments on commit e9519c9

Please sign in to comment.