squishjs 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squishjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "squish & unsquish stuff",
5
5
  "scripts": {
6
6
  "test": "node testRunner.js"
package/src/Asset.js CHANGED
@@ -1,3 +1,8 @@
1
+ const path = require('path');
2
+ const { getAppDataPath } = require('./utils');
3
+
4
+ const HG_ASSET_PATH = path.join(getAppDataPath(), 'asset-cache');
5
+
1
6
  class Asset {
2
7
  constructor(info, data = null) {
3
8
  this.info = info;
@@ -66,9 +71,6 @@ class Asset {
66
71
  };
67
72
 
68
73
  getFileLocation() {
69
-
70
- const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
71
-
72
74
  const fileHash = this.getHash(this.info.id);
73
75
  return `${HG_ASSET_PATH}/${fileHash}`;
74
76
  }
@@ -91,9 +93,6 @@ class Asset {
91
93
  }
92
94
 
93
95
  async downloadSync(force) {
94
-
95
- const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
96
-
97
96
  if (!fs.existsSync(HG_ASSET_PATH)) {
98
97
  fs.mkdirSync(HG_ASSET_PATH);
99
98
  }
@@ -111,9 +110,6 @@ class Asset {
111
110
  }
112
111
 
113
112
  download(force) {
114
-
115
- const HG_ASSET_PATH = this.getConfigValue('HG_ASSET_PATH', `${process.cwd()}/.asset_cache`);
116
-
117
113
  if (!this.fs.existsSync(HG_ASSET_PATH)) {
118
114
  this.fs.mkdirSync(HG_ASSET_PATH);
119
115
  }
package/src/utils.js ADDED
@@ -0,0 +1,46 @@
1
+ const path = require('path');
2
+
3
+ const getAppDataPath = () => {
4
+ switch (process.platform) {
5
+ case "darwin": {
6
+ return path.join(process.env.HOME, "Library", "Application Support", "Your app name");
7
+ }
8
+ case "win32": {
9
+ return path.join(process.env.APPDATA, "Your app name");
10
+ }
11
+ case "linux": {
12
+ return path.join(process.env.HOME, ".Your app name");
13
+ }
14
+ default: {
15
+ console.log("Unsupported platform!");
16
+ process.exit(1);
17
+ }
18
+ }
19
+ }
20
+
21
+
22
+ function saveAppData(content) {
23
+ const appDatatDirPath = getAppDataPath();
24
+
25
+ // Create appDataDir if not exist
26
+ if (!fs.existsSync(appDatatDirPath)) {
27
+ fs.mkdirSync(appDatatDirPath);
28
+ }
29
+
30
+ const appDataFilePath = path.join(appDatatDirPath, 'appData.json');
31
+ content = JSON.stringify(content);
32
+
33
+ fs.writeFile(appDataFilePath, content, (err) => {
34
+ if (err) {
35
+ console.log("There was a problem saving data!");
36
+ // console.log(err);
37
+ } else {
38
+ console.log("Data saved correctly!");
39
+ loadAppData();
40
+ }
41
+ });
42
+ };
43
+
44
+ module.exports = {
45
+ getAppDataPath
46
+ }