Skip to content
Snippets Groups Projects
osuny.js 4.13 KiB
Newer Older
Arnaud Levy's avatar
Arnaud Levy committed
#! /usr/bin/env node

Alexis BENOIT's avatar
Alexis BENOIT committed
const shell = require("shelljs"),
    dev = require("./dev"),
    migrate = require("./migrate/migrate"),
    updateNodeVersion = require("./update-version/update-node-version");
shell.set('-e'); // exit upon first error
Olivia Simonet's avatar
Olivia Simonet committed
console.log(`
  .=*#%%#*=        -*#%%#*=.      =+-      ++.     .+ .+#%%#+.     :++      -+-
 :@@=:..:+@@.     #@#:..:+@@.     *@*      @@:     -@#@+:..-@@-    -@@      *@*
 +@*      %@=    .@@.     %@=     *@*      @@:     -@@.     *@*    -@@      *@*
 +@*      %@=     %@*     *%=     *@*      @@:     -@@      *@*    -@@      *@*
 +@*      %@=      +@@=           *@*      @@:     -@@      *@*    -@@      *@*
 +@*      %@=       .+@@+.        *@*      @@:     -@@      *@*    -@@      *@*
 +@*      %@=         .+@@+.      *@*      @@:     -@@      *@*    .@@=.   :@@=
 +@*      %@=     ==     +@@:     *@*      @@:     -@@      *@*     .+%@@@@%*-
 +@*      %@=    .@@.     +@#     *@*     .@@:     -@@      *@*         @@-
 =@%     .@@-     @@-     #@#     +@#    :#@@:     -@@      *@*         @@-
  =%@%##%@%=      :#@%##%@@*       *@@##@%=:@:     :@@      *@+         %@-
     .:..            ..:.            ...
Arnaud Levy's avatar
Arnaud Levy committed
 `);
Arnaud Levy's avatar
Arnaud Levy committed

const command = process.argv[2];

Arnaud Levy's avatar
Arnaud Levy committed
let pagefindExclude = '';
// Categories: No list of categories
pagefindExclude += '.categories__taxonomy, .categories__term, ';
pagefindExclude += '.posts_categories__taxonomy, .posts_categories__term, ';
pagefindExclude += '.events_categories__taxonomy, .events_categories__term, ';
// Diplomas: No list of diplomas or block diplomas
pagefindExclude += '.diplomas__taxonomy, .block-diplomas, ';
// Agenda events: No list of events or block events
pagefindExclude += '.events__section, .block-agenda, ';
// Organizations: No list of organizations or block organizations
pagefindExclude += '.organizations__section, .block-organizations, ';
// Pages: No block pages (there's no difference between list and page)
pagefindExclude += '.block-pages, ';
// Persons: no list or block
pagefindExclude += '.persons__section, .block-persons, ';
// No list of people's facets
pagefindExclude += '.administrators__term, .authors__term, .researchers__term, .teachers__term,';
// Posts: no list, block posts, or post sidebar
pagefindExclude += '.posts__section, .block-posts, .post-sidebar, ';
// Programs: no block
pagefindExclude += '.block-programs';
Alexis BENOIT's avatar
Alexis BENOIT committed

function execute(string) {
    console.log("OSUNY runs " + string);
    shell.exec(string);
Arnaud Levy's avatar
Arnaud Levy committed
if (command === "watch") {
    execute("hugo server");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "dev") {
    execute("hugo");
    execute("npx pagefind --site 'public' --output-subdir '../static/pagefind' --glob '**/index.{html}' --exclude-selectors '" + pagefindExclude + "'");
    execute("hugo server");
Arnaud Levy's avatar
Arnaud Levy committed
}

Alexis BENOIT's avatar
Alexis BENOIT committed
if (command === "local") {
    var IP = dev.network["en0"][0] || "0.0.0.0";
    execute("hugo");
    execute("npx pagefind --site 'public' --output-subdir '../static/pagefind' --glob '**/index.{html}' --exclude-selectors '" + pagefindExclude + "'");
Alexis BENOIT's avatar
Alexis BENOIT committed
    execute("hugo server --bind=" + IP + " --baseURL=http://" + IP + ":1313 -D");
}

Arnaud Levy's avatar
Arnaud Levy committed
if (command === "build") {
alexisben's avatar
alexisben committed
    execute("hugo --minify");
    execute("npm_config_yes=true npx pagefind --site 'public' --glob '**/index.{html}' --exclude-selectors '" + pagefindExclude + "'");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "percy-build") {
    execute("yarn upgrade");
    execute("hugo --baseURL=/");
    execute("npm_config_yes=true npx pagefind --site 'public' --glob '**/index.{html}' --exclude-selectors '" + pagefindExclude + "'");
Arnaud Levy's avatar
Arnaud Levy committed
if (command === "update") {
    execute("git pull --recurse-submodules --depth 1");
    execute("git submodule update --remote");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "setup-example") {
    execute("git submodule add https://github.com/noesya/osuny-example");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "server-example") {
    execute("hugo server --config osuny-example/config/example/config.yaml");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "example") {
Arnaud Levy's avatar
Arnaud Levy committed
    execute("yarn setup-example > /dev/null || yarn upgrade");
    execute("yarn osuny server-example");
Arnaud Levy's avatar
Arnaud Levy committed
}

if (command === "update-theme") {
    execute("git submodule update --remote");
    execute("yarn upgrade");
Arnaud Levy's avatar
Arnaud Levy committed
}
if (command === "migrate") {
    migrate(process.argv);
}