sliftutils 0.6.3 → 0.6.4

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.
@@ -0,0 +1,87 @@
1
+ import fs from "fs";
2
+ import { delay } from "socket-function/src/batching";
3
+ import { bundleEntryCaller } from "../bundler/bundleEntryCaller";
4
+ import yargs from "yargs";
5
+ import { formatTime } from "socket-function/src/formatting/format";
6
+ import path from "path";
7
+ import { getAllFiles } from "../misc/fs";
8
+
9
+ async function main() {
10
+ let time = Date.now();
11
+ //todonext
12
+ // We need to build both the extBackground.ts and extContentScript.ts
13
+ // And copy the manifest.json
14
+ // AND copy everything in ./assets which has updated
15
+ let yargObj = yargs(process.argv)
16
+ .option("backgroundEntry", { type: "string", default: "./extBackground.ts", desc: `Path to the entry point file` })
17
+ .option("contentEntry", { type: "string", default: "./extContentScript.ts", desc: `Path to the entry point file` })
18
+ .option("manifestPath", { type: "string", default: "./manifest.json", desc: `Path to the manifest.json file` })
19
+ .option("assetsFolder", { type: "string", default: "./assets", desc: `Path to the assets folder` })
20
+ .option("outputFolder", { type: "string", default: "./build-nodejs", desc: `Output folder` })
21
+ .argv || {}
22
+ ;
23
+
24
+
25
+ // Wait for any async functions to load.
26
+ await delay(0);
27
+
28
+ let hasBackgroundEntry = fs.existsSync(yargObj.backgroundEntry);
29
+ let hasContentEntry = fs.existsSync(yargObj.contentEntry);
30
+ let hasManifest = fs.existsSync(yargObj.manifestPath);
31
+ let hasAssets = fs.existsSync(yargObj.assetsFolder);
32
+
33
+ if (!hasBackgroundEntry && !hasContentEntry) {
34
+ throw new Error("No extension entry points found. Please specify at least one entry point with the --backgroundEntry or --contentEntry option. Or, create the default file at ./extBackground.ts or ./extContentScript.ts.");
35
+ }
36
+ if (!hasManifest) {
37
+ throw new Error("No manifest file found. Please specify the manifest file with the --manifestPath option. Or, create the default file at ./manifest.json.");
38
+ }
39
+ if (!hasAssets) {
40
+ throw new Error("No assets folder found. Please specify the assets folder with the --assetsFolder option. Or, create the default folder at ./assets.");
41
+ }
42
+
43
+ await fs.promises.mkdir("./build-extension", { recursive: true });
44
+
45
+ if (hasBackgroundEntry) {
46
+ await bundleEntryCaller({
47
+ entryPoint: yargObj.backgroundEntry,
48
+ outputFolder: yargObj.outputFolder,
49
+ });
50
+ }
51
+ if (hasContentEntry) {
52
+ await bundleEntryCaller({
53
+ entryPoint: yargObj.contentEntry,
54
+ outputFolder: yargObj.outputFolder,
55
+ });
56
+ }
57
+ await fs.promises.cp(yargObj.manifestPath, path.join(yargObj.outputFolder, "manifest.json"));
58
+
59
+ let filesCopied = 0;
60
+
61
+ for await (const file of getAllFiles(yargObj.assetsFolder)) {
62
+ let relativePath = path.relative(yargObj.assetsFolder, file);
63
+ let newPath = path.join(yargObj.outputFolder, "assets", relativePath);
64
+ // Only copy it if the timestamp has updated
65
+ async function getTimestamp(filePath: string): Promise<number> {
66
+ try {
67
+ const stats = await fs.promises.stat(filePath);
68
+ return stats.mtimeMs;
69
+ } catch (error) {
70
+ return 0;
71
+ }
72
+ }
73
+ let newTimestamp = await getTimestamp(file);
74
+ let oldTimestamp = await getTimestamp(newPath);
75
+ if (newTimestamp > oldTimestamp) {
76
+ await fs.promises.cp(file, newPath);
77
+ filesCopied++;
78
+ }
79
+ }
80
+ if (filesCopied > 0) {
81
+ console.log(`Copied ${filesCopied} changed assets`);
82
+ }
83
+
84
+ let duration = Date.now() - time;
85
+ console.log(`NodeJS build completed in ${formatTime(duration)}`);
86
+ }
87
+ main().catch(console.error).finally(() => process.exit());
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ require("typenode");
3
+ require("./extensionBuild");
@@ -20,7 +20,7 @@ async function main() {
20
20
 
21
21
  await bundleEntryCaller({
22
22
  entryPoint: yargObj.entryPoint,
23
- outputFolder: "./build-nodejs",
23
+ outputFolder: yargObj.outputFolder,
24
24
  });
25
25
 
26
26
  let duration = Date.now() - time;
package/misc/fs.ts ADDED
@@ -0,0 +1,19 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export async function* getAllFiles(folder: string): AsyncIterableIterator<string> {
5
+ const files = await fs.promises.readdir(folder);
6
+ for (const file of files) {
7
+ const filePath = path.join(folder, file);
8
+ try {
9
+ const stats = await fs.promises.stat(filePath);
10
+ if (stats.isDirectory()) {
11
+ yield* getAllFiles(filePath);
12
+ } else {
13
+ yield filePath;
14
+ }
15
+ } catch (error) {
16
+ console.warn(`Failed while accessing path, skipping: ${filePath}`, error);
17
+ }
18
+ }
19
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
7
7
  "type": "yarn tsc --noEmit",
8
- "build-nodejs": "yarn typenode ./builders/nodeJSBuild.ts"
8
+ "build-nodejs": "yarn typenode ./builders/nodeJSBuild.ts",
9
+ "notes": "mobx, preact, socket-function, typenode SHOULD be peerDependencies. But we want to use yarn (better dependency deduplication), so we can't use peerDependencies (as they aren't installed by default, which makes them a nightmare to use). If you want to override the versions, feel free to use overrides/resolutions."
9
10
  },
10
11
  "bin": {
11
12
  "build-nodejs": "./builders/nodeJSBuildRun.js"
@@ -13,7 +14,11 @@
13
14
  "dependencies": {
14
15
  "@types/shell-quote": "^1.7.5",
15
16
  "js-sha256": "^0.11.1",
17
+ "mobx": "^6.13.3",
18
+ "preact": "10.24.3",
16
19
  "shell-quote": "^1.8.3",
20
+ "socket-function": "^0.155.0",
21
+ "typenode": "^6.0.0",
17
22
  "typesafecss": "^0.26.0",
18
23
  "yargs": "15.4.1"
19
24
  },
@@ -22,11 +27,5 @@
22
27
  "@types/yargs": "15.0.19",
23
28
  "debugbreak": "^0.9.9",
24
29
  "typedev": "^0.1.1"
25
- },
26
- "peerDependencies": {
27
- "mobx": "^6.13.3",
28
- "preact": "10.24.3",
29
- "socket-function": "^0.155.0",
30
- "typenode": "^6.0.0"
31
30
  }
32
31
  }
package/spec.txt CHANGED
@@ -1,12 +1,9 @@
1
1
  TODO:
2
2
 
3
- Ugh... where is it getting the typescript version? Why is it picking the latest... typenode doesn't want the latest...
4
-
5
- Why is the binary not being added?
6
3
 
7
4
  4) New project with:
8
5
 
9
- maybe... we need bins and entry points for the common types of builds
6
+ We need bins and entry points for the common types of builds
10
7
  extension
11
8
  copy manifest.json
12
9
  build background.ts, copy it