Mwalker has submitted this change and it was merged.

Change subject: Updating submodule pointers and unifying the makefile
......................................................................


Updating submodule pointers and unifying the makefile

Change-Id: Iadc058fbee6d3fbb92d8647a82339b005feab035
---
M .gitignore
A Makefile
D make.sh
M mw-ocg-bundler
M mw-ocg-latexer
M mw-ocg-service
M mw-ocg-texter
A unify-package-json.js
8 files changed, 171 insertions(+), 24 deletions(-)

Approvals:
  Mwalker: Verified; Looks good to me, approved



diff --git a/.gitignore b/.gitignore
index 1bc63e8..fe26abb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
 node_modules/*
 
 LocalSettings.js
+
+.idea
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..56be9fd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,20 @@
+all: debug
+
+core:
+       rm ./package.json
+       npm cache clear
+       npm install when
+       ./unify-package-json.js
+       npm install
+       npm update
+       npm dedupe
+
+production: core
+       npm prune --production
+       rm -rf ./node_modules/icu-bidi/build
+
+debug: core
+       npm prune
+
+clean:
+       rm -rf ./node_modules
diff --git a/make.sh b/make.sh
deleted file mode 100755
index 5462176..0000000
--- a/make.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/bash
-# Make the node_modules folder
-
-SCRIPTPATH=`dirname $(readlink -f ./make.sh)`
-mkdir -p node_modules
-
-for f in ./mw-ocg*/
-do
-       ln -s $SCRIPTPATH/node_modules $f/node_modules
-       cd $f
-       npm install
-       NPMEXIT=$?
-
-       cd ..
-       #rm $f/node_modules
-
-       if [ $NPMEXIT != 0 ]; then
-               echo "npm install for $f exited with failure"
-               exit $?
-       fi
-done
-
-echo "Done! Apparent success"
-
diff --git a/mw-ocg-bundler b/mw-ocg-bundler
index b44b3b5..085d024 160000
--- a/mw-ocg-bundler
+++ b/mw-ocg-bundler
-Subproject commit b44b3b51fc8b4862b5a2e6486967548920f9ad26
+Subproject commit 085d024cdc33d82fb2cc4b9d7a1560a24dd6910c
diff --git a/mw-ocg-latexer b/mw-ocg-latexer
index fcbe016..9bff3d6 160000
--- a/mw-ocg-latexer
+++ b/mw-ocg-latexer
-Subproject commit fcbe016e0ed942552a9b464e329d0fb0698768bd
+Subproject commit 9bff3d6da3ad1255f5c9d5f8d8a190756545acfe
diff --git a/mw-ocg-service b/mw-ocg-service
index 1262422..91eaf0c 160000
--- a/mw-ocg-service
+++ b/mw-ocg-service
-Subproject commit 1262422a81eb193247ff828090df8a0d71343e63
+Subproject commit 91eaf0cbda583e299084cc5cf5ec372c452b98fb
diff --git a/mw-ocg-texter b/mw-ocg-texter
index 291563f..de48026 160000
--- a/mw-ocg-texter
+++ b/mw-ocg-texter
-Subproject commit 291563f95694b60a01ba571945516b58e439c0f3
+Subproject commit de48026939d70695867aa6cd2b44b692ac590ee2
diff --git a/unify-package-json.js b/unify-package-json.js
new file mode 100755
index 0000000..2234c6a
--- /dev/null
+++ b/unify-package-json.js
@@ -0,0 +1,149 @@
+#!/usr/bin/env nodejs
+
+/**
+ * Make script to composite dependencies of node modules into one big file.
+ *
+ * This will find all package.json files recursively and merge them into one.
+ * It will throw errors if multiple files reference different versions of the
+ * same upstream package.
+ *
+ * Ironically; this script itself has dependencies in the form of the when 
library
+ * (because node.js for some stupid reason doesn't include promises anymore)
+ */
+
+var child_process = require( 'child_process' ),
+       semver = require( 'semver' ),
+       fs = require( 'fs' ),
+       util = require( 'util' );
+
+try {
+       var when = require('when');
+} catch ( err ) {
+       console.err( "The 'when' library could not be loaded. Please `npm 
install when`")
+}
+
+function findPackageJson() {
+       return when.promise( function( resolve, reject, notify ) {
+               child_process.exec(
+                       'find . -path ./node_modules -prune -o -name 
package.json -print',
+                       function( error, stdout, stderr ) {
+                               files = stdout.trim().split( '\n' );
+                               resolve( files );
+                       }
+               )
+       } );
+}
+
+function readPackageJson( files ) {
+       return when.map(
+               files,
+               function( file ) {
+                       return require( file );
+               }
+       );
+}
+
+function buildDependencies( packageObjs ) {
+       var glodeps, optdeps, glodevdeps;
+       var iterate = function iterate( key, arrayObj ) {
+               var unifiedDeps = {};
+
+               arrayObj.forEach( function( el ) {
+                       var name = el.name,
+                               packdeps = el[key],
+                               pkg, glover, pkgver;
+
+                       for ( pkg in packdeps ) {
+                               if ( !packdeps.hasOwnProperty( pkg ) ) {
+                                       continue;
+                               }
+
+                               if ( pkg in unifiedDeps ) {
+                                       // Check to see if the versions are 
compatible
+                                       glover = unifiedDeps[pkg][0];
+                                       pkgver = packdeps[pkg];
+
+                                       // Strict equality is nice; they need 
the same thing
+                                       if ( glover === pkgver ) {
+                                               continue;
+                                       }
+
+                                       // If either is an approximate version 
(major / minor match) strip
+                                       // the tidle so semver can process and 
then see if the other requirement matches
+                                       if ( glover[0] === '~' && 
semver.satisfies( glover.substr( 1 ), pkgver ) ) {
+                                               continue;
+                                       }
+                                       if ( pkgver[0] === '~' && 
semver.satisfies( pkgver.substr( 1 ), glover ) ) {
+                                               continue;
+                                       }
+
+                                       // TODO: Handle greater than / less 
than.
+
+                                       console.error(
+                                               util.format(
+                                                       'Could not reconcile 
common dependency on %s. %s requires %s where %s requires %s.',
+                                                       pkg,
+                                                       unifiedDeps[pkg][1], 
glover,
+                                                       name, pkgver
+                                               )
+                                       );
+
+                               } else {
+                                       // Not already used, just add it
+                                       unifiedDeps[pkg] = [packdeps[pkg], 
name];
+                               }
+                       }
+               } );
+
+               // Clean the metadata we left
+               for ( dep in unifiedDeps ) {
+                       if ( !unifiedDeps.hasOwnProperty( dep ) ) {
+                               continue;
+                       }
+                       unifiedDeps[dep] = unifiedDeps[dep][0];
+               }
+
+               return unifiedDeps;
+       };
+
+       console.info( 'Unifying runtime dependencies' );
+       glodeps = iterate( 'dependencies', packageObjs );
+       console.info( 'Unifying optional dependencies' );
+       optdeps = iterate( 'optionalDependencies', packageObjs );
+       console.info( 'Unifying unified development dependencies' );
+       glodevdeps = iterate( 'devDependencies', packageObjs );
+
+       return {
+               'dependencies': glodeps,
+               'optionalDependencies': optdeps,
+               'devDependencies': glodevdeps
+       };
+}
+
+function writePackageJson( deps ) {
+       var packageObj = {
+               name: "mw-ocg-service-bundle",
+               description: "Common build dependency bundle for the MediaWiki 
Offline Content Generator",
+               repository: {
+                       type: "git",
+                       url: 
"gerrit.wikimedia.org/r/mediawiki/services/ocg-collection"
+               },
+
+               dependencies: deps.dependencies,
+               optionalDependencies: deps.optionalDependencies,
+               devDependencies: deps.devDependencies
+       };
+
+       fs.writeFile( 'package.json', JSON.stringify( packageObj, null, 2 ), 
function( err ) {
+               console.log('wrote file');
+       } );
+}
+
+/* === Glue logic === */
+findPackageJson()
+       .then( readPackageJson )
+       .then( when.lift( buildDependencies ) )
+       .then( writePackageJson )
+       .catch( function( err ) { console.error( err ) });
+
+

-- 
To view, visit https://gerrit.wikimedia.org/r/134523
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iadc058fbee6d3fbb92d8647a82339b005feab035
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/ocg-collection
Gerrit-Branch: master
Gerrit-Owner: Mwalker <mwal...@wikimedia.org>
Gerrit-Reviewer: Mwalker <mwal...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to