1#!/usr/bin/php
2<?php
3/**
4 * This script builds the extension version of the plugin
5 */
6if('cli' != php_sapi_name()) die('This is a command line script only');
7if(!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../../');
8require_once(DOKU_INC . 'inc/init.php');
9
10// build script
11{
12    // open output
13    $fh = fopen(__DIR__ . '/extension/script.js', 'w');
14
15    // add comment
16    fwrite($fh, "/**
17 * Injected content script, extending the DokuWiki toolbar
18 *
19 * This script is built automatically from the source files
20 * using the extension.php script. It should not be edited.
21 * See https://github.com/splitbrain/dokuwiki-plugin-toolbox
22 * for the original files and for contributing to the extension.
23 */
24");
25
26    // load the language files
27    unset($lang);
28    /** @var array $lang */
29    include("lang/en/lang.php");
30    fwrite($fh, 'var toolbox_lang = ' . json_encode($lang['js']) . ";\n");
31
32    // set the icon base
33    fwrite($fh, "var toolbox_icon = '//github.com/splitbrain/dokuwiki-plugin-toolbox/raw/master/pix/';\n");
34
35    // add the scripts
36    $scripts = glob(__DIR__ . '/Toolbox*.js');
37    $scripts[] = __DIR__ . '/toolbox.js';
38    foreach($scripts as $script) {
39        fwrite($fh, file_get_contents($script));
40    }
41
42    // reinitialize the toolbar
43    fwrite($fh, "var tb = document.getElementById('toolbox__picker');");
44    fwrite($fh, "if(!tb) initToolbar('tool__bar','wiki__text',toolbar);");
45
46    // close output
47    fclose($fh);
48}
49
50// set version in manifest
51{
52    $info = confToHash(__DIR__ . '/plugin.info.txt');
53    $manifest = __DIR__ . '/extension/manifest.json';
54    $m = json_decode(file_get_contents($manifest));
55    $m->version = str_replace('-', '.', $info['date']);
56    file_put_contents($manifest, json_encode($m, JSON_PRETTY_PRINT));
57}
58
59// create zip file
60{
61    $filename = __DIR__ . '/extension.zip';
62    $zip = new ZipArchive();
63    if($zip->open($filename, ZipArchive::CREATE) !== true) {
64        die("cannot open <$filename>\n");
65    }
66
67    $files = glob(__DIR__ . '/extension/*');
68    foreach($files as $file) {
69        $zip->addFile($file, basename($file));
70    }
71
72    $zip->close();
73}
74