-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aafcb4b
commit 61307f8
Showing
3 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { execSync } from "child_process"; | ||
import https from "https"; | ||
|
||
import { getVersion } from "./getCliVersion.js"; | ||
import { logger } from "./logger.js"; | ||
|
||
export const renderVersionWarning = (npmVersion: string) => { | ||
const currentVersion = getVersion(); | ||
|
||
if (currentVersion.includes("beta")) { | ||
logger.warn(" You are using a beta version of create-perma-app."); | ||
logger.warn(" Please report any bugs you encounter."); | ||
} else if (currentVersion.includes("next")) { | ||
logger.warn(" You are running create-perma-app with the @next tag which is no longer maintained."); | ||
logger.warn(" Please run the CLI with @latest instead."); | ||
} else if (currentVersion !== npmVersion) { | ||
logger.warn(" You are using an outdated version of create-perma-app."); | ||
logger.warn(" Your version:", currentVersion + ".", "Latest version in the npm registry:", npmVersion); | ||
logger.warn(" Please run the CLI with @latest to get the latest updates."); | ||
} | ||
console.log(""); | ||
}; | ||
|
||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the LICENSE file in the root | ||
* directory of this source tree. | ||
* https://github.com/facebook/create-react-app/blob/main/packages/create-react-app/LICENSE | ||
*/ | ||
interface DistTagsBody { | ||
latest: string; | ||
} | ||
|
||
function checkForLatestVersion(): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
https | ||
.get("https://registry.npmjs.org/-/package/create-perma-app/dist-tags", (res) => { | ||
if (res.statusCode === 200) { | ||
let body = ""; | ||
res.on("data", (data) => (body += data)); | ||
res.on("end", () => { | ||
resolve((JSON.parse(body) as DistTagsBody).latest); | ||
}); | ||
} else { | ||
reject(); | ||
} | ||
}) | ||
.on("error", () => { | ||
// logger.error("Unable to check for latest version."); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
export const getNpmVersion = () => | ||
// `fetch` to the registry is faster than `npm view` so we try that first | ||
checkForLatestVersion().catch(() => { | ||
try { | ||
return execSync("npm view create-perma-app version").toString().trim(); | ||
} catch { | ||
return null; | ||
} | ||
}); |