Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ If you contribute, make sure to use `npm run build`, copy the script to a websit

Just run `npm run watch` and every file will be validated and compiled on save. We minify our scripts with [UglifyJS](http://lisperator.net/uglifyjs/), a well-known JavaScript minifier.

You can quickly run the unit tests with `npm run test:unit`. This command doesn't rely on BrowserStack and is handy for local checks.

The most important file of the repository is [`/src/default.js`](src/default.js)

## Device testing is sponsored by BrowserStack
Expand Down
20 changes: 10 additions & 10 deletions compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ const fillTemplate = (template, { overwriteOptions = null } = {}) => {
return template
.replace(
/\{\{\s?nginxHost\s?\}\}/gi,
'<!--# echo var="http_host" default="" -->'
'<!--# echo var="http_host" default="" -->',
)
.replace(
/\{\{\s?nginxProxyHost\s?\}\}/gi,
'<!--# echo var="proxy_hostname" default="" --><!--# echo var="proxy_path" default="/simple" -->'
'<!--# echo var="proxy_hostname" default="" --><!--# echo var="proxy_path" default="/simple" -->',
)
.replace(
/\\?"\{\{\s?overwriteOptions\s?\}\}\\?"/gi,
overwriteOptions
? JSON.stringify(overwriteOptions).replace(/:"([^"]+)"/gi, ":$1")
: "{}"
: "{}",
)
.replace(
/"\{\{\s?cloudFlareCustomDomain\s?\}\}"/gi,
'INSTALL_OPTIONS.custom_domain || "queue.simpleanalyticscdn.com"'
'INSTALL_OPTIONS.custom_domain || "queue.simpleanalyticscdn.com"',
);
};

Expand Down Expand Up @@ -284,7 +284,7 @@ const files = templates.reduce((list, template) => {
if (template.variables.sri) {
list.push(
{ ...template, variables: { ...template.variables, sri: true } },
{ ...template, variables: { ...template.variables, sri: false } }
{ ...template, variables: { ...template.variables, sri: false } },
);
} else {
list.push(template);
Expand Down Expand Up @@ -346,7 +346,7 @@ for (const file of files) {
filename: originalFileName,
url: `${finalFileName}.map`,
},
}
},
)
: {
code: prepend + rawCode,
Expand Down Expand Up @@ -374,7 +374,7 @@ for (const file of files) {
RED,
`[${name}][ERROR] ${input
.split("/")
.pop()} ${description} at line ${lineNumber} position ${index}`
.pop()} ${description} at line ${lineNumber} position ${index}`,
);
continue;
}
Expand Down Expand Up @@ -402,15 +402,15 @@ for (const file of files) {

let write = code.replace(
/sourceMappingURL=latest\.js\.map/gi,
`sourceMappingURL=${cdnFileName}.map`
`sourceMappingURL=${cdnFileName}.map`,
);

fs.writeFileSync(versionFile, write);

if (compiledMap) {
let writeCompiled = compiledMap.replace(
/latest\.source\.js/gi,
cdnFileName
cdnFileName,
);

fs.writeFileSync(`${versionFile}.map`, writeCompiled);
Expand Down Expand Up @@ -438,7 +438,7 @@ for (const file of files) {
console.log(
` ${name.toLowerCase()} ${fill1}Compiled ${sourceName} ${fill2} ${bytesZeroFilled} bytes ${
variables.sri ? " (SRI)" : ""
}`
}`,
);
}

Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "node compile.js",
"pretest": "npm run build -- testing",
"test": "node -r dotenv/config ./test/index.js",
"test:unit": "mocha ./test/unit",
"posttest": "npm run build"
},
"repository": {
Expand All @@ -32,6 +33,7 @@
"mocha": "^6.2.3",
"nodemon": "^1.19.4",
"request": "^2.88.0",
"jsdom": "^22.1.0",
"selenium-webdriver": "^4.3.1",
"uglify-js": "^3.9.4",
"uuid-validate": "0.0.3"
Expand Down
15 changes: 8 additions & 7 deletions playground/callback.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -46,15 +46,17 @@
@font-face {
font-family: "Space Grotesk";
font-weight: 500;
src: url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff2")
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff")
format("woff");
}
@font-face {
font-family: "Space Grotesk";
font-weight: 400;
src: url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff2")
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff")
format("woff");
Expand Down Expand Up @@ -179,9 +181,8 @@ <h2>Automated events</h2>
return param;
})
.join(" ");
document.querySelector(
"textarea"
).value += `${type.toUpperCase()}: ${line}\n`;
document.querySelector("textarea").value +=
`${type.toUpperCase()}: ${line}\n`;
}

console.log = function () {
Expand Down Expand Up @@ -253,7 +254,7 @@ <h2>Automated events</h2>
});

const callbackMetadataLink = document.querySelector(
"[data-metadata-callback]"
"[data-metadata-callback]",
);
callbackMetadataLink.addEventListener("click", (event) => {
event.preventDefault();
Expand Down
17 changes: 9 additions & 8 deletions playground/events.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down Expand Up @@ -33,9 +33,9 @@
},
() => {
console.info(
"Simple Analytics auto events: collected before_script_load"
"Simple Analytics auto events: collected before_script_load",
);
}
},
);
</script>

Expand Down Expand Up @@ -67,15 +67,17 @@
@font-face {
font-family: "Space Grotesk";
font-weight: 500;
src: url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff2")
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Medium.woff")
format("woff");
}
@font-face {
font-family: "Space Grotesk";
font-weight: 400;
src: url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff2")
src:
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff2")
format("woff2"),
url("https://assets.simpleanalytics.com/fonts/SpaceGrotesk-Regular.woff")
format("woff");
Expand Down Expand Up @@ -206,9 +208,8 @@ <h2>Automated events</h2>
return param;
})
.join(" ");
document.querySelector(
"textarea"
).value += `${type.toUpperCase()}: ${line}\n`;
document.querySelector("textarea").value +=
`${type.toUpperCase()}: ${line}\n`;
}

console.log = function () {
Expand Down
2 changes: 1 addition & 1 deletion src/auto-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
/^https?:\/\//i.test(link.href) &&
new RegExp(
"\\.(" + (optionsLink.downloadsExtensions || []).join("|") + ")$",
"i"
"i",
).test(link.pathname)
) {
collect = "download";
Expand Down
Loading