@citolab/tspci 2.8.2 → 2.9.7

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.
@@ -16,6 +16,16 @@ clean_dir_contents() {
16
16
  mkdir -p "${NPM_CACHE_DIR}"
17
17
  clean_dir_contents "${TEST_ROOT}"
18
18
 
19
+ # On Windows (Git Bash), convert Unix-style paths to native Windows paths so
20
+ # npm can resolve file: references correctly. No-op on Linux/macOS.
21
+ npm_path() {
22
+ if command -v cygpath &>/dev/null; then
23
+ cygpath -m "$1"
24
+ else
25
+ echo "$1"
26
+ fi
27
+ }
28
+
19
29
  TARBALLS=()
20
30
  cleanup() {
21
31
  for file in "${TARBALLS[@]:-}"; do
@@ -37,7 +47,7 @@ pack_local_pkg() {
37
47
  local tgz
38
48
  prepare_pkg_for_pack "${pkg_dir}"
39
49
  echo " - packing ${pkg_name}" >&2
40
- tgz="$(cd "${pkg_dir}" && npm pack --silent --ignore-scripts --cache "${NPM_CACHE_DIR}" | tail -n 1)"
50
+ tgz="$(cd "${pkg_dir}" && npm pack --silent --ignore-scripts --cache "${NPM_CACHE_DIR}" | tail -n 1 | tr -d '\r')"
41
51
  local full_path="${pkg_dir}/${tgz}"
42
52
  TARBALLS+=("${full_path}")
43
53
  echo "${full_path}"
@@ -76,7 +86,7 @@ create_project() {
76
86
  pkg.dependencies["@citolab/preact-store"] = `file:${preactStoreTar}`;
77
87
  }
78
88
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
79
- ' "${project_dir}/package.json" "${TSPCI_TGZ}" "${PREACT_STORE_TGZ}"
89
+ ' "${project_dir}/package.json" "$(npm_path "${TSPCI_TGZ}")" "$(npm_path "${PREACT_STORE_TGZ}")"
80
90
 
81
91
  (cd "${project_dir}" && npm install --cache "${NPM_CACHE_DIR}" --workspaces=false)
82
92
  }
@@ -112,21 +122,21 @@ run_base_build "${TEST_ROOT}/TypeScriptTailwindPci"
112
122
 
113
123
  echo "Scenario 4: add tspci-qbci and export .ci package"
114
124
  create_project "QbciPci" "typescript" "QBCI export matrix test"
115
- (cd "${TEST_ROOT}/QbciPci" && npm install --save-dev "file:${QBCI_TGZ}" --cache "${NPM_CACHE_DIR}" --workspaces=false)
125
+ (cd "${TEST_ROOT}/QbciPci" && npm install --save-dev "file:$(npm_path "${QBCI_TGZ}")" --cache "${NPM_CACHE_DIR}" --workspaces=false)
116
126
  (cd "${TEST_ROOT}/QbciPci" && npm run tspci -- add --target qbci)
117
127
  (cd "${TEST_ROOT}/QbciPci" && npm run prod -- --target qbci)
118
128
  ls "${TEST_ROOT}/QbciPci/ci-dist/"*.ci >/dev/null
119
129
 
120
130
  echo "Scenario 5: add tspci-qti3 and export qti3 zip"
121
131
  create_project "Qti3Pci" "typescript" "QTI3 export matrix test"
122
- (cd "${TEST_ROOT}/Qti3Pci" && npm install --save-dev "file:${QTI3_TGZ}" --cache "${NPM_CACHE_DIR}" --workspaces=false)
132
+ (cd "${TEST_ROOT}/Qti3Pci" && npm install --save-dev "file:$(npm_path "${QTI3_TGZ}")" --cache "${NPM_CACHE_DIR}" --workspaces=false)
123
133
  (cd "${TEST_ROOT}/Qti3Pci" && npm run tspci -- add --target qti3)
124
134
  (cd "${TEST_ROOT}/Qti3Pci" && npm run prod -- --target qti3)
125
135
  ls "${TEST_ROOT}/Qti3Pci/qti3-dist/"*.zip >/dev/null
126
136
 
127
137
  echo "Scenario 6: add tspci-tao and export tao zip"
128
138
  create_project "TaoPci" "typescript" "TAO export matrix test"
129
- (cd "${TEST_ROOT}/TaoPci" && npm install --save-dev "file:${TAO_TGZ}" --cache "${NPM_CACHE_DIR}" --workspaces=false)
139
+ (cd "${TEST_ROOT}/TaoPci" && npm install --save-dev "file:$(npm_path "${TAO_TGZ}")" --cache "${NPM_CACHE_DIR}" --workspaces=false)
130
140
  (cd "${TEST_ROOT}/TaoPci" && npm run tspci -- add --target tao --ci)
131
141
  node -e '
132
142
  const fs = require("fs");
@@ -146,7 +156,7 @@ ls "${TEST_ROOT}/TaoPci/dist/tao-pci-"*.zip >/dev/null
146
156
 
147
157
  echo "Scenario 7: preact-store with TypeScript + tailwind builds"
148
158
  create_project "TailwindPreactStorePci" "preact+tailwind" "Tailwind + preact-store matrix test"
149
- (cd "${TEST_ROOT}/TailwindPreactStorePci" && npm install --save "file:${PREACT_STORE_TGZ}" --cache "${NPM_CACHE_DIR}" --workspaces=false)
159
+ (cd "${TEST_ROOT}/TailwindPreactStorePci" && npm install --save "file:$(npm_path "${PREACT_STORE_TGZ}")" --cache "${NPM_CACHE_DIR}" --workspaces=false)
150
160
  run_base_build "${TEST_ROOT}/TailwindPreactStorePci"
151
161
 
152
162
  echo ""
package/src/cli.js CHANGED
@@ -9,12 +9,13 @@ import fs from "fs";
9
9
  import os from "os";
10
10
  import clear from "clear";
11
11
  import figlet from "figlet";
12
- import inquirer from "inquirer";
12
+ import chokidar from "chokidar";
13
+ import { select } from "@inquirer/prompts";
13
14
 
14
15
  const args = process.argv.slice(2);
15
16
 
16
17
  // PK: retreive dirname, most of the time automaticly inserted in es modules
17
- import { fileURLToPath } from "url";
18
+ import { fileURLToPath, pathToFileURL } from "url";
18
19
  const __filename = fileURLToPath(import.meta.url);
19
20
  const __dirname = path.dirname(__filename);
20
21
 
@@ -22,6 +23,52 @@ const PACKAGE_ROOT_PATH = process.cwd();
22
23
  const PACKAGE_DIST_PATH = path.join(PACKAGE_ROOT_PATH, "dist");
23
24
  const NODE_MODULES = path.join(process.cwd(), "node_modules");
24
25
 
26
+ const getDevIndexHtmlSourceCandidates = (target = "IMS") => {
27
+ const projectSource = path.join(PACKAGE_ROOT_PATH, "src/index.html");
28
+ const templateSource =
29
+ target === "IMS"
30
+ ? path.join(__dirname, "../public/index.html")
31
+ : path.join(NODE_MODULES, `@citolab/tspci-${target}/public/index.html`);
32
+ return { projectSource, templateSource };
33
+ };
34
+
35
+ const resolveActiveDevIndexHtmlSource = (target = "IMS") => {
36
+ const { projectSource, templateSource } = getDevIndexHtmlSourceCandidates(target);
37
+ return fs.existsSync(projectSource) ? projectSource : templateSource;
38
+ };
39
+
40
+ const copyDevIndexHtmlToDist = (target = "IMS", reason = "initial") => {
41
+ const source = resolveActiveDevIndexHtmlSource(target);
42
+ if (!fs.existsSync(source)) {
43
+ throw new Error(`No index.html template found for dev mode. Expected: ${source}`);
44
+ }
45
+ fs.copyFileSync(source, path.join(PACKAGE_DIST_PATH, "index.html"));
46
+ console.log(`index.html copied to dist (${reason}) from ${source}`);
47
+ };
48
+
49
+ const watchDevIndexHtmlSources = (target = "IMS") => {
50
+ const { projectSource, templateSource } = getDevIndexHtmlSourceCandidates(target);
51
+ const watcher = chokidar.watch([projectSource, templateSource], {
52
+ ignoreInitial: true,
53
+ awaitWriteFinish: {
54
+ stabilityThreshold: 120,
55
+ pollInterval: 20,
56
+ },
57
+ });
58
+
59
+ watcher.on("all", (event, changedPath) => {
60
+ try {
61
+ copyDevIndexHtmlToDist(target, `${event}: ${changedPath}`);
62
+ } catch (err) {
63
+ console.error(`Failed to refresh index.html after ${event} on ${changedPath}`, err);
64
+ }
65
+ });
66
+
67
+ const closeWatcher = () => watcher.close();
68
+ process.on("SIGINT", closeWatcher);
69
+ process.on("SIGTERM", closeWatcher);
70
+ };
71
+
25
72
  // https://rollupjs.org/guide/en/#programmatically-loading-a-config-file
26
73
  const watchBuild = (devServer = false, target = "IMS") => {
27
74
  const rollupFile = devServer ? "rollup.config.dev.js" : "rollup.config.js";
@@ -36,27 +83,8 @@ const watchBuild = (devServer = false, target = "IMS") => {
36
83
  }
37
84
  if (devServer) {
38
85
  try {
39
- if (fs.existsSync(path.join(PACKAGE_ROOT_PATH, "src/index.html"))) {
40
- fs.copyFile(
41
- path.join(PACKAGE_ROOT_PATH, "src/index.html"),
42
- path.join(PACKAGE_DIST_PATH, "index.html"),
43
- (err) => {
44
- if (err) throw err;
45
- console.log("using index.html found in src/index.html, copied to dist");
46
- }
47
- );
48
- } else {
49
- let fileToCopy;
50
- if (target == "IMS") {
51
- fileToCopy = path.join(__dirname, `../public/index.html`);
52
- } else {
53
- fileToCopy = path.join(NODE_MODULES, `@citolab/tspci-${target}/public/index.html`);
54
- }
55
- fs.copyFile(fileToCopy, path.join(PACKAGE_DIST_PATH, "index.html"), (err) => {
56
- if (err) throw err;
57
- console.log("using index.html was copied to /dist folder pci");
58
- });
59
- }
86
+ copyDevIndexHtmlToDist(target);
87
+ watchDevIndexHtmlSources(target);
60
88
  } catch (err) {
61
89
  console.error(err);
62
90
  }
@@ -110,16 +138,13 @@ const prodBuild = async () => {
110
138
  });
111
139
  };
112
140
 
113
- function selectOptions(prompt, options) {
114
- return inquirer.prompt([
115
- {
116
- type: "list",
117
- message: prompt,
118
- name: "value",
119
- choices: options,
120
- default: options[0],
121
- },
122
- ]);
141
+ async function selectOptions(prompt, options) {
142
+ const value = await select({
143
+ message: prompt,
144
+ choices: options.map((o) => ({ value: o })),
145
+ default: options[0],
146
+ });
147
+ return { value };
123
148
  }
124
149
 
125
150
  function askOption(prompt) {
@@ -446,7 +471,7 @@ const run = async () => {
446
471
  let init = false;
447
472
  if (fs.existsSync(scriptFile)) {
448
473
  // run init() script
449
- import(`file:///${scriptFile}`).then((script) => {
474
+ import(pathToFileURL(scriptFile).href).then((script) => {
450
475
  if (script.init) {
451
476
  init = true;
452
477
  console.log(chalk.green(`Running init script for ${targetName}`));
@@ -511,7 +536,7 @@ const run = async () => {
511
536
  return;
512
537
  }
513
538
  const scriptFile = path.join(path.join(path.join(NODE_MODULES, `${targetName}`), "src"), `createPackage.mjs`);
514
- import(`file:///${scriptFile}`).then((script) => {
539
+ import(pathToFileURL(scriptFile).href).then((script) => {
515
540
  script.bundle();
516
541
  });
517
542
  });