prepare-package 1.1.2 → 1.1.3
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/dist/index.js +23 -9
- package/package.json +1 -1
- package/src/index.js +23 -9
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ module.exports = async function (options) {
|
|
|
35
35
|
|| `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
36
36
|
|
|
37
37
|
// Log the options
|
|
38
|
-
console.log(chalk.blue(`[prepare-package]: Options
|
|
38
|
+
console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
|
|
39
39
|
console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
|
|
40
40
|
console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
|
|
41
41
|
console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
|
|
@@ -74,10 +74,10 @@ module.exports = async function (options) {
|
|
|
74
74
|
// Send analytics
|
|
75
75
|
await sendAnalytics(thisPackageJSON, theirPackageJSON)
|
|
76
76
|
.then((r) => {
|
|
77
|
-
console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}
|
|
77
|
+
console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}`));
|
|
78
78
|
})
|
|
79
79
|
.catch(e => {
|
|
80
|
-
console.log(chalk.red(`[prepare-package]: Failed to send analytics
|
|
80
|
+
console.log(chalk.red(`[prepare-package]: Failed to send analytics`, e));
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -92,10 +92,10 @@ module.exports = async function (options) {
|
|
|
92
92
|
tries: 3,
|
|
93
93
|
})
|
|
94
94
|
.then(result => {
|
|
95
|
-
console.log(chalk.green(`[prepare-package]: Purged
|
|
95
|
+
console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));
|
|
96
96
|
})
|
|
97
97
|
.catch(e => {
|
|
98
|
-
console.log(chalk.red(`[prepare-package]: Failed to purge
|
|
98
|
+
console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -157,13 +157,27 @@ function sendAnalytics(thisPackageJSON, theirPackageJSON) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Get the user's location
|
|
160
|
+
const savePath = path.resolve(os.tmpdir(), 'prepare-package-geolocation-cache.json');
|
|
160
161
|
const geolocation = await fetch('https://ipapi.co/json/', {
|
|
161
162
|
response: 'json',
|
|
162
163
|
tries: 2,
|
|
163
164
|
timeout: 30000,
|
|
164
165
|
})
|
|
165
|
-
.
|
|
166
|
-
|
|
166
|
+
.then((r) => {
|
|
167
|
+
// Save to tmpdir
|
|
168
|
+
jetpack.write(savePath, JSON.stringify(r, null, 2));
|
|
169
|
+
|
|
170
|
+
return r;
|
|
171
|
+
})
|
|
172
|
+
.catch((e) => {
|
|
173
|
+
console.log(chalk.red(`[prepare-package]: Failed to get geolocation`, e));
|
|
174
|
+
|
|
175
|
+
// Try to get from cache
|
|
176
|
+
if (jetpack.exists(savePath)) {
|
|
177
|
+
console.log(chalk.blue(`[prepare-package]: Used cached geolocation`));
|
|
178
|
+
|
|
179
|
+
return JSON.parse(jetpack.read(savePath));
|
|
180
|
+
}
|
|
167
181
|
});
|
|
168
182
|
|
|
169
183
|
// Add the geolocation to the body
|
|
@@ -176,8 +190,8 @@ function sendAnalytics(thisPackageJSON, theirPackageJSON) {
|
|
|
176
190
|
}
|
|
177
191
|
|
|
178
192
|
// Log the options
|
|
179
|
-
console.log(chalk.blue(`[prepare-package]: Sending analytics
|
|
180
|
-
|
|
193
|
+
// console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`), body, body.events[0].params);
|
|
194
|
+
console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`));
|
|
181
195
|
|
|
182
196
|
// Send event
|
|
183
197
|
fetch(url, {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -35,7 +35,7 @@ module.exports = async function (options) {
|
|
|
35
35
|
|| `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
36
36
|
|
|
37
37
|
// Log the options
|
|
38
|
-
console.log(chalk.blue(`[prepare-package]: Options
|
|
38
|
+
console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
|
|
39
39
|
console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
|
|
40
40
|
console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
|
|
41
41
|
console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
|
|
@@ -74,10 +74,10 @@ module.exports = async function (options) {
|
|
|
74
74
|
// Send analytics
|
|
75
75
|
await sendAnalytics(thisPackageJSON, theirPackageJSON)
|
|
76
76
|
.then((r) => {
|
|
77
|
-
console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}
|
|
77
|
+
console.log(chalk.green(`[prepare-package]: Sent analytics code=${r.status}`));
|
|
78
78
|
})
|
|
79
79
|
.catch(e => {
|
|
80
|
-
console.log(chalk.red(`[prepare-package]: Failed to send analytics
|
|
80
|
+
console.log(chalk.red(`[prepare-package]: Failed to send analytics`, e));
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -92,10 +92,10 @@ module.exports = async function (options) {
|
|
|
92
92
|
tries: 3,
|
|
93
93
|
})
|
|
94
94
|
.then(result => {
|
|
95
|
-
console.log(chalk.green(`[prepare-package]: Purged
|
|
95
|
+
console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));
|
|
96
96
|
})
|
|
97
97
|
.catch(e => {
|
|
98
|
-
console.log(chalk.red(`[prepare-package]: Failed to purge
|
|
98
|
+
console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));
|
|
99
99
|
})
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -157,13 +157,27 @@ function sendAnalytics(thisPackageJSON, theirPackageJSON) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Get the user's location
|
|
160
|
+
const savePath = path.resolve(os.tmpdir(), 'prepare-package-geolocation-cache.json');
|
|
160
161
|
const geolocation = await fetch('https://ipapi.co/json/', {
|
|
161
162
|
response: 'json',
|
|
162
163
|
tries: 2,
|
|
163
164
|
timeout: 30000,
|
|
164
165
|
})
|
|
165
|
-
.
|
|
166
|
-
|
|
166
|
+
.then((r) => {
|
|
167
|
+
// Save to tmpdir
|
|
168
|
+
jetpack.write(savePath, JSON.stringify(r, null, 2));
|
|
169
|
+
|
|
170
|
+
return r;
|
|
171
|
+
})
|
|
172
|
+
.catch((e) => {
|
|
173
|
+
console.log(chalk.red(`[prepare-package]: Failed to get geolocation`, e));
|
|
174
|
+
|
|
175
|
+
// Try to get from cache
|
|
176
|
+
if (jetpack.exists(savePath)) {
|
|
177
|
+
console.log(chalk.blue(`[prepare-package]: Used cached geolocation`));
|
|
178
|
+
|
|
179
|
+
return JSON.parse(jetpack.read(savePath));
|
|
180
|
+
}
|
|
167
181
|
});
|
|
168
182
|
|
|
169
183
|
// Add the geolocation to the body
|
|
@@ -176,8 +190,8 @@ function sendAnalytics(thisPackageJSON, theirPackageJSON) {
|
|
|
176
190
|
}
|
|
177
191
|
|
|
178
192
|
// Log the options
|
|
179
|
-
console.log(chalk.blue(`[prepare-package]: Sending analytics
|
|
180
|
-
|
|
193
|
+
// console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`), body, body.events[0].params);
|
|
194
|
+
console.log(chalk.blue(`[prepare-package]: Sending analytics mac=${mac}, uuid=${uuid}...`));
|
|
181
195
|
|
|
182
196
|
// Send event
|
|
183
197
|
fetch(url, {
|