kopia lustrzana https://github.com/c9/core
commit
77da3de516
|
@ -0,0 +1,140 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
/*global describe it*/
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
"use server";
|
||||||
|
|
||||||
|
|
||||||
|
require("amd-loader");
|
||||||
|
require("c9/inline-mocha")(module);
|
||||||
|
|
||||||
|
var assert = require("assert");
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
describe("client config consistency", function(){
|
||||||
|
// this.timeout(60000);
|
||||||
|
|
||||||
|
var fileCache = Object.create(null);
|
||||||
|
var clientOptions;
|
||||||
|
var root = __dirname + "/../";
|
||||||
|
|
||||||
|
it("should get clientOptions from server", function(next) {
|
||||||
|
fetchClientOptions(function(err, clientOptions) {
|
||||||
|
assert(!err && clientOptions);
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.readdirSync(root + "/configs").forEach(function(name) {
|
||||||
|
if (!/client-(workspace|ssh|default)/.test(name)) return;
|
||||||
|
|
||||||
|
it("should not have missing plugins in config " + name, function(next) {
|
||||||
|
fetchClientOptions(function(err, clientOptions) {
|
||||||
|
if (err) return next();
|
||||||
|
checkConfig(name, clientOptions, next);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function fetchClientOptions(callback) {
|
||||||
|
if (clientOptions)
|
||||||
|
return callback(null, JSON.parse(JSON.stringify(clientOptions)));
|
||||||
|
var server = require(root + "/server.js");
|
||||||
|
server(["--_getConfig", "-l", "localhost", "--collab=true"], "", function(e, plugins) {
|
||||||
|
clientOptions = plugins.filter(function(p) {
|
||||||
|
return /standalone[\\\/]standalone/.test(p.packagePath);
|
||||||
|
})[0].options;
|
||||||
|
fetchClientOptions(callback);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkConfig(name, clientOptions, next) {
|
||||||
|
var hasError = false;
|
||||||
|
var configPath = root + "/configs/" + name;
|
||||||
|
var configPathReal = fs.realpathSync(configPath);
|
||||||
|
var clientPlugins = require(configPath)(clientOptions);
|
||||||
|
|
||||||
|
clientPlugins = clientPlugins.map(function(p, i) {
|
||||||
|
if (typeof p == "string")
|
||||||
|
return {packagePath: p};
|
||||||
|
return p;
|
||||||
|
});
|
||||||
|
clientPlugins.forEach(function(p) {
|
||||||
|
if (p.packagePath) {
|
||||||
|
if (!fileCache[p.packagePath]) {
|
||||||
|
|
||||||
|
var filePath;
|
||||||
|
try {
|
||||||
|
filePath = require.resolve(p.packagePath);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
try {
|
||||||
|
filePath = require.resolve(p.packagePath.replace(/^plugins\//, ""));
|
||||||
|
} catch (e) {
|
||||||
|
// TODO instead of quessing we need a simple way of getting pathmap
|
||||||
|
if (configPath != configPathReal)
|
||||||
|
filePath = require.resolve(configPathReal + "/../../node_modules/" + p.packagePath.replace(/^plugins\//, ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!filePath.match(/\.js$/))
|
||||||
|
filePath += ".js";
|
||||||
|
|
||||||
|
fileCache[p.packagePath] = fs.readFileSync(filePath, "utf8");
|
||||||
|
}
|
||||||
|
var source = fileCache[p.packagePath];
|
||||||
|
p.provides = getDeps("provides", source);
|
||||||
|
p.consumes = getDeps("consumes", source);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var provides = {"auth.bootstrap": 1, "hub": 1};
|
||||||
|
var paths = {};
|
||||||
|
clientPlugins.forEach(function(p) {
|
||||||
|
if (paths[p.packagePath]) {
|
||||||
|
console.error(name, paths[p.packagePath].packagePath, p.packagePath);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
paths[p.packagePath] = p;
|
||||||
|
p.provides && p.provides.forEach(function(name) {
|
||||||
|
if (provides[name]) {
|
||||||
|
// console.warn(name, p.packagePath, provides[name]);
|
||||||
|
}
|
||||||
|
provides[name] = p.packagePath;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var unresolved = [];
|
||||||
|
clientPlugins.forEach(function(p) {
|
||||||
|
var missing = (p.consumes || []).filter(function(name) {
|
||||||
|
return !provides[name];
|
||||||
|
});
|
||||||
|
if (missing.length) {
|
||||||
|
unresolved.push({
|
||||||
|
packagePath: p.packagePath,
|
||||||
|
missing: missing
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (unresolved.length) {
|
||||||
|
// not throwing an error to check all configs
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDeps(type, source) {
|
||||||
|
var re = new RegExp(type + /\s*=\s*(\[[^\[\]]*\])/.source);
|
||||||
|
var m = source.match(re);
|
||||||
|
if (!m) return [];
|
||||||
|
m = m[1].replace(/\/\/.*|\/\*[\s\S]*?\*\//g, "")
|
||||||
|
.replace(/,\s*\]/g, "]")
|
||||||
|
.replace(/'/g, "\"");
|
||||||
|
return JSON.parse(m);
|
||||||
|
}
|
||||||
|
assert(!unresolved.length, (
|
||||||
|
"unresolved plugins in /configs/" + name +
|
||||||
|
JSON.stringify(unresolved, null, 4)
|
||||||
|
).replace(/^/gm, "\t")
|
||||||
|
);
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
|
@ -2,13 +2,17 @@
|
||||||
set -e
|
set -e
|
||||||
cd `dirname $0`/..
|
cd `dirname $0`/..
|
||||||
|
|
||||||
# set -x
|
|
||||||
NAME=$1
|
NAME=$1
|
||||||
shift
|
shift
|
||||||
BRANCH=master
|
BRANCH=master
|
||||||
URL=
|
URL=
|
||||||
|
FORCE=
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
case $i in
|
case $i in
|
||||||
|
-d|--debug)
|
||||||
|
set -x
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-b=*|--branch=*)
|
-b=*|--branch=*)
|
||||||
BRANCH="${i#*=}"
|
BRANCH="${i#*=}"
|
||||||
shift
|
shift
|
||||||
|
@ -17,6 +21,10 @@ for i in "$@"; do
|
||||||
URL="${i#*=}"
|
URL="${i#*=}"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-f|--force|--hard)
|
||||||
|
FORCE=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
# unknown option
|
# unknown option
|
||||||
;;
|
;;
|
||||||
|
@ -28,29 +36,45 @@ if [ "$NAME" == "" ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
update_one() {
|
||||||
echo adding name=$NAME url=$URL branch=refs/remotes/origin/$BRANCH
|
echo adding name=$NAME url=$URL branch=refs/remotes/origin/$BRANCH
|
||||||
|
|
||||||
if [ "$URL" == "" ]; then
|
if [ "$URL" == "" ]; then
|
||||||
URL=git@github.com:c9/$NAME.git
|
URL=git@github.com:c9/$NAME.git
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d $NAME/.git ]; then
|
mkdir -p $NAME
|
||||||
pushd $NAME
|
pushd $NAME
|
||||||
|
|
||||||
|
if ! [ -d .git ]; then
|
||||||
|
git init .
|
||||||
|
git remote add origin "$URL"
|
||||||
|
fi
|
||||||
|
|
||||||
OLD_URL=$(git config --get remote.origin.url)
|
OLD_URL=$(git config --get remote.origin.url)
|
||||||
if [ "$OLD_URL" != "$URL" ]; then
|
if [ "$OLD_URL" != "$URL" ]; then
|
||||||
echo "folder $NAME exists and points to $OLD_URL"
|
echo "folder $NAME exists and points to $OLD_URL"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if ! $(git config --get-all remote.origin.fetch | grep -q pull); then
|
||||||
|
git config --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/pull/*";
|
||||||
|
fi
|
||||||
git fetch origin
|
git fetch origin
|
||||||
git remote set-head origin -a
|
git remote set-head origin -a
|
||||||
popd
|
popd
|
||||||
else
|
|
||||||
mkdir -p $NAME
|
|
||||||
git clone $URL $NAME
|
|
||||||
fi
|
|
||||||
|
|
||||||
pushd $NAME
|
pushd $NAME
|
||||||
HASH=$(git rev-parse --revs-only refs/remotes/origin/$BRANCH)
|
HASH=$(git rev-parse --revs-only refs/remotes/origin/$BRANCH)
|
||||||
|
if [ "$FORCE" == "1" ]; then
|
||||||
|
echo "hard reset $NAME to $HASH"
|
||||||
|
git reset $HASH --hard
|
||||||
|
if $(grep -q dependencies "./package.json"); then
|
||||||
|
rm -rf node_modules npm-shrinkwrap.json
|
||||||
|
git reset --hard
|
||||||
|
npm i
|
||||||
|
npm shrinkwrap
|
||||||
|
fi
|
||||||
|
fi
|
||||||
popd
|
popd
|
||||||
|
|
||||||
[ -f ./config.json ] || echo "{}" > ./config.json
|
[ -f ./config.json ] || echo "{}" > ./config.json
|
||||||
|
@ -81,17 +105,37 @@ node -e '
|
||||||
});
|
});
|
||||||
updateJSON("../package.json", function(package) {
|
updateJSON("../package.json", function(package) {
|
||||||
var deps = package.dependencies;
|
var deps = package.dependencies;
|
||||||
console.log(deps[name], hash)
|
console.log(deps[name], hash);
|
||||||
deps[name] = deps[name].replace(/#[a-f\d]*$/i, "#" + hash)
|
deps[name] = deps[name].replace(/#[a-f\d]*$/i, "#" + hash);
|
||||||
console.log(deps[name], hash)
|
console.log(deps[name], hash);
|
||||||
});
|
});
|
||||||
updateJSON("../npm-shrinkwrap.json", function(package) {
|
updateJSON("../npm-shrinkwrap.json", function(package) {
|
||||||
var deps = package.dependencies;
|
var deps = package.dependencies;
|
||||||
deps[name].from = deps[name].from.replace(/#[a-f\d]*$/i, "#" + hash);
|
deps[name].from = deps[name].from.replace(/#[a-f\d]*$/i, "#" + hash);
|
||||||
deps[name].resolved = deps[name].resolved.replace(/#[a-f\d]*$/i, "#" + hash);
|
deps[name].resolved = deps[name].resolved.replace(/#[a-f\d]*$/i, "#" + hash);
|
||||||
|
console.log(__dirname)
|
||||||
|
if (fs.existsSync(name + "/npm-shrinkwrap.json")) {
|
||||||
|
var shrinkwrap = JSON.parse(fs.readFileSync(name + "/npm-shrinkwrap.json", "utf8"));
|
||||||
|
deps[name].dependencies = shrinkwrap.dependencies;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
'
|
'
|
||||||
|
|
||||||
rm -rf "../node_modules/$NAME"
|
rm -rf "../node_modules/$NAME"
|
||||||
ln -s `pwd`/$NAME `pwd`/../node_modules/$NAME
|
ln -s `pwd`/$NAME `pwd`/../node_modules/$NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$NAME" == "all" ]; then
|
||||||
|
for i in $(ls .); do
|
||||||
|
if [ -d "./$i/.git" ] || [ -f "./$i/package.json" ]; then
|
||||||
|
NAME=$i
|
||||||
|
URL=
|
||||||
|
update_one;
|
||||||
|
fi;
|
||||||
|
done
|
||||||
|
else
|
||||||
|
update_one
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue