Commit bd764b1d authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

supression de la dépendance à node pour la gestion des éditions & plugins

parent 96001c9b
Loading
Loading
Loading
Loading

Dockerfile

deleted100644 → 0
+0 −13
Original line number Diff line number Diff line
FROM basex/basexhttp:latest
MAINTAINER Certic-Pdn TEAM <contact.certic@unicaen.fr>
COPY max.xq /srv/basex/webapp
COPY rxq /srv/basex/webapp/rxq
COPY configuration /srv/basex/webapp/configuration
COPY editions /srv/basex/webapp/editions
COPY plugins /srv/basex/webapp/plugins
COPY ui /srv/basex/webapp/ui
COPY node_modules/bootstrap/dist/js/bootstrap.bundle.min.js /srv/basex/webapp/ui/lib
COPY node_modules/bootstrap/dist/css/bootstrap.min.css /srv/basex/webapp/ui/lib
COPY node_modules/bootstrap/dist/js/bootstrap.min.js /srv/basex/webapp/ui/lib
COPY node_modules/jquery/dist/jquery.min.js /srv/basex/webapp/ui/lib
COPY node_modules/popper.js/dist/popper.min.js /srv/basex/webapp/ui/lib
+0 −3
Original line number Diff line number Diff line
@@ -81,9 +81,6 @@ Une documentation est disponible dans le répertoire [documentation](./documenta






![UNICAEN-PDN-CERTIC](https://www.certic.unicaen.fr/ui/images/UNICAEN_PDN_CERTIC.png)

[![IA](http://medites.fr/partenaires/investissement-avenir/@@images/d94128c2-f712-4712-9659-a86f6f8f36c5.jpeg)](http://www.agence-nationale-recherche.fr/investissements-d-avenir/)
+180 −180
Original line number Diff line number Diff line
//checks dependencies availabilty
var execSync;
var fs;
try {
    require.resolve("readline");
    require.resolve("xmldom");
    execSync = require('child_process').execSync;
    fs = require('fs');

} catch (e) {
    console.log("Missing librairies - Please run npm install readline xmldom child_process");
    process.exit(e.code);
}

//imports des librairies
var fs = require('fs');
var readline = require('readline');
var DOMParser = require('xmldom').DOMParser;
var XMLSerializer = require('xmldom').XMLSerializer;


const CONFIGURATION_FOLDER_PATH = __dirname + "/../configuration/";
const EDITIONS_FOLDER_PATH = __dirname + "/../editions/";
const MAIN_CONFIG_FILE_NAME = "configuration.xml";
const MAIN_CONFIG_FILE = CONFIGURATION_FOLDER_PATH + MAIN_CONFIG_FILE_NAME;
const TEMPLATE_CONFIG_FILE = __dirname + "/edition_conf_tmpl.xml";
const EAD_TEMPLATE_CONFIG_FILE = __dirname + "/ead_edition_conf_tmpl.xml";
const DEMO_CONFIG_INC = EDITIONS_FOLDER_PATH + "max_tei_demo/max_tei_demo_config_inc.xml"

if (process.argv[2] == "-demo")
    include_baseconf("max_tei_demo", DEMO_CONFIG_INC);
else if (process.argv[2] == "-new")
    new_edition(process.argv[3],process.argv[4],process.argv[5]);
else if (process.argv[2] == "-plugin"){
    insert_plugin_config(process.argv[3], process.argv[4]);
    install_plugin_dependencies(process.argv[3]);
}
else if(process.argv[2] == "-rmplugin"){
    remove_plugin_config(process.argv[3], process.argv[4]);
}
return;


function new_edition(editionId, db, type) {
    create_project_baseconf(editionId, db, type);
}

/*
  Substitution des variables de l'édition au sein du template
  de base.
*/
 function create_project_baseconf(id, db, type_env) {
    var template = fs.readFileSync(type_env === 'ead' ? EAD_TEMPLATE_CONFIG_FILE : TEMPLATE_CONFIG_FILE, {encoding: 'utf-8'})
    template = template.replace("%ID%", id).replace("%DB%", db).replace("%ENV%", type_env);
    //Écriture du fichier de config.
    var filename = id + "_config_inc.xml";
    fs.writeFileSync(filename, template);
    if (!fs.existsSync(EDITIONS_FOLDER_PATH + id)) {
        fs.mkdirSync(EDITIONS_FOLDER_PATH + id, (err) => {
            if (err) console.log(err);
        });
    }
    //Déplacement du fichier créé dans le répertoire de l'édition.
    fs.rename(filename, EDITIONS_FOLDER_PATH + id + "/" + filename, function (err) {
        if (err) {
            return console.log(err);
        }
    });
    console.log("=== Création du fichier de configuration " + filename + " - OK");
    include_baseconf(id, EDITIONS_FOLDER_PATH + id + "/" + filename)
}

/*
Inclusion d'une configuration d'une édition au sein de la configuration globale de MaX
*/
 function include_baseconf(project_id, config_file) {
    try {
        var relative_file = config_file.split(__dirname +'/')[1]
        var include_content = "<xi:include href='" + relative_file + "' xmlns:xi='http://www.w3.org/2001/XInclude'/>";
        var config_content = fs.readFileSync(config_file, {encoding: 'utf-8'})
        var include_dom = new DOMParser().parseFromString(include_content);
        install_plugins_dependencies(new DOMParser().parseFromString(config_content));
        var main_config_content = fs.readFileSync(MAIN_CONFIG_FILE, {encoding: 'utf-8'})
        var config_dom = new DOMParser().parseFromString(main_config_content);
        var editions_node =
            config_dom.getElementsByTagName('configuration')[0].getElementsByTagName('editions')[0];
        let existing_includes = config_dom.getElementsByTagNameNS("http://www.w3.org/2001/XInclude","include");
        for(let i = 0; i < existing_includes.length; i++){
          let href = existing_includes[i].getAttribute('href');
          if(href === relative_file){
            console.log("\n[WARNING] Le projet " + project_id +" est déjà importé dans le fichier de configuration principale.\n");
            return true;
          }
        }
        var a = config_dom.importNode(include_dom, 1);
        editions_node.appendChild(a);
        var s = new XMLSerializer();

        //Le résultat de la sérialisation n'est pas correctement indentée
        fs.writeFileSync(MAIN_CONFIG_FILE, s.serializeToString(config_dom))//, function (err) {
        console.log("=== Mise à jour de la configuration principale de MaX (inclusion de " + relative_file + ") - OK");
        return true;

    } catch (e) {
        console.log(e)
    }

}

/*
* Installation des plugins
*/
function install_plugins_dependencies(dom){
    let pluginElts = dom.getElementsByTagName('plugins')[0].getElementsByTagName('plugin');
    if(pluginElts.length > 0)
      console.log("==== Installation des dépendances JS des plugins [" + pluginElts.length +"]")
    else {
      console.log("==== Aucun plugin à traiter")
    }
    for(let i = 0; i < pluginElts.length; i++){
        let name = pluginElts[i].getAttribute('name');
        install_plugin_dependencies(name);
    }
}

function install_plugin_dependencies(plugin_id){
        let path = __dirname+'/../plugins/' + plugin_id +'/resources.json';
        if (fs.existsSync(path)) {
          console.log(' + Installation des dépendances pour ' + plugin_id);
          let data = fs.readFileSync(path);
          let deps = JSON.parse(data);
          Object.keys(deps).forEach(function(k,v){
            console.log(' cp -r ' + __dirname + '/../'+deps[k] +' ' +__dirname + '/../ui/lib/');
            execSync('cp -r ' + __dirname + '/../'+deps[k] +' ' + __dirname + '/../ui/lib/');
          });
        }
        else{
          console.log(' - Pas de dépendances pour ' + plugin_id);
        }
}

function insert_plugin_config(plugin_id, edition_id){
    var config_file = EDITIONS_FOLDER_PATH + edition_id +"/"+edition_id+"_config_inc.xml";
    var config_content = fs.readFileSync(config_file,{encoding: 'utf-8'})
    var config_dom = new DOMParser().parseFromString(config_content);
    var plugins_node = config_dom.getElementsByTagName('plugins')[0];
    var enabled_plugins = plugins_node.getElementsByTagName('plugin');
    for(let i = 0 ; i < enabled_plugins.length; i++){
        var p = enabled_plugins[i];
        if(p.getAttribute('name') === plugin_id){
          return;
        }
    }

    var plugin_node = config_dom.createElement('plugin');
    plugin_node.setAttribute('name',plugin_id);
    plugins_node.appendChild(plugin_node);
    var s = new XMLSerializer();
    fs.writeFileSync(config_file, s.serializeToString(config_dom))
    return true;
}

function remove_plugin_config(plugin_id, edition_id){
    console.log('removing plugin ' + plugin_id + " for " + edition_id)
    var config_file = EDITIONS_FOLDER_PATH + edition_id +"/"+edition_id+"_config_inc.xml";
    var config_content = fs.readFileSync(config_file,{encoding: 'utf-8'})
    var config_dom = new DOMParser().parseFromString(config_content);
    var plugins_node = config_dom.getElementsByTagName('plugins')[0];
    var enabled_plugins = plugins_node.getElementsByTagName('plugin');
    for(let i = 0 ; i < enabled_plugins.length; i++){
        var p = enabled_plugins[i];
        if(p.getAttribute('name') === plugin_id){
          plugins_node.removeChild(p);
        }
    }
    var s = new XMLSerializer();
    fs.writeFileSync(config_file, s.serializeToString(config_dom));
    return true;
}
// //checks dependencies availabilty
// var execSync;
// var fs;
// try {
//     require.resolve("readline");
//     require.resolve("xmldom");
//     execSync = require('child_process').execSync;
//     fs = require('fs');
//
// } catch (e) {
//     console.log("Missing librairies - Please run npm install readline xmldom child_process");
//     process.exit(e.code);
// }
//
// //imports des librairies
// var fs = require('fs');
// var readline = require('readline');
// var DOMParser = require('xmldom').DOMParser;
// var XMLSerializer = require('xmldom').XMLSerializer;
//
//
// const CONFIGURATION_FOLDER_PATH = __dirname + "/../configuration/";
// const EDITIONS_FOLDER_PATH = __dirname + "/../editions/";
// const MAIN_CONFIG_FILE_NAME = "configuration.xml";
// const MAIN_CONFIG_FILE = CONFIGURATION_FOLDER_PATH + MAIN_CONFIG_FILE_NAME;
// const TEMPLATE_CONFIG_FILE = __dirname + "/edition_conf_tmpl.xml";
// const EAD_TEMPLATE_CONFIG_FILE = __dirname + "/ead_edition_conf_tmpl.xml";
// const DEMO_CONFIG_INC = EDITIONS_FOLDER_PATH + "max_tei_demo/max_tei_demo_config_inc.xml"
//
// // if (process.argv[2] == "-demo")
// //     include_baseconf("max_tei_demo", DEMO_CONFIG_INC);
// // else if (process.argv[2] == "-new")
// //     new_edition(process.argv[3],process.argv[4],process.argv[5]);
// if (process.argv[2] == "-plugin"){
//     insert_plugin_config(process.argv[3], process.argv[4]);
//     install_plugin_dependencies(process.argv[3]);
// }
// else if(process.argv[2] == "-rmplugin"){
//     remove_plugin_config(process.argv[3], process.argv[4]);
// }
// return;
//
//
// function new_edition(editionId, db, type) {
//     create_project_baseconf(editionId, db, type);
// }
//
// /*
//   Substitution des variables de l'édition au sein du template
//   de base.
// */
//  function create_project_baseconf(id, db, type_env) {
//     var template = fs.readFileSync(type_env === 'ead' ? EAD_TEMPLATE_CONFIG_FILE : TEMPLATE_CONFIG_FILE, {encoding: 'utf-8'})
//     template = template.replace("%ID%", id).replace("%DB%", db).replace("%ENV%", type_env);
//     //Écriture du fichier de config.
//     var filename = id + "_config_inc.xml";
//     fs.writeFileSync(filename, template);
//     if (!fs.existsSync(EDITIONS_FOLDER_PATH + id)) {
//         fs.mkdirSync(EDITIONS_FOLDER_PATH + id, (err) => {
//             if (err) console.log(err);
//         });
//     }
//     //Déplacement du fichier créé dans le répertoire de l'édition.
//     fs.rename(filename, EDITIONS_FOLDER_PATH + id + "/" + filename, function (err) {
//         if (err) {
//             return console.log(err);
//         }
//     });
//     console.log("=== Création du fichier de configuration " + filename + " - OK");
//     include_baseconf(id, EDITIONS_FOLDER_PATH + id + "/" + filename)
// }
//
// /*
// Inclusion d'une configuration d'une édition au sein de la configuration globale de MaX
// */
//  function include_baseconf(project_id, config_file) {
//     try {
//         var relative_file = config_file.split(__dirname +'/')[1]
//         var include_content = "<xi:include href='" + relative_file + "' xmlns:xi='http://www.w3.org/2001/XInclude'/>";
//         var config_content = fs.readFileSync(config_file, {encoding: 'utf-8'})
//         var include_dom = new DOMParser().parseFromString(include_content);
//         install_plugins_dependencies(new DOMParser().parseFromString(config_content));
//         var main_config_content = fs.readFileSync(MAIN_CONFIG_FILE, {encoding: 'utf-8'})
//         var config_dom = new DOMParser().parseFromString(main_config_content);
//         var editions_node =
//             config_dom.getElementsByTagName('configuration')[0].getElementsByTagName('editions')[0];
//         let existing_includes = config_dom.getElementsByTagNameNS("http://www.w3.org/2001/XInclude","include");
//         for(let i = 0; i < existing_includes.length; i++){
//           let href = existing_includes[i].getAttribute('href');
//           if(href === relative_file){
//             console.log("\n[WARNING] Le projet " + project_id +" est déjà importé dans le fichier de configuration principale.\n");
//             return true;
//           }
//         }
//         var a = config_dom.importNode(include_dom, 1);
//         editions_node.appendChild(a);
//         var s = new XMLSerializer();
//
//         //Le résultat de la sérialisation n'est pas correctement indentée
//         fs.writeFileSync(MAIN_CONFIG_FILE, s.serializeToString(config_dom))//, function (err) {
//         console.log("=== Mise à jour de la configuration principale de MaX (inclusion de " + relative_file + ") - OK");
//         return true;
//
//     } catch (e) {
//         console.log(e)
//     }
//
// }
//
// /*
// * Installation des plugins
// */
// function install_plugins_dependencies(dom){
//     let pluginElts = dom.getElementsByTagName('plugins')[0].getElementsByTagName('plugin');
//     if(pluginElts.length > 0)
//       console.log("==== Installation des dépendances JS des plugins [" + pluginElts.length +"]")
//     else {
//       console.log("==== Aucun plugin à traiter")
//     }
//     for(let i = 0; i < pluginElts.length; i++){
//         let name = pluginElts[i].getAttribute('name');
//         install_plugin_dependencies(name);
//     }
// }
//
// function install_plugin_dependencies(plugin_id){
//         let path = __dirname+'/../plugins/' + plugin_id +'/resources.json';
//         if (fs.existsSync(path)) {
//           console.log(' + Installation des dépendances pour ' + plugin_id);
//           let data = fs.readFileSync(path);
//           let deps = JSON.parse(data);
//           Object.keys(deps).forEach(function(k,v){
//             console.log(' cp -r ' + __dirname + '/../'+deps[k] +' ' +__dirname + '/../ui/lib/');
//             execSync('cp -r ' + __dirname + '/../'+deps[k] +' ' + __dirname + '/../ui/lib/');
//           });
//         }
//         else{
//           console.log(' - Pas de dépendances pour ' + plugin_id);
//         }
// }
//
// function insert_plugin_config(plugin_id, edition_id){
//     var config_file = EDITIONS_FOLDER_PATH + edition_id +"/"+edition_id+"_config_inc.xml";
//     var config_content = fs.readFileSync(config_file,{encoding: 'utf-8'})
//     var config_dom = new DOMParser().parseFromString(config_content);
//     var plugins_node = config_dom.getElementsByTagName('plugins')[0];
//     var enabled_plugins = plugins_node.getElementsByTagName('plugin');
//     for(let i = 0 ; i < enabled_plugins.length; i++){
//         var p = enabled_plugins[i];
//         if(p.getAttribute('name') === plugin_id){
//           return;
//         }
//     }
//
//     var plugin_node = config_dom.createElement('plugin');
//     plugin_node.setAttribute('name',plugin_id);
//     plugins_node.appendChild(plugin_node);
//     var s = new XMLSerializer();
//     fs.writeFileSync(config_file, s.serializeToString(config_dom))
//     return true;
// }
//
// function remove_plugin_config(plugin_id, edition_id){
//     console.log('removing plugin ' + plugin_id + " for " + edition_id)
//     var config_file = EDITIONS_FOLDER_PATH + edition_id +"/"+edition_id+"_config_inc.xml";
//     var config_content = fs.readFileSync(config_file,{encoding: 'utf-8'})
//     var config_dom = new DOMParser().parseFromString(config_content);
//     var plugins_node = config_dom.getElementsByTagName('plugins')[0];
//     var enabled_plugins = plugins_node.getElementsByTagName('plugin');
//     for(let i = 0 ; i < enabled_plugins.length; i++){
//         var p = enabled_plugins[i];
//         if(p.getAttribute('name') === plugin_id){
//           plugins_node.removeChild(p);
//         }
//     }
//     var s = new XMLSerializer();
//     fs.writeFileSync(config_file, s.serializeToString(config_dom));
//     return true;
// }
//
+16 −22
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ display_usage(){
    echo ""
    echo "   -h: Display help."
    echo "   -p: Specify BaseX port to use for db feed. Default one is "$PORT"."
    echo "   -i: Max env initialization."
    echo "   -i: Max development env initialization."
    echo "   -d: Deploy the demo edition project."
    echo "   -n: Deploy new edition with its XML sources."
    echo "   --list-plugins: show plugins and status."
@@ -91,16 +91,19 @@ enable_plugin(){
      return
  fi

  if [ ! -f $MAX_PLUGINS_DIR/$1/.ignore ]
  if [ -f $MAX_PLUGINS_DIR/$1/.ignore ]
  then
      echo -e "Plugin $1 was already enabled."
      echo -e ''
      return
      rm $MAX_PLUGINS_DIR/$1/.ignore
  fi

  rm $MAX_PLUGINS_DIR/$1/.ignore
  node $DIRECTORY/edition_manager.js -plugin $1 $2
  $BASEX_BIN -u -bpluginId=$1 -bprojectId=$2 $DIRECTORY"/xq/insert_plugin_config.xq" # -u => save modified file on disk

  if [ $? -eq 0 ]
  then
    echo -e "Plugin $1 successfully enabled"
  else
    echo -e "ERROR - Plugin $1 was not enabled !"
  fi
  echo -e ''
}

@@ -113,7 +116,7 @@ disable_plugin(){
    return
  fi

  node $DIRECTORY/edition_manager.js -rmplugin $1 $2
  $BASEX_BIN -u -bpluginId=$1 -bprojectId=$2 $DIRECTORY"/xq/remove_plugin_config.xq" # -u => save modified file on disk

  NB_USAGE=$($BASEX_BIN "count(doc('../configuration/configuration.xml')//plugin[@name='$1'])")

@@ -125,13 +128,6 @@ disable_plugin(){
  echo -e ''
}

#enable_project_plugins(){
#  config_file=$DIRECTORY/../editions/$1/$1_config_inc.xml
#  plugins=$($BASEX_BIN -i$config_file "for \$i in //plugins/plugin/@name return string(\$i)")
#  for p in $plugins
#    do enable_plugin $p
#  done
#}

# 1 argument required
if [  $# -lt 1 ]
@@ -203,7 +199,7 @@ demo_edition_build(){
#    cp $DIRECTORY/demo/demo_lorem_config_inc.xml $DIRECTORY/../editions/demo_lorem
#    echo "  -> resource files copy: DONE"
    cd $DIRECTORY/../editions
    echo "Downloading Max TEI Demo ressources"
    echo "Downloading Max TEI Demo resources"

    wget $DEMO_RELEASE_URL

@@ -226,8 +222,6 @@ demo_edition_build(){
    enable_plugin img_viewer max_tei_demo
    enable_plugin search max_tei_demo
    enable_plugin tei_pdf max_tei_demo

    #node $DIRECTORY/edition_manager.js -demo
    include_project_config max_tei_demo

    if [ $? -ne 0 ]
@@ -265,9 +259,9 @@ format_configuration_file(){
    rm $FILE".bak"
}

init_max(){
init_dev_max(){
    cd $DIRECTORY/..
    echo " -> Fetches node dependencies."
    #echo " -> Fetches node dependencies."
    npm install
    echo " -> Adds nodes_modules/.ignore file."
    #creates a .ignore file in nodejs dependencies folder
@@ -336,6 +330,6 @@ fi

if [ $CHOOSEN_MODE == $INIT_MODE ]
then
    init_max
    init_dev_max
    exit 0
fi
+28 −0
Original line number Diff line number Diff line
(: création du fichier de configuration de base pour un nouveau projet:)

declare variable $projectId external;
declare variable $dbPath external;
declare variable $envType external;

let $config :=
    if($envType = 'ead')
    then
        <edition xml:id="{$projectId}" dbpath="{$dbPath}" env="{$envType}" prettyName="My EAD edition">
            <textOptions>
            </textOptions>

            <plugins>
                <plugin name="side_toc"/>
            </plugins>
        </edition>
    else
        <edition xml:id="{$projectId}" dbpath="{$dbPath}" env="{$envType}" prettyName="My {$envType} edition">
            <textOptions>
            </textOptions>

            <plugins>
            </plugins>

        </edition>

return file:write('../editions/'||$projectId||'/'||$projectId||'_config_inc.xml', $config)
Loading