@citolab/tspci-qbci 2.0.9 → 2.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -674
- package/package.json +2 -2
- package/public/index.html +141 -140
- package/questify-default/metadata.json +6 -6
- package/questify-default/ref/json/manifest.json +4 -4
- package/readme.md +16 -16
- package/release-notes.md +3 -3
- package/src/createPackage.mjs +114 -114
- package/types/index.d.ts +53 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/tspci-qbci",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.3.0-alpha.0",
|
|
4
4
|
"description": "create a .ci file that can be imported into Questify",
|
|
5
5
|
"author": "patrick <patrick.deklein@cito.nl>, Marcel Hoekstra <marcel.hoekstra@cito.nl>",
|
|
6
6
|
"repository": "",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"archiver": "^5.3.0"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {},
|
|
13
|
-
"gitHead": "
|
|
13
|
+
"gitHead": "872d3b8628f1e7e9b2568563b8aae5ffa1a818d6",
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
}
|
package/public/index.html
CHANGED
|
@@ -1,140 +1,141 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Hello RequireJS</title>
|
|
5
|
-
|
|
6
|
-
<script
|
|
7
|
-
src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
|
|
8
|
-
integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg=="
|
|
9
|
-
crossorigin="anonymous"
|
|
10
|
-
referrerpolicy="no-referrer"
|
|
11
|
-
></script>
|
|
12
|
-
<!-- <link rel="stylesheet" class="bootswatcher" href="//bootswatch.com/5/lumen/bootstrap.min.css" /> -->
|
|
13
|
-
|
|
14
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" />
|
|
15
|
-
|
|
16
|
-
<style>
|
|
17
|
-
html {
|
|
18
|
-
font-size: 100%;
|
|
19
|
-
}
|
|
20
|
-
#pciContainer {
|
|
21
|
-
display:block;
|
|
22
|
-
width: 100%;
|
|
23
|
-
/* min-width: 800px; */
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
import {
|
|
50
|
-
import
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
localStorage.removeItem(item.typeIdentifier + "
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
item.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
iframeDoc.
|
|
116
|
-
iframeDoc.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<
|
|
123
|
-
|
|
124
|
-
<li>Is the css
|
|
125
|
-
<li>
|
|
126
|
-
<li>Can
|
|
127
|
-
<li>Can
|
|
128
|
-
<li>
|
|
129
|
-
<li>
|
|
130
|
-
<li>
|
|
131
|
-
<li>
|
|
132
|
-
<li>
|
|
133
|
-
<li>
|
|
134
|
-
<li>
|
|
135
|
-
<li>
|
|
136
|
-
<li>
|
|
137
|
-
<li>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
</
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Hello RequireJS</title>
|
|
5
|
+
|
|
6
|
+
<script
|
|
7
|
+
src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
|
|
8
|
+
integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg=="
|
|
9
|
+
crossorigin="anonymous"
|
|
10
|
+
referrerpolicy="no-referrer"
|
|
11
|
+
></script>
|
|
12
|
+
<!-- <link rel="stylesheet" class="bootswatcher" href="//bootswatch.com/5/lumen/bootstrap.min.css" /> -->
|
|
13
|
+
|
|
14
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" />
|
|
15
|
+
|
|
16
|
+
<style>
|
|
17
|
+
html {
|
|
18
|
+
font-size: 100%;
|
|
19
|
+
}
|
|
20
|
+
#pciContainer {
|
|
21
|
+
display:block;
|
|
22
|
+
width: 100%;
|
|
23
|
+
/* min-width: 800px; */
|
|
24
|
+
padding: 20px;
|
|
25
|
+
max-width: 1024px;
|
|
26
|
+
height: 600px;
|
|
27
|
+
min-height: 600px;
|
|
28
|
+
/* max-height: 600px; */
|
|
29
|
+
border: 1px solid #eeeeee;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
margin: 0 auto;
|
|
32
|
+
background-color: white;
|
|
33
|
+
border-radius: 10px;
|
|
34
|
+
margin-top: 1rem;
|
|
35
|
+
}
|
|
36
|
+
#devtools {
|
|
37
|
+
max-width: 1024px;
|
|
38
|
+
margin: 0 auto;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
41
|
+
</head>
|
|
42
|
+
<body class="bg-light">
|
|
43
|
+
<div class="container">
|
|
44
|
+
<iframe id="pciContainer" class="shadow-sm"> </iframe>
|
|
45
|
+
<div id="devtools"></div>
|
|
46
|
+
</div>
|
|
47
|
+
|
|
48
|
+
<script type="module">
|
|
49
|
+
import { h, Component, render } from "https://unpkg.com/preact@latest?module";
|
|
50
|
+
import { useState, useEffect } from "https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module";
|
|
51
|
+
import htm from "https://unpkg.com/htm?module";
|
|
52
|
+
// Initialize htm with Preact
|
|
53
|
+
const html = htm.bind(h);
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
const [show, setShow] = useState(false);
|
|
57
|
+
|
|
58
|
+
function resetlocalstorage() {
|
|
59
|
+
localStorage.removeItem(item.typeIdentifier + "_props");
|
|
60
|
+
localStorage.removeItem(item.typeIdentifier + "_response");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function reload() {
|
|
64
|
+
const response = window["CES"].getResponse();
|
|
65
|
+
localStorage.setItem("ci_response", response);
|
|
66
|
+
location.reload();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function changeConfig(key, value) {
|
|
70
|
+
item.config.properties[key] = value;
|
|
71
|
+
item.trigger(`change${key}`, value);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function reConfig(key, value) {
|
|
75
|
+
localStorage.setItem(item.typeIdentifier + "_props", JSON.stringify(item.config.properties));
|
|
76
|
+
location.reload();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return html`
|
|
80
|
+
<div>
|
|
81
|
+
<div class="d-flex justify-content-start mt-3" role="toolbar" aria-label="Toolbar with button groups">
|
|
82
|
+
<div class="btn-group me-2 shadow-sm" role="group" aria-label="Basic checkbox toggle button group">
|
|
83
|
+
<button class="btn btn-outline-secondary" onClick="${() => reload()}">reload</button>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const localStorageResponse = localStorage.getItem("ci_response");
|
|
91
|
+
let response;
|
|
92
|
+
if (localStorageResponse) {
|
|
93
|
+
response = localStorageResponse;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
window["CES"] = {
|
|
97
|
+
response: response,
|
|
98
|
+
setResponse: (data) => {
|
|
99
|
+
console.log("setting the data", data)
|
|
100
|
+
response = data;
|
|
101
|
+
},
|
|
102
|
+
getResponse: () => {
|
|
103
|
+
console.log("getting the data");
|
|
104
|
+
return response;
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
var iframe = document.getElementById("pciContainer"),
|
|
108
|
+
iframeWin = iframe.contentWindow || iframe,
|
|
109
|
+
iframeDoc = iframe.contentDocument || iframeWin.document;
|
|
110
|
+
|
|
111
|
+
iframe.onload = () => {
|
|
112
|
+
render(html`<${App} />`, document.getElementById("devtools"));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
iframeDoc.open();
|
|
116
|
+
iframeDoc.write("\<html>\<head>\<script src='index.js'>\<\/script>\<\/head>\<body>\<\/body>\<\/html>");
|
|
117
|
+
iframeDoc.close();
|
|
118
|
+
|
|
119
|
+
localStorage.removeItem("ci_response");
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<h3 style="margin-top: 12rem">checklist</h3>
|
|
123
|
+
<ul style="margin-bottom: 10rem">
|
|
124
|
+
<li>Is the css scoped to the item?</li>
|
|
125
|
+
<li>Is the css/item somewhat responsive on smaller screens</li>
|
|
126
|
+
<li>Can you reset the item to its initial state</li>
|
|
127
|
+
<li>Can it restore its state ( reload )</li>
|
|
128
|
+
<li>Can you change the config</li>
|
|
129
|
+
<li>Colorblind</li>
|
|
130
|
+
<li>Touch/Mouse friendly</li>
|
|
131
|
+
<li>Works in older browser like IE11</li>
|
|
132
|
+
<li>Destroys itself correctly, removing event listeners</li>
|
|
133
|
+
<li>No objects or variables on global scope</li>
|
|
134
|
+
<li>Triggers correctly on changed config properties</li>
|
|
135
|
+
<li>Implements on off() methods of tao?</li>
|
|
136
|
+
<li>Response type and response correct</li>
|
|
137
|
+
<li>getResponse() should give undefined when user has not done anything</li>
|
|
138
|
+
<li>For TAO to enter response is the entered comparable by the response given</li>
|
|
139
|
+
</ul>
|
|
140
|
+
</body>
|
|
141
|
+
</html>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "###___title___###",
|
|
3
|
-
"typeIdentifier": "###___typeIdentifier___###",
|
|
4
|
-
"width": 500,
|
|
5
|
-
"height": 500,
|
|
6
|
-
"scalable": true
|
|
1
|
+
{
|
|
2
|
+
"title": "###___title___###",
|
|
3
|
+
"typeIdentifier": "###___typeIdentifier___###",
|
|
4
|
+
"width": 500,
|
|
5
|
+
"height": 500,
|
|
6
|
+
"scalable": true
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"script": ["ref/script/index.min.js"],
|
|
3
|
-
"style": [],
|
|
4
|
-
"media": []
|
|
1
|
+
{
|
|
2
|
+
"script": ["ref/script/index.min.js"],
|
|
3
|
+
"style": [],
|
|
4
|
+
"media": []
|
|
5
5
|
}
|
package/readme.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
## @citolab/qbci
|
|
2
|
-
|
|
3
|
-
Create a .ci to import into Questify
|
|
4
|
-
|
|
5
|
-
# run
|
|
6
|
-
``` sh
|
|
7
|
-
tspci --target qbci
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
## config options
|
|
11
|
-
|
|
12
|
-
In the package.json of the pci:
|
|
13
|
-
- typeIdentifier (required)
|
|
14
|
-
- label (if empty, package name will be used)
|
|
15
|
-
- width
|
|
16
|
-
- height
|
|
1
|
+
## @citolab/qbci
|
|
2
|
+
|
|
3
|
+
Create a .ci to import into Questify
|
|
4
|
+
|
|
5
|
+
# run
|
|
6
|
+
``` sh
|
|
7
|
+
tspci --target qbci
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## config options
|
|
11
|
+
|
|
12
|
+
In the package.json of the pci:
|
|
13
|
+
- typeIdentifier (required)
|
|
14
|
+
- label (if empty, package name will be used)
|
|
15
|
+
- width
|
|
16
|
+
- height
|
package/release-notes.md
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
# 2.0.0
|
|
2
|
-
|
|
3
|
-
- first release questify builder ci plugin
|
|
1
|
+
# 2.0.0
|
|
2
|
+
|
|
3
|
+
- first release questify builder ci plugin
|
package/src/createPackage.mjs
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import fs, { mkdirSync } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import archiver from "archiver";
|
|
4
|
-
import { exit } from "process";
|
|
5
|
-
|
|
6
|
-
export const bundle = () => {
|
|
7
|
-
const PACKAGE_ROOT_PATH = process.cwd();
|
|
8
|
-
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-qbci");
|
|
9
|
-
|
|
10
|
-
const outputDirectory = path.join(PACKAGE_ROOT_PATH, "dist");
|
|
11
|
-
const outputDirectoryTemp = path.join(outputDirectory, "tmp");
|
|
12
|
-
|
|
13
|
-
// remove directory to be sure it's empty
|
|
14
|
-
if (fs.existsSync(outputDirectoryTemp)) {
|
|
15
|
-
fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// re-create the directory
|
|
19
|
-
if (!fs.existsSync(outputDirectory)) {
|
|
20
|
-
mkdirSync(outputDirectory);
|
|
21
|
-
}
|
|
22
|
-
if (!fs.existsSync(outputDirectoryTemp)) {
|
|
23
|
-
mkdirSync(outputDirectoryTemp);
|
|
24
|
-
}
|
|
25
|
-
const config = path.join(PACKAGE_ROOT_PATH, "package.json");
|
|
26
|
-
if (!fs.existsSync(config)) {
|
|
27
|
-
console.error(`cannot find package.json: ${config}`);
|
|
28
|
-
process.exit();
|
|
29
|
-
}
|
|
30
|
-
const rawConfigData = fs.readFileSync(config);
|
|
31
|
-
const packageData = JSON.parse(rawConfigData);
|
|
32
|
-
|
|
33
|
-
const questifyMetadata = path.join(path.join(PACKAGER_PATH, "questify-default"), "metadata.json");
|
|
34
|
-
if (!fs.existsSync(config)) {
|
|
35
|
-
console.error(`cannot find metadata.json: ${questifyMetadata}`);
|
|
36
|
-
process.exit();
|
|
37
|
-
}
|
|
38
|
-
const rawMetadata = fs.readFileSync(questifyMetadata);
|
|
39
|
-
const questifyMetadataData = JSON.parse(rawMetadata);
|
|
40
|
-
|
|
41
|
-
const propertiesToCopy = ["width", "height"];
|
|
42
|
-
|
|
43
|
-
copyDirectoryRecursiveSync(path.join(PACKAGER_PATH, "questify-default"), outputDirectoryTemp, false);
|
|
44
|
-
|
|
45
|
-
const name = packageData.label
|
|
46
|
-
? packageData.label
|
|
47
|
-
: packageData.name
|
|
48
|
-
? packageData.name.split("/")[packageData.name.split("/").length - 1]
|
|
49
|
-
: "ci";
|
|
50
|
-
const typeIdentifier = packageData.typeIdentifier;
|
|
51
|
-
if (!typeIdentifier) {
|
|
52
|
-
console.error("missing type identifier in package.json");
|
|
53
|
-
process.exit();
|
|
54
|
-
}
|
|
55
|
-
questifyMetadataData.typeIdentifier = typeIdentifier;
|
|
56
|
-
questifyMetadataData.title = name;
|
|
57
|
-
for (const propertyName in propertiesToCopy) {
|
|
58
|
-
if (packageData[propertyName]) {
|
|
59
|
-
questifyMetadataData[propertyName] = packageData[propertyName];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const metadataString = JSON.stringify(questifyMetadataData);
|
|
63
|
-
fs.writeFileSync(path.join(outputDirectoryTemp, "metadata.json"), metadataString, "utf8");
|
|
64
|
-
|
|
65
|
-
// copy the actual PCI file
|
|
66
|
-
const pciFile = config.main || "/dist/index.js";
|
|
67
|
-
|
|
68
|
-
// pk: add .min. to the name else QB is gonna minify it and it BREAKS
|
|
69
|
-
fs.copyFileSync(path.join(PACKAGE_ROOT_PATH, pciFile), path.join(outputDirectoryTemp, "/ref/script/index.min.js"));
|
|
70
|
-
|
|
71
|
-
// zip the folder
|
|
72
|
-
const zipName = `questify-ci-${name}_${packageData.version}.ci`;
|
|
73
|
-
zipDirectory(outputDirectoryTemp, path.join(outputDirectory, zipName)).then(() =>
|
|
74
|
-
// fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
75
|
-
console.log(`created questify ci zip: ${zipName}`)
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
function copyDirectoryRecursiveSync(source, target) {
|
|
80
|
-
if (!fs.lstatSync(source).isDirectory() || source.endsWith("tmp")) return;
|
|
81
|
-
// var operation = move ? fs.renameSync : fs.copyFileSync;
|
|
82
|
-
fs.readdirSync(source).forEach(function (itemName) {
|
|
83
|
-
if (!(itemName.indexOf("questify-pci-") !== -1 && itemName.indexOf(".zip") !== -1)) {
|
|
84
|
-
var sourcePath = path.join(source, itemName);
|
|
85
|
-
var targetPath = path.join(target, itemName);
|
|
86
|
-
if (fs.lstatSync(sourcePath).isDirectory()) {
|
|
87
|
-
if (!fs.existsSync(targetPath) && !targetPath.toLocaleLowerCase().endsWith("tmp")) {
|
|
88
|
-
fs.mkdirSync(targetPath);
|
|
89
|
-
}
|
|
90
|
-
copyDirectoryRecursiveSync(sourcePath, targetPath);
|
|
91
|
-
} else {
|
|
92
|
-
if (fs.existsSync(targetPath)) {
|
|
93
|
-
fs.unlinkSync(targetPath);
|
|
94
|
-
}
|
|
95
|
-
fs.copyFileSync(sourcePath, targetPath, 0);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function zipDirectory(sourceDir, outPath) {
|
|
102
|
-
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
103
|
-
const stream = fs.createWriteStream(outPath);
|
|
104
|
-
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
archive
|
|
107
|
-
.directory(sourceDir, false)
|
|
108
|
-
.on("error", (err) => reject(err))
|
|
109
|
-
.pipe(stream);
|
|
110
|
-
|
|
111
|
-
stream.on("close", () => resolve());
|
|
112
|
-
archive.finalize();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
1
|
+
import fs, { mkdirSync } from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import archiver from "archiver";
|
|
4
|
+
import { exit } from "process";
|
|
5
|
+
|
|
6
|
+
export const bundle = () => {
|
|
7
|
+
const PACKAGE_ROOT_PATH = process.cwd();
|
|
8
|
+
const PACKAGER_PATH = path.join(PACKAGE_ROOT_PATH + "/node_modules/@citolab/tspci-qbci");
|
|
9
|
+
|
|
10
|
+
const outputDirectory = path.join(PACKAGE_ROOT_PATH, "dist");
|
|
11
|
+
const outputDirectoryTemp = path.join(outputDirectory, "tmp");
|
|
12
|
+
|
|
13
|
+
// remove directory to be sure it's empty
|
|
14
|
+
if (fs.existsSync(outputDirectoryTemp)) {
|
|
15
|
+
fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// re-create the directory
|
|
19
|
+
if (!fs.existsSync(outputDirectory)) {
|
|
20
|
+
mkdirSync(outputDirectory);
|
|
21
|
+
}
|
|
22
|
+
if (!fs.existsSync(outputDirectoryTemp)) {
|
|
23
|
+
mkdirSync(outputDirectoryTemp);
|
|
24
|
+
}
|
|
25
|
+
const config = path.join(PACKAGE_ROOT_PATH, "package.json");
|
|
26
|
+
if (!fs.existsSync(config)) {
|
|
27
|
+
console.error(`cannot find package.json: ${config}`);
|
|
28
|
+
process.exit();
|
|
29
|
+
}
|
|
30
|
+
const rawConfigData = fs.readFileSync(config);
|
|
31
|
+
const packageData = JSON.parse(rawConfigData);
|
|
32
|
+
|
|
33
|
+
const questifyMetadata = path.join(path.join(PACKAGER_PATH, "questify-default"), "metadata.json");
|
|
34
|
+
if (!fs.existsSync(config)) {
|
|
35
|
+
console.error(`cannot find metadata.json: ${questifyMetadata}`);
|
|
36
|
+
process.exit();
|
|
37
|
+
}
|
|
38
|
+
const rawMetadata = fs.readFileSync(questifyMetadata);
|
|
39
|
+
const questifyMetadataData = JSON.parse(rawMetadata);
|
|
40
|
+
|
|
41
|
+
const propertiesToCopy = ["width", "height"];
|
|
42
|
+
|
|
43
|
+
copyDirectoryRecursiveSync(path.join(PACKAGER_PATH, "questify-default"), outputDirectoryTemp, false);
|
|
44
|
+
|
|
45
|
+
const name = packageData.label
|
|
46
|
+
? packageData.label
|
|
47
|
+
: packageData.name
|
|
48
|
+
? packageData.name.split("/")[packageData.name.split("/").length - 1]
|
|
49
|
+
: "ci";
|
|
50
|
+
const typeIdentifier = packageData.typeIdentifier;
|
|
51
|
+
if (!typeIdentifier) {
|
|
52
|
+
console.error("missing type identifier in package.json");
|
|
53
|
+
process.exit();
|
|
54
|
+
}
|
|
55
|
+
questifyMetadataData.typeIdentifier = typeIdentifier;
|
|
56
|
+
questifyMetadataData.title = name;
|
|
57
|
+
for (const propertyName in propertiesToCopy) {
|
|
58
|
+
if (packageData[propertyName]) {
|
|
59
|
+
questifyMetadataData[propertyName] = packageData[propertyName];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const metadataString = JSON.stringify(questifyMetadataData);
|
|
63
|
+
fs.writeFileSync(path.join(outputDirectoryTemp, "metadata.json"), metadataString, "utf8");
|
|
64
|
+
|
|
65
|
+
// copy the actual PCI file
|
|
66
|
+
const pciFile = config.main || "/dist/index.js";
|
|
67
|
+
|
|
68
|
+
// pk: add .min. to the name else QB is gonna minify it and it BREAKS
|
|
69
|
+
fs.copyFileSync(path.join(PACKAGE_ROOT_PATH, pciFile), path.join(outputDirectoryTemp, "/ref/script/index.min.js"));
|
|
70
|
+
|
|
71
|
+
// zip the folder
|
|
72
|
+
const zipName = `questify-ci-${name}_${packageData.version}.ci`;
|
|
73
|
+
zipDirectory(outputDirectoryTemp, path.join(outputDirectory, zipName)).then(() =>
|
|
74
|
+
// fs.rmdirSync(outputDirectoryTemp, { recursive: true });
|
|
75
|
+
console.log(`created questify ci zip: ${zipName}`)
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function copyDirectoryRecursiveSync(source, target) {
|
|
80
|
+
if (!fs.lstatSync(source).isDirectory() || source.endsWith("tmp")) return;
|
|
81
|
+
// var operation = move ? fs.renameSync : fs.copyFileSync;
|
|
82
|
+
fs.readdirSync(source).forEach(function (itemName) {
|
|
83
|
+
if (!(itemName.indexOf("questify-pci-") !== -1 && itemName.indexOf(".zip") !== -1)) {
|
|
84
|
+
var sourcePath = path.join(source, itemName);
|
|
85
|
+
var targetPath = path.join(target, itemName);
|
|
86
|
+
if (fs.lstatSync(sourcePath).isDirectory()) {
|
|
87
|
+
if (!fs.existsSync(targetPath) && !targetPath.toLocaleLowerCase().endsWith("tmp")) {
|
|
88
|
+
fs.mkdirSync(targetPath);
|
|
89
|
+
}
|
|
90
|
+
copyDirectoryRecursiveSync(sourcePath, targetPath);
|
|
91
|
+
} else {
|
|
92
|
+
if (fs.existsSync(targetPath)) {
|
|
93
|
+
fs.unlinkSync(targetPath);
|
|
94
|
+
}
|
|
95
|
+
fs.copyFileSync(sourcePath, targetPath, 0);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function zipDirectory(sourceDir, outPath) {
|
|
102
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
103
|
+
const stream = fs.createWriteStream(outPath);
|
|
104
|
+
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
archive
|
|
107
|
+
.directory(sourceDir, false)
|
|
108
|
+
.on("error", (err) => reject(err))
|
|
109
|
+
.pipe(stream);
|
|
110
|
+
|
|
111
|
+
stream.on("close", () => resolve());
|
|
112
|
+
archive.finalize();
|
|
113
|
+
});
|
|
114
|
+
}
|