Skip to content

Commit 0e13293

Browse files
Merge pull request #29 from simpleanalytics/v9
V9
2 parents 703cc68 + 01d8d05 commit 0e13293

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2645
-4974
lines changed

.env-default

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
BS_CAPABILITIES=
2+
BS_LOCAL_OPTIONS=
3+
STOP_ON_FAIL=
4+
BROWSERSTACK_USERNAME=
5+
BROWSERSTACK_ACCESS_KEY=
6+
DEBUG=true
7+
LOCATION=developer_x
8+
9+
# Define a test browser on local machine
10+
DEV_LIMIT=1
11+
DEV_NAME=
12+
DEV_BROWSER=
13+
DEV_BROWSER_VERSION=
14+
DEV_OS=ios
15+
DEV_DEVICE=
16+
DEV_OS_VERSION=12
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: SA Public Scripts CI
1+
name: Browserstack
22

33
on:
44
pull_request:
@@ -13,10 +13,23 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [14.17]
16+
node-version: [16.16]
1717

1818
steps:
19-
- uses: actions/checkout@v1
19+
- name: "BrowserStack Env Setup"
20+
uses: "browserstack/github-actions/setup-env@master"
21+
with:
22+
username: ${{ secrets.BROWSERSTACK_USERNAME }}
23+
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
24+
25+
- name: "Start BrowserStackLocal Tunnel"
26+
uses: "browserstack/github-actions/setup-local@master"
27+
with:
28+
local-testing: "start"
29+
local-logging-level: "all-logs"
30+
local-identifier: "random"
31+
32+
- uses: actions/checkout@v2
2033

2134
- name: Prettier Action on PR
2235
if: github.event_name == 'pull_request'
@@ -46,16 +59,19 @@ jobs:
4659
node-version: ${{ matrix.node-version }}
4760

4861
- name: Run npm ci
49-
run: npm ci
62+
run: sudo npm ci
5063

5164
- name: Run npm test with BrowserStack Local
52-
uses: ianwalter/[email protected]
53-
with:
54-
args: npm run test
65+
run: npm run build && node ./test/index.js
5566
env:
5667
CI: true
5768
NODE_ENV: test
5869
DEBUG: false
5970
LOCATION: ${{ secrets.LOCATION }}
6071
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
6172
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
73+
74+
- name: "Stop BrowserStackLocal"
75+
uses: "browserstack/github-actions/setup-local@master"
76+
with:
77+
local-testing: "stop"

.github/workflows/license.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Update copyright year(s) in license file
2+
3+
on:
4+
schedule:
5+
- cron: "0 3 1 1 *" # 03:00 AM on January 1
6+
7+
jobs:
8+
update-license-year:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- uses: FantasticFiasco/action-update-license-year@v2
15+
with:
16+
token: ${{ secrets.GITHUB_TOKEN }}

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.16

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2020 Simple Analytics
3+
Copyright (c) 2018-2022 Simple Analytics
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<img src="https://github.com/simpleanalytics/scripts/workflows/SA%20Public%20Scripts%20CI/badge.svg">
99
</a></p>
1010

11-
Simple Analytics is a privacy friendly analytics tool with a strong mission: never invade the privacy of your visitors. We just show you the essentials: page views, referrers, top pages, and devices. We don't use cookies. We don't collect any personal data. So no cookie banners or GDPR to worry about. When a service is free you are the product. We won't ever sell your data. As a result, we require a subscription.
11+
Simple Analytics is a privacy-first analytics tool with a strong mission: never invade the privacy of your visitors. We just show you the essentials: page views, referrers, top pages, and devices. We don't use cookies. We don't collect any personal data. So no cookie banners or GDPR to worry about. When a service is free you are the product. We won't ever sell your data. As a result, we require a subscription.
1212

1313
## Open Source
1414

15-
As our public scripts are very important in our mission to privacy we decided to make the source code available. We use the MIT license which is short and to the point. It lets you do almost anything you want with this project, like making and distributing closed source versions. See [LICENSE](LICENSE) for more info.
15+
As our public scripts are very important in our mission to privacy we decided to make the source code available. We use the MIT license which is short and to the point. It lets you do almost anything you want with this project, like making and distributing closed-source versions. See [LICENSE](LICENSE) for more info.
1616

1717
## Contribute
1818

@@ -24,16 +24,16 @@ If you contribute, make sure to use `npm run build`, copy the script to a websit
2424

2525
## Run this locally
2626

27-
Just run `npm run watch` and every file will be validated and minified on save. We minify our scripts with [UglifyJS](http://lisperator.net/uglifyjs/), a well known JavaScript minifier.
27+
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.
2828

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

3131
## Device testing is sponsored by BrowserStack
3232

33-
We get amazing sponsoring from [BrowserStack](https://www.browserstack.com/). Thanks BrowserStack!
33+
We get amazing sponsorship from [BrowserStack](https://www.browserstack.com/). Thanks, BrowserStack!
3434

3535
<img src="https://mijnimpact-adriaan-io.s3.amazonaws.com/1581763646555-browserstack-logo.png" width="300px" alt="BrowserStack Logo" />
3636

3737
## Contact
3838

39-
Feel free to drop any issues you have with our open source scripts. If you want to contact us you can also use our contact form or email listed here: [simpleanalytics.com/contact](https://simpleanalytics.com/contact).
39+
Feel free to drop any issues you have with our open-source scripts. If you want to contact us you can also use our contact form or email listed here: [simpleanalytics.com/contact](https://simpleanalytics.com/contact).

minify.js renamed to compile.js

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const GREEN = "\x1b[32m%s\x1b[0m";
88
const YELLOW = "\x1b[33m%s\x1b[0m";
99
const RED = "\x1b[31m%s\x1b[0m";
1010

11-
const VERSION = 8;
11+
const VERSION = 9;
1212

1313
Handlebars.registerHelper("or", function (param1, param2) {
1414
return param1 || param2;
@@ -68,10 +68,14 @@ const DEFAULTS = {
6868
errorhandling: true,
6969
warnings: true,
7070
ignorednt: true,
71-
saGlobal: "sa_event",
71+
namespace: "sa",
7272
url: "docs.simpleanalytics.com/script",
7373
scriptName: "script",
7474
allowparams: true,
75+
pathoverwriter: true,
76+
metadata: true,
77+
nonuniquehostnames: true,
78+
ignoremetrics: true,
7579
dev: false,
7680
};
7781

@@ -91,6 +95,10 @@ const LIGHT = {
9195
warnings: false,
9296
ignorednt: false,
9397
allowparams: false,
98+
pathoverwriter: false,
99+
metadata: false,
100+
nonuniquehostnames: false,
101+
ignoremetrics: false,
94102
};
95103

96104
const templates = [
@@ -219,7 +227,8 @@ const templates = [
219227
...LIGHT,
220228
version: VERSION,
221229
scriptName: `cdn_light_${VERSION}`,
222-
baseUrl: "{{nginxHost}}",
230+
baseUrl: "simpleanalyticscdn.com",
231+
apiUrlPrefix: "queue.",
223232
},
224233
},
225234
{
@@ -273,11 +282,7 @@ const files = templates.reduce((list, template) => {
273282
for (const file of files) {
274283
const { variables, input, output } = file;
275284
const name = output.toUpperCase();
276-
const versionFile = `${__dirname}/dist/v${variables.version}/${output}`;
277-
const cdnVersionFile = versionFile.replace(
278-
/latest\.js/i,
279-
`v${variables.version}.js`
280-
);
285+
let versionFile = `${__dirname}/dist/v${variables.version}/${output}`;
281286
const latestFile = `${__dirname}/dist/latest/${output}`;
282287

283288
const contents = fs
@@ -334,12 +339,11 @@ for (const file of files) {
334339
code: prepend + rawCode,
335340
};
336341

337-
if (!codeTemplate)
338-
console.warn(RED, `[MINIFY][${name}] codeTemplate is undefined`);
339-
if (!template) console.warn(RED, `[MINIFY][${name}] template is undefined`);
342+
if (!codeTemplate) console.warn(RED, `[${name}] codeTemplate is undefined`);
343+
if (!template) console.warn(RED, `[${name}] template is undefined`);
340344

341345
for (const warning of warnings || [])
342-
console.warn(YELLOW, `[MINIFY][${name}] ${warning}`);
346+
console.warn(YELLOW, `[${name}] ${warning}`);
343347

344348
const code = fillTemplate(codeTemplate, variables);
345349

@@ -355,7 +359,7 @@ for (const file of files) {
355359
const { index, lineNumber, description } = error;
356360
console.log(
357361
RED,
358-
`[MINIFY][${name}][ERROR] ${input
362+
`[${name}][ERROR] ${input
359363
.split("/")
360364
.pop()} ${description} at line ${lineNumber} position ${index}`
361365
);
@@ -369,25 +373,45 @@ for (const file of files) {
369373
}
370374

371375
const compiledMap = map ? fillTemplate(map, variables) : null;
376+
const isCustom = /^custom\//.test(output);
372377

373378
if (variables.version && variables.sri) {
374-
const cdnFileName = cdnVersionFile.split("/").pop();
375-
fs.writeFileSync(
376-
cdnVersionFile,
377-
code.replace(
378-
/sourceMappingURL=latest\.js\.map/gi,
379-
`sourceMappingURL=${cdnFileName}.map`
380-
)
379+
let cdnFileName = versionFile.split("/").pop();
380+
381+
// Skip custom vX.js SRI file, we use app.js for that.
382+
if (cdnFileName === "latest.js" && isCustom) continue;
383+
384+
// Rewrite latest.js to app.js in vX folder
385+
if (cdnFileName === "latest.js" && !isCustom) {
386+
cdnFileName = "app.js";
387+
versionFile = versionFile.replace("latest.js", "app.js");
388+
}
389+
390+
let write = code.replace(
391+
/sourceMappingURL=latest\.js\.map/gi,
392+
`sourceMappingURL=${cdnFileName}.map`
381393
);
394+
395+
fs.writeFileSync(versionFile, write);
396+
382397
if (compiledMap) {
383-
fs.writeFileSync(
384-
`${cdnVersionFile}.map`,
385-
compiledMap.replace(/latest\.source\.js/gi, cdnFileName)
398+
let writeCompiled = compiledMap.replace(
399+
/latest\.source\.js/gi,
400+
cdnFileName
386401
);
402+
403+
fs.writeFileSync(`${versionFile}.map`, writeCompiled);
387404
}
388405
} else {
389-
fs.writeFileSync(latestFile, code.replace(/; SRI-version/i, ""));
390-
if (compiledMap) fs.writeFileSync(`${latestFile}.map`, compiledMap);
406+
let write = code.replace(/; SRI-version/i, "");
407+
408+
fs.writeFileSync(latestFile, write);
409+
410+
if (compiledMap) {
411+
let writeCompiled = compiledMap;
412+
413+
fs.writeFileSync(`${latestFile}.map`, writeCompiled);
414+
}
391415
}
392416

393417
const bytes = new TextEncoder("utf-8").encode(code).length;
@@ -399,10 +423,10 @@ for (const file of files) {
399423
const fill2 = " ".repeat(Math.max(0, 14 - sourceName.length));
400424

401425
console.log(
402-
`[MINIFY] ${name.toLowerCase()} ${fill1}Minified ${sourceName} ${fill2} ${bytesZeroFilled} bytes ${
426+
` ${name.toLowerCase()} ${fill1}Compiled ${sourceName} ${fill2} ${bytesZeroFilled} bytes ${
403427
variables.sri ? " (SRI)" : ""
404428
}`
405429
);
406430
}
407431

408-
console.log(GREEN, `[MINIFY] Done minifying all files`);
432+
console.log(GREEN, ` Done compiling all files`);

deploy.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ echo "==> You are about to deploy to $SERVER_NAME"
3434
read -p "==> Are you sure (y/N)? " -r
3535
echo
3636
if [[ $REPLY =~ ^[Yy]$ ]]; then
37-
echo '==> Minifying one more time'
37+
echo '==> Compiling one more time'
3838

39-
npm run minify
39+
npm run compile
4040

4141
if [[ `git status --porcelain` ]]; then
4242
echo -e "==> ${RED}There are changes in your repo, commit and test them first${RESET}"
@@ -60,10 +60,12 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
6060
ssh [email protected] mkdir -p "/var/www/default/v$VERSION"
6161

6262
echo "==> Copying SRI v$VERSION file to $SERVER_NAME"
63-
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/v$VERSION.js" "$REMOTE_PATH/v$VERSION/app.js"
64-
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/v$VERSION.js.map" "$REMOTE_PATH/v$VERSION/app.js.map"
63+
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/app.js" "$REMOTE_PATH/v$VERSION/app.js"
64+
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/app.js.map" "$REMOTE_PATH/v$VERSION/app.js.map"
6565
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/light.js" "$REMOTE_PATH/v$VERSION/light.js"
6666
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/light.js.map" "$REMOTE_PATH/v$VERSION/light.js.map"
67+
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/proxy.js" "$REMOTE_PATH/v$VERSION/proxy.js"
68+
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/proxy.js.map" "$REMOTE_PATH/v$VERSION/proxy.js.map"
6769
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/auto-events.js" "$REMOTE_PATH/v$VERSION/auto-events.js"
6870
rsync --quiet --rsync-path="sudo rsync" "./dist/v$VERSION/custom/auto-events.js.map" "$REMOTE_PATH/v$VERSION/auto-events.js.map"
6971

dist/latest/auto-events.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)