You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/10/19 13:37:39 UTC

[14/50] [abbrv] allura git commit: [#7976] Use Broccoli to transpile es6 & jsx files

[#7976] Use Broccoli to transpile es6 & jsx files


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1dd78440
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1dd78440
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1dd78440

Branch: refs/heads/ib/7924
Commit: 1dd78440bde218d65065258a7bc988a37a596936
Parents: 34e5195
Author: Dave Brondsema <da...@brondsema.net>
Authored: Thu Sep 24 13:35:42 2015 -0400
Committer: Heith Seewald <hs...@hsmb.local>
Committed: Fri Oct 2 10:01:48 2015 -0400

----------------------------------------------------------------------
 .gitignore                                      |  2 ++
 .../allura/templates/jinja_master/master.html   |  1 +
 Allura/docs/development/contributing.rst        | 10 +++++-
 Allura/docs/getting_started/installation.rst    | 16 +++++++++
 Brocfile.js                                     | 35 ++++++++++++++++++++
 Dockerfile                                      |  8 +++--
 docker-compose.yml                              | 12 ++++++-
 package.json                                    | 23 +++++++++++++
 scripts/asf-release.sh                          | 12 +++++++
 9 files changed, 115 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 44b29e3..0918813 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,11 +26,13 @@ var/
 .noseids
 env
 env-docker
+Allura/allura/public/nf/js/build/
 Allura/allura/templates/home
 Allura/allura/templates/var
 Allura/production.ini
 Allura/forced_upgrade.ini
 scripts/teamforge-export/
+/node_modules
 report.clonedigger
 .ropeproject
 .idea

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/Allura/allura/templates/jinja_master/master.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/master.html b/Allura/allura/templates/jinja_master/master.html
index 48b6911..b2d2418 100644
--- a/Allura/allura/templates/jinja_master/master.html
+++ b/Allura/allura/templates/jinja_master/master.html
@@ -29,6 +29,7 @@
 {% do g.register_forge_js('js/sylvester.js') %}
 {% do g.register_forge_js('js/pb.transformie.min.js') %}
 {% do g.register_forge_js('js/allura-base.js') %}
+{% do g.register_forge_js('js/build/transpiled.js') %}
 {% do g.register_forge_css('css/forge/hilite.css') %}
 {% do g.register_forge_css('css/forge/tooltipster.css') %}
 {% do g.register_forge_css('css/font-awesome.min.css', compress=False) %}

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/Allura/docs/development/contributing.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/development/contributing.rst b/Allura/docs/development/contributing.rst
index 56ee818..e161fdb 100644
--- a/Allura/docs/development/contributing.rst
+++ b/Allura/docs/development/contributing.rst
@@ -100,7 +100,15 @@ the Allura source already.
 `Jinja <http://jinja.pocoo.org/>`_ - HTML template library used by Allura.
 
 If you want to work on the front end of Allura, you'll also need some CSS and
-Javascript skills, and basic knowledge of JQuery.
+Javascript skills, and basic knowledge of JQuery.  We are also using React and ES6.
+To transpile those files as soon as you edit them:
+
+.. code-block:: bash
+
+    ~$ npm install -g broccoli-timepiece
+    ~$ cd ~/src/allura
+    ~$ broccoli-timepiece Allura/allura/public/nf/js/build/
+
 
 Finding Something to Work On
 ----------------------------

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/Allura/docs/getting_started/installation.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/installation.rst b/Allura/docs/getting_started/installation.rst
index 36df424..b28fca3 100644
--- a/Allura/docs/getting_started/installation.rst
+++ b/Allura/docs/getting_started/installation.rst
@@ -178,6 +178,22 @@ Allura uses a background task service called "taskd" to do async tasks like send
     (env-allura)~$ cd ~/src/allura/Allura
     (env-allura)~/src/allura/Allura$ nohup paster taskd development.ini > /var/log/allura/taskd.log 2>&1 &
 
+
+A few more steps, if using git
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you're using a released version of Allura, these are already done for you.  This transpiles JS into a version all browsers support:
+
+.. code-block:: bash
+
+    (env-allura)~$ sudo aptitude install nodejs npm
+    (env-allura)~$ sudo ln -s /usr/bin/nodejs /usr/bin/node
+    (env-allura)~$ cd ~/src/allura
+    (env-allura)~$ npm install -g broccoli-cli
+    (env-allura)~$ npm install
+    (env-allura)~$ broccoli build Allura/allura/public/nf/js/build/
+
+
 The application server
 ~~~~~~~~~~~~~~~~~~~~~~
 

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/Brocfile.js
----------------------------------------------------------------------
diff --git a/Brocfile.js b/Brocfile.js
new file mode 100644
index 0000000..e16ee4c
--- /dev/null
+++ b/Brocfile.js
@@ -0,0 +1,35 @@
+var babelTranspiler = require("broccoli-babel-transpiler");
+var sourceMap = require('broccoli-source-map');
+var concat = require('broccoli-concat');
+var funnel = require('broccoli-funnel');
+var uglifyJavaScript = require('broccoli-uglify-js');
+
+var tree = funnel('Allura/allura/public/nf/js', {
+  include: ['*.es6.js'],
+});
+tree = babelTranspiler(tree, {
+    browserPolyfill: true,
+    //filterExtensions:['es6.js'],
+    sourceMaps: 'inline',  // external doesn't work, have to use extract below
+    comments: false,
+});
+tree = concat(tree, {
+  inputFiles: ['**/*.js'],
+  outputFile: '/transpiled.js'
+});
+tree = sourceMap.extract(tree);
+
+if (process.env.BROCCOLI_ENV === 'production') {
+    /* can't use this for dev mode, since it drops the sourcemap comment even if we set  output: {comments: true}
+     https://github.com/mishoo/UglifyJS2/issues/653
+     https://github.com/mishoo/UglifyJS2/issues/754
+     https://github.com/mishoo/UglifyJS2/issues/780
+     https://github.com/mishoo/UglifyJS2/issues/520
+     */
+    tree = uglifyJavaScript(tree, {
+        mangle: false,
+        compress: false
+    });
+}
+
+module.exports = tree;

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/Dockerfile
----------------------------------------------------------------------
diff --git a/Dockerfile b/Dockerfile
index 12170ef..f125d55 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -29,7 +29,10 @@ RUN apt-get update && apt-get install -y \
     python-pip \
     zip \
     subversion \
-    python-svn
+    python-svn \
+    npm
+RUN ln -s /usr/bin/nodejs /usr/bin/node
+RUN npm install -g broccoli-cli
 
 # Snapshot generation for SVN (and maybe other SCMs) might fail without this
 RUN locale-gen en_US.UTF-8
@@ -39,4 +42,5 @@ ENV LANG en_US.UTF-8
 # tests). If this is not set, it uses os.getlogin, which fails inside docker.
 ENV USER root
 
-WORKDIR /allura
+WORKDIR /allura/Allura
+CMD gunicorn --paste docker-dev.ini --reload

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/docker-compose.yml
----------------------------------------------------------------------
diff --git a/docker-compose.yml b/docker-compose.yml
index 6822677..86102ed 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -18,7 +18,17 @@
 web:
   build: .
   working_dir: /allura
-  command: bash -c 'cd Allura && gunicorn --paste docker-dev.ini --reload'
+  # specialized command (and working_dir) to run broccoli
+  # since it depends on files from the shared volume, it can't be run as part of the Dockerfile build :(
+  command: >
+    sh -c '
+    if [ ! -e Allura/allura/public/nf/js/build/transpiled.js ]; then
+      npm install &&
+      rm -rf Allura/allura/public/nf/js/build/ &&
+      broccoli build Allura/allura/public/nf/js/build/;
+    fi;
+    gunicorn --paste Allura/docker-dev.ini --reload
+    '
   ports:
     - "8080:8080"
   volumes:

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..58dcc6b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,23 @@
+{
+  "name": "allura",
+  "version": "0.0.0",
+  "description": "",
+  "main": "Brocfile.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "https://git-wip-us.apache.org/repos/asf/allura.git"
+  },
+  "author": "",
+  "license": "Apache-2.0",
+  "devDependencies": {
+    "broccoli": "^0.16.8",
+    "broccoli-babel-transpiler": "^5.4.5",
+    "broccoli-concat": "0.0.13",
+    "broccoli-funnel": "^0.2.8",
+    "broccoli-source-map": "^0.2.3",
+    "broccoli-uglify-js": "^0.1.3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/allura/blob/1dd78440/scripts/asf-release.sh
----------------------------------------------------------------------
diff --git a/scripts/asf-release.sh b/scripts/asf-release.sh
index 9239dc2..8ee73a4 100755
--- a/scripts/asf-release.sh
+++ b/scripts/asf-release.sh
@@ -41,6 +41,7 @@ prompt VERSION "Version" "$VERSION"
 RELEASE_BASE=allura-$VERSION
 RELEASE_DIR=$RELEASE_DIR_BASE/$RELEASE_BASE
 RELEASE_FILENAME=$RELEASE_BASE.tar.gz
+RELEASE_FILE_EXTRACTED=$RELEASE_DIR/$RELEASE_BASE
 RELEASE_FILE=$RELEASE_DIR/$RELEASE_FILENAME
 RELEASE_TAG=asf_release_$VERSION
 CLOSE_DATE=`date -d '+72 hours' +%F`
@@ -68,6 +69,17 @@ COMMIT_SHA=`git rev-parse $RELEASE_TAG`
 mkdir -p $RELEASE_DIR
 git archive -o $RELEASE_FILE --prefix $RELEASE_BASE/ $RELEASE_TAG
 
+# expand archive, run broccoli in it, rebuild archive
+cd $RELEASE_DIR
+tar xzf $RELEASE_FILE
+cd $RELEASE_FILE_EXTRACTED
+npm install >/dev/null
+BROCCOLI_ENV=production broccoli build Allura/allura/public/nf/js/build/
+rm -rf node_modules
+cd ..
+tar czf $RELEASE_FILE $RELEASE_BASE
+rm -rf $RELEASE_FILE_EXTRACTED
+
 gpg --default-key $KEY --armor --output $RELEASE_FILE.asc --detach-sig $RELEASE_FILE
 MD5_CHECKSUM=`cd $RELEASE_DIR ; md5sum $RELEASE_FILENAME` ; echo "$MD5_CHECKSUM" > $RELEASE_FILE.md5
 SHA1_CHECKSUM=`cd $RELEASE_DIR ; shasum -a1 $RELEASE_FILENAME` ; echo "$SHA1_CHECKSUM" > $RELEASE_FILE.sha1