@m2c2kit/core 0.1.10 → 0.3.6

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/index.html ADDED
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="Cache-Control" content="no-store, max-age=0" />
6
+ <meta http-equiv="Pragma" content="no-cache" />
7
+ <meta http-equiv="Expires" content="0" />
8
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
9
+ <link href="assets/css/m2c2kit.css" rel="preload" as="style" />
10
+ <link href="assets/css/m2c2kit.css" rel="stylesheet" />
11
+ <link href="assets/css/defaultV2.css" rel="stylesheet" />
12
+ <link href="assets/css/nouislider.css" rel="stylesheet" />
13
+ <link href="assets/css/select2.css" rel="stylesheet" />
14
+ <link
15
+ href="assets/css/bootstrap-datepicker.standalone.css"
16
+ rel="stylesheet"
17
+ />
18
+ <link href="assets/css/bootstrap-slider.css" rel="stylesheet" />
19
+ <script type="module" src="./index.js" defer></script>
20
+ </head>
21
+
22
+ <body class="m2c2kit-background-color m2c2kit-no-margin">
23
+ <div id="m2c2kit-survey-div"></div>
24
+ <div
25
+ class="m2c2kit-full-viewport m2c2kit-flex-container"
26
+ id="m2c2kit-container-div"
27
+ >
28
+ <canvas class="m2c2kit-full-viewport" id="m2c2kit-canvas"></canvas>
29
+ </div>
30
+ </body>
31
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m2c2kit/core",
3
- "version": "0.1.10",
3
+ "version": "0.3.6",
4
4
  "description": "The m2c2kit core functionality",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -11,33 +11,39 @@
11
11
  },
12
12
  "files": [
13
13
  "dist/index.js",
14
- "dist/index.d.ts"
14
+ "dist/index.d.ts",
15
+ "assets/**",
16
+ "index.html",
17
+ "post-install.mjs"
15
18
  ],
16
19
  "scripts": {
17
- "build": "rollup -c",
18
- "test": "jest"
20
+ "build": "npm run clean && tsc && rollup -c",
21
+ "clean": "rimraf build build-nobundler build-umd dist .rollup.cache tsconfig.tsbuildinfo",
22
+ "test": "jest",
23
+ "postinstall": "node post-install.mjs"
19
24
  },
20
25
  "license": "MIT",
21
- "dependencies": {
22
- "canvaskit-wasm": "0.33.0"
23
- },
24
26
  "devDependencies": {
25
- "@rollup/plugin-babel": "5.3.1",
26
- "@rollup/plugin-commonjs": "21.0.2",
27
- "@rollup/plugin-node-resolve": "13.1.3",
28
- "@rollup/plugin-typescript": "8.3.1",
29
- "@types/jest": "^27.4.0",
30
- "@types/jsdom": "^16.2.14",
31
- "canvas": "^2.8.0",
32
- "jest": "^27.4.7",
33
- "jsdom": "^19.0.0",
34
- "rollup": "2.70.0",
27
+ "@rollup/plugin-babel": "6.0.3",
28
+ "@rollup/plugin-commonjs": "24.1.0",
29
+ "@rollup/plugin-node-resolve": "15.0.2",
30
+ "@rollup/plugin-replace": "5.0.2",
31
+ "@types/jest": "29.5.1",
32
+ "@types/jsdom": "21.1.1",
33
+ "canvas": "2.11.2",
34
+ "canvaskit-wasm": "0.38.0",
35
+ "esbuild": "0.17.17",
36
+ "findup-sync": "5.0.0",
37
+ "jest": "29.5.0",
38
+ "jest-environment-jsdom": "29.5.0",
39
+ "jsdom": "21.1.1",
40
+ "rimraf": "5.0.0",
41
+ "rollup": "3.20.6",
35
42
  "rollup-plugin-copy": "3.4.0",
36
- "rollup-plugin-delete": "2.0.0",
37
- "rollup-plugin-dts": "4.2.0",
38
- "rollup-plugin-shim": "1.0.0",
39
- "rollup-plugin-sourcemaps": "0.6.3",
40
- "rollup-plugin-terser": "7.0.2",
41
- "ts-jest": "^27.1.2"
43
+ "rollup-plugin-dts": "5.3.0",
44
+ "rollup-plugin-esbuild": "5.0.0",
45
+ "rollup-plugin-polyfill-node": "0.12.0",
46
+ "ts-jest": "29.1.0",
47
+ "typescript": "5.0.4"
42
48
  }
43
49
  }
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, existsSync } from "fs";
3
+ import { resolve, join, dirname, basename } from "path";
4
+ import { env, exit } from "process";
5
+ import { readdir, readFile, mkdir, writeFile } from "fs/promises";
6
+
7
+ /**
8
+ * Our current working directory for this postinstall script is the
9
+ * package's root folder in node_modules, e.g., node_modules/{packageName}
10
+ */
11
+
12
+ /**
13
+ * The folder in which npm command was executed -- this differs from the
14
+ * current working directory.
15
+ */
16
+ const npmCwd = env.INIT_CWD;
17
+
18
+ /**
19
+ * If the full m2c2kit repo has been cloned and "npm install" is executed,
20
+ * when this package is installed it will run this post-install script.
21
+ * But, we should run this only when the package is being installed in a
22
+ * new m2c2kit project, because it will copy assets to the
23
+ * appropriate location in the project root. The below code will check if
24
+ * npm install is being run on the entire m2c2kit repo, and if so, exit this
25
+ * script before copying any assets.
26
+ * Note: this will cause problems if someone decides to name their m2c2kit
27
+ * project "m2c2kit".
28
+ */
29
+ const { name } = JSON.parse(readFileSync(join(npmCwd, "package.json")));
30
+ if (name === "m2c2kit") {
31
+ exit(0);
32
+ }
33
+
34
+ async function copyFolderRecursive(options) {
35
+ async function getFilePathsRecursive(dir) {
36
+ const dirents = await readdir(dir, { withFileTypes: true });
37
+ const files = await Promise.all(
38
+ dirents.map((dirent) => {
39
+ const res = resolve(dir, dirent.name);
40
+ return dirent.isDirectory() ? getFilePathsRecursive(res) : res;
41
+ })
42
+ );
43
+ return Array.prototype.concat(...files);
44
+ }
45
+
46
+ const filePaths = await getFilePathsRecursive(options.sourceFolder);
47
+
48
+ filePaths.forEach(async (filePath) => {
49
+ const destinationFilePath = join(
50
+ options.destinationFolder,
51
+ filePath.replace(resolve(options.sourceFolder), options.baseFolder)
52
+ );
53
+ if (!options.overwrite && existsSync(destinationFilePath)) {
54
+ return;
55
+ }
56
+
57
+ const folder = dirname(destinationFilePath);
58
+ if (!existsSync(folder)) {
59
+ await mkdir(folder, { recursive: true });
60
+ }
61
+
62
+ const content = await readFile(filePath);
63
+ await writeFile(destinationFilePath, content);
64
+ });
65
+ }
66
+
67
+ async function copyFile(options) {
68
+ if (
69
+ !options.overwrite &&
70
+ existsSync(
71
+ join(options.destinationFolder, basename(options.sourceFilePath))
72
+ )
73
+ ) {
74
+ return;
75
+ }
76
+
77
+ const content = await readFile(options.sourceFilePath);
78
+
79
+ if (!existsSync(options.destinationFolder)) {
80
+ await mkdir(options.destinationFolder, { recursive: true });
81
+ }
82
+ await writeFile(
83
+ join(options.destinationFolder, basename(options.sourceFilePath)),
84
+ content
85
+ );
86
+ }
87
+
88
+ copyFolderRecursive({
89
+ sourceFolder: "assets",
90
+ destinationFolder: join(npmCwd, "src"),
91
+ baseFolder: "assets",
92
+ overwrite: false,
93
+ });
94
+ copyFile({
95
+ sourceFilePath: "index.html",
96
+ destinationFolder: join(npmCwd, "src"),
97
+ overwrite: false,
98
+ });