Skip to content

Commit fe85709

Browse files
author
Pascal Klesse
committed
feat: Add version check
1 parent 149a88a commit fe85709

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ async function create() {
55
const fs = require("fs");
66
const path = require("path");
77
const childProcess = require("child_process");
8+
const pjson = require('./package.json');
9+
10+
console.log('ℹ️ create-nuxt-base started in version ', pjson.version);
11+
12+
const packageInfos = await getPackageData(pjson.name);
13+
14+
if (packageInfos) {
15+
const latestVersion = packageInfos['dist-tags'].latest;
16+
17+
if (latestVersion !== pjson.version) {
18+
console.log('📣 Its a newer version of create-nuxt-base available!', pjson.version);
19+
console.log('Your version', pjson.version);
20+
console.log('Available version', latestVersion);
21+
}
22+
}
823

924
const projectName = process.argv[2];
1025

@@ -112,4 +127,28 @@ async function copyFiles(from, to) {
112127
}
113128
}
114129

130+
function getPackageData(packageName) {
131+
const https = require('https');
132+
133+
return new Promise((resolve, reject) => {
134+
https
135+
.get('https://registry.npmjs.org/' + packageName, (resp) => {
136+
let data = '';
137+
138+
// A chunk of data has been received.
139+
resp.on('data', (chunk) => {
140+
data += chunk;
141+
});
142+
143+
// The whole response has been received. Print out the result.
144+
resp.on('end', () => {
145+
resolve(JSON.parse(data));
146+
});
147+
})
148+
.on('error', (err) => {
149+
reject(err);
150+
});
151+
});
152+
}
153+
115154
create();

0 commit comments

Comments
 (0)