react-update-notification
Advanced tools
Comparing version 0.1.0-alpha.0 to 0.1.0-alpha.1
@@ -7,15 +7,64 @@ #!/usr/bin/env node | ||
const cheerio = require('cheerio'); | ||
const yargs = require('yargs'); | ||
const version = process.env.npm_package_version; | ||
const buildPath = path.resolve(process.cwd(), process.argv[2]); | ||
const versionPath = path.resolve(buildPath, 'version.json'); | ||
const indexPath = path.resolve(buildPath, 'index.html'); | ||
function generate(argv) { | ||
const versionPath = path.resolve(process.cwd(), argv.v); | ||
const indexPath = path.resolve(process.cwd(), argv.i); | ||
fs.writeFileSync(versionPath, JSON.stringify({ version })); | ||
try { | ||
fs.writeFileSync(versionPath, JSON.stringify({ version })); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') { | ||
console.error( | ||
`Error: incorrect path to version file. Path used: ${e.path}` | ||
); | ||
} else { | ||
console.log(e); | ||
} | ||
process.exit(1); | ||
} | ||
const loadedIndex = cheerio.load(fs.readFileSync(indexPath).toString()); | ||
loadedIndex('head').append( | ||
`<script>window.__APP_VERSION__ = ${version};</script>` | ||
); | ||
fs.writeFileSync(indexPath, loadedIndex.html()); | ||
let indexFile; | ||
try { | ||
indexFile = fs.readFileSync(indexPath); | ||
} catch (e) { | ||
if (e.code === 'ENOENT') { | ||
console.error( | ||
`Error: incorrect path to index.html. Path used: ${e.path}` | ||
); | ||
} else { | ||
console.log(e); | ||
} | ||
process.exit(1); | ||
} | ||
const loadedIndex = cheerio.load(indexFile.toString()); | ||
loadedIndex('head').append( | ||
`<script>window.__APP_VERSION__ = "${version}"; window.__APP_VERSION_FILE__ = "${argv.v}"</script>` | ||
); | ||
fs.writeFileSync(indexPath, loadedIndex.html()); | ||
} | ||
const argv = yargs | ||
.usage('Usage: $0 [options]') | ||
.option('indexFile', { | ||
alias: 'i', | ||
description: 'Path to index.html', | ||
nargs: 1, | ||
default: 'build/index.html' | ||
}) | ||
.option('versionFile', { | ||
alias: 'v', | ||
description: 'Version file target path', | ||
nargs: 1, | ||
default: 'build/version.json' | ||
}) | ||
.example('$0 -i build/index.html') | ||
.example('$0 -i build/index.html -v build/version.json') | ||
.version(false) | ||
.help().argv; | ||
generate(argv); |
@@ -7,6 +7,6 @@ declare global { | ||
declare type Status = 'checking' | 'current' | 'available'; | ||
export declare const useVersion: () => { | ||
export declare const useUpdateCheck: () => { | ||
status: Status; | ||
refresh: () => void; | ||
reloadPage: () => void; | ||
}; | ||
export {}; |
import { useState, useEffect } from 'react'; | ||
var refresh = function () { return window.location.reload(true); }; | ||
var reloadPage = function () { return window.location.reload(true); }; | ||
var currentVersion = window.__APP_VERSION__; | ||
export var useVersion = function () { | ||
export var useUpdateCheck = function () { | ||
var _a = useState('checking'), status = _a[0], setStatus = _a[1]; | ||
@@ -21,4 +21,4 @@ useEffect(function () { | ||
}); | ||
}); | ||
return { status: status, refresh: refresh }; | ||
}, []); | ||
return { status: status, reloadPage: reloadPage }; | ||
}; |
@@ -7,6 +7,6 @@ declare global { | ||
declare type Status = 'checking' | 'current' | 'available'; | ||
export declare const useVersion: () => { | ||
export declare const useUpdateCheck: () => { | ||
status: Status; | ||
refresh: () => void; | ||
reloadPage: () => void; | ||
}; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = require("react"); | ||
var refresh = function () { return window.location.reload(true); }; | ||
var reloadPage = function () { return window.location.reload(true); }; | ||
var currentVersion = window.__APP_VERSION__; | ||
exports.useVersion = function () { | ||
exports.useUpdateCheck = function () { | ||
var _a = react_1.useState('checking'), status = _a[0], setStatus = _a[1]; | ||
@@ -23,4 +23,4 @@ react_1.useEffect(function () { | ||
}); | ||
}); | ||
return { status: status, refresh: refresh }; | ||
}, []); | ||
return { status: status, reloadPage: reloadPage }; | ||
}; |
{ | ||
"name": "react-update-notification", | ||
"version": "0.1.0-alpha.0", | ||
"version": "0.1.0-alpha.1", | ||
"description": "New version notification for your React application.", | ||
@@ -36,4 +36,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"cheerio": "^1.0.0-rc.3" | ||
"cheerio": "^1.0.0-rc.3", | ||
"yargs": "^15.1.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
6324
7
130
0
70
3
+ Addedyargs@^15.1.0
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcliui@6.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedrequire-main-filename@2.0.0(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwhich-module@2.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedy18n@4.0.3(transitive)
+ Addedyargs@15.4.1(transitive)
+ Addedyargs-parser@18.1.3(transitive)