browser-extension-manager 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/TODO.md +0 -0
- package/bin/browser-extension-manager +7 -0
- package/dist/assets/css/fontawesome.scss +2 -0
- package/dist/assets/css/main.scss +3 -0
- package/dist/assets/js/main.js +4 -0
- package/dist/assets/js copy/base.js +7 -0
- package/dist/assets/js copy/core.js +81 -0
- package/dist/assets/js copy/main.js +10 -0
- package/dist/background.js +261 -0
- package/dist/build.js +92 -0
- package/dist/cli.js +70 -0
- package/dist/commands/clean.js +33 -0
- package/dist/commands/install.js +52 -0
- package/dist/commands/setup.js +484 -0
- package/dist/commands/version.js +12 -0
- package/dist/config/manifest.json +78 -0
- package/dist/content.js +52 -0
- package/dist/defaults/.nvmrc +1 -0
- package/dist/defaults/.vscode/settings.json +8 -0
- package/dist/defaults/_.gitignore +71 -0
- package/dist/defaults/hooks/build:post.js +8 -0
- package/dist/defaults/hooks/build:pre.js +8 -0
- package/dist/defaults/src/_locales/en/messages.json +14 -0
- package/dist/defaults/src/assets/css/content.scss +2 -0
- package/dist/defaults/src/assets/css/options.scss +2 -0
- package/dist/defaults/src/assets/css/popup.scss +2 -0
- package/dist/defaults/src/assets/images/_ +0 -0
- package/dist/defaults/src/assets/images/icons/icon.png +0 -0
- package/dist/defaults/src/assets/js/background.js +11 -0
- package/dist/defaults/src/assets/js/content.js +8 -0
- package/dist/defaults/src/assets/js/popup.js +7 -0
- package/dist/defaults/src/assets/vendor/_ +0 -0
- package/dist/defaults/src/manifest.json +86 -0
- package/dist/defaults/src/pages/options.html +21 -0
- package/dist/defaults/src/pages/popup.html +21 -0
- package/dist/gulp/main.js +50 -0
- package/dist/gulp/plugins/webpack/replace.js +52 -0
- package/dist/gulp/tasks/developmentRebuild.js +94 -0
- package/dist/gulp/tasks/distribute.js +163 -0
- package/dist/gulp/tasks/icons.js +149 -0
- package/dist/gulp/tasks/package.js +167 -0
- package/dist/gulp/tasks/sass.js +74 -0
- package/dist/gulp/tasks/serve.js +183 -0
- package/dist/gulp/tasks/test.js +16 -0
- package/dist/gulp/tasks/webpack.js +186 -0
- package/dist/index.js +27 -0
- package/dist/lib/affiliatizer.js +198 -0
- package/dist/lib/extension.js +104 -0
- package/dist/lib/logger.js +56 -0
- package/dist/lib/messaging.js +48 -0
- package/package.json +87 -0
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v22/*
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
|
+
|
|
7
|
+
## Changelog Categories
|
|
8
|
+
|
|
9
|
+
- `BREAKING` for breaking changes.
|
|
10
|
+
- `Added` for new features.
|
|
11
|
+
- `Changed` for changes in existing functionality.
|
|
12
|
+
- `Deprecated` for soon-to-be removed features.
|
|
13
|
+
- `Removed` for now removed features.
|
|
14
|
+
- `Fixed` for any bug fixes.
|
|
15
|
+
- `Security` in case of vulnerabilities.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
## [1.0.0] - 2024-06-19
|
|
19
|
+
### Added
|
|
20
|
+
- Initial release of the project 🚀
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Browser Extension Manager
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://itwcreativeworks.com">
|
|
3
|
+
<img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg" width="100px">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://img.shields.io/github/package-json/v/itw-creative-works/ultimate-browser-extension.svg">
|
|
9
|
+
<br>
|
|
10
|
+
<img src="https://img.shields.io/librariesio/release/npm/ultimate-browser-extension.svg">
|
|
11
|
+
<img src="https://img.shields.io/bundlephobia/min/ultimate-browser-extension.svg">
|
|
12
|
+
<img src="https://img.shields.io/codeclimate/maintainability-percentage/itw-creative-works/ultimate-browser-extension.svg">
|
|
13
|
+
<img src="https://img.shields.io/npm/dm/ultimate-browser-extension.svg">
|
|
14
|
+
<img src="https://img.shields.io/node/v/ultimate-browser-extension.svg">
|
|
15
|
+
<img src="https://img.shields.io/website/https/itwcreativeworks.com.svg">
|
|
16
|
+
<img src="https://img.shields.io/github/license/itw-creative-works/ultimate-browser-extension.svg">
|
|
17
|
+
<img src="https://img.shields.io/github/contributors/itw-creative-works/ultimate-browser-extension.svg">
|
|
18
|
+
<img src="https://img.shields.io/github/last-commit/itw-creative-works/ultimate-browser-extension.svg">
|
|
19
|
+
<br>
|
|
20
|
+
<br>
|
|
21
|
+
<a href="https://itwcreativeworks.com">Site</a> | <a href="https://www.npmjs.com/package/ultimate-browser-extension">NPM Module</a> | <a href="https://github.com/itw-creative-works/ultimate-browser-extension">GitHub Repo</a>
|
|
22
|
+
<br>
|
|
23
|
+
<br>
|
|
24
|
+
<strong>Ultimate Browser Extension</strong> is a template that helps you jumpstart your Jekyll sites and is fueled by an intuitive incorporation of npm, gulp, and is fully SEO optimized and blazingly fast.
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
## 🦄 Features
|
|
28
|
+
* **Build for Any Browser**: Export to Chrome, Firefox, Edge, and Opera.
|
|
29
|
+
* **NPM & Gulp**: Fueled by an intuitive incorporation of npm and gulp.
|
|
30
|
+
|
|
31
|
+
## 🚀 Getting started
|
|
32
|
+
1. [Create a repo](https://github.com/itw-creative-works/ultimate-browser-extension/generate) from the **Ultimate Browser Extension** template.
|
|
33
|
+
2. Clone the repo to your local machine.
|
|
34
|
+
3. Run these command to get everything setup and sync'd!
|
|
35
|
+
```bash
|
|
36
|
+
npm install
|
|
37
|
+
npx bxm setup
|
|
38
|
+
npm start
|
|
39
|
+
```
|
|
40
|
+
4. Open your browser and navigate to `chrome://extensions` (or the equivalent for your browser).
|
|
41
|
+
5. Enable **Developer mode**.
|
|
42
|
+
6. Click on **Load unpacked** and select the `dist` folder in your project directory.
|
|
43
|
+
7. Your extension should now be loaded and ready to use!
|
|
44
|
+
|
|
45
|
+
## 📦 How to sync with the template
|
|
46
|
+
1. Simply run `npx bxm setup` in Terminal to get all the latest updates from the **Ultimate Browser Extension template**.
|
|
47
|
+
|
|
48
|
+
## 🌎 Publishing your extension
|
|
49
|
+
1. Run `npm run dist` in Terminal to build your extension for production in every browser.
|
|
50
|
+
2. Upload the respective `.zip` files to the browser's extension store.
|
|
51
|
+
|
|
52
|
+
<!-- ## ⛳️ Flags
|
|
53
|
+
* `--test=false` - Coming soon
|
|
54
|
+
```bash
|
|
55
|
+
npm start -- --test=false
|
|
56
|
+
``` -->
|
package/TODO.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Manager.log('Init main.js');
|
|
2
|
+
|
|
3
|
+
// var dom = Manager.dom();
|
|
4
|
+
// var url = window.location.href;
|
|
5
|
+
|
|
6
|
+
// // Load page specific scripts
|
|
7
|
+
// if (url.includes('/pricing')) {
|
|
8
|
+
// dom.loadScript({src: 'https://cdn.itwcreativeworks.com/assets/general/js/pricing-page-handler/index.js'})
|
|
9
|
+
// } else if (url.includes('/download')) {
|
|
10
|
+
// dom.loadScript({src: 'https://cdn.itwcreativeworks.com/assets/general/js/download-page-handler/index.js'})
|
|
11
|
+
// } else if (url.includes('/browser-extension') || url.includes('/extension')) {
|
|
12
|
+
// dom.loadScript({src: 'https://cdn.itwcreativeworks.com/assets/general/js/browser-extension-page-handler/index.js'})
|
|
13
|
+
// } else if (window.location.pathname.endsWith('.html')) {
|
|
14
|
+
// // Redirect and remove .html
|
|
15
|
+
// window.location.pathname = window.location.pathname.replace('.html', '');
|
|
16
|
+
// }
|
|
17
|
+
|
|
18
|
+
// // Load Slapform
|
|
19
|
+
// var slapform;
|
|
20
|
+
// dom.select('form.slapform')
|
|
21
|
+
// .each(function (el, i) {
|
|
22
|
+
|
|
23
|
+
// dom.select(el).on('submit', function (event) {
|
|
24
|
+
// event.preventDefault();
|
|
25
|
+
// import('./slapform-processor.js')
|
|
26
|
+
// .then(function (mod) {
|
|
27
|
+
// slapform = slapform || new mod.default;
|
|
28
|
+
// slapform.process(event);
|
|
29
|
+
// })
|
|
30
|
+
// });
|
|
31
|
+
|
|
32
|
+
// dom.select(el.querySelector('button[type="submit"]'))
|
|
33
|
+
// .removeAttribute('disabled')
|
|
34
|
+
// .removeClass('disabled');
|
|
35
|
+
// })
|
|
36
|
+
|
|
37
|
+
// // Setup Tracking
|
|
38
|
+
// var storage = Manager.storage();
|
|
39
|
+
// var auth = storage.get('user.auth') || {};
|
|
40
|
+
// var setup = false;
|
|
41
|
+
|
|
42
|
+
// if (auth && auth.uid && auth.email) {
|
|
43
|
+
// setupTracking(auth);
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
// // Save user auth data
|
|
47
|
+
// Manager.auth().ready(function (user) {
|
|
48
|
+
// setupTracking(user);
|
|
49
|
+
|
|
50
|
+
// storage.set('user.auth.uid', user.uid);
|
|
51
|
+
// storage.set('user.auth.email', user.email);
|
|
52
|
+
// })
|
|
53
|
+
|
|
54
|
+
// function setupTracking(config) {
|
|
55
|
+
// if (setup) { return; }
|
|
56
|
+
|
|
57
|
+
// var tracking = window.Configuration.global.tracking;
|
|
58
|
+
// var phone = config.phone ? parseInt(config.phone.replace(/\+/ig, '')) : null;
|
|
59
|
+
|
|
60
|
+
// // Google Analytics
|
|
61
|
+
// gtag('set', 'user_id', config.uid);
|
|
62
|
+
|
|
63
|
+
// // Facebook Pixel
|
|
64
|
+
// fbq('init', tracking.facebookPixel, {
|
|
65
|
+
// external_id: config.uid,
|
|
66
|
+
// em: config.email,
|
|
67
|
+
// ph: phone,
|
|
68
|
+
// // fn: 'first_name',
|
|
69
|
+
// // ln: 'last_name',
|
|
70
|
+
// });
|
|
71
|
+
|
|
72
|
+
// // TikTok Pixel
|
|
73
|
+
// ttq.identify({
|
|
74
|
+
// external_id: config.uid || '',
|
|
75
|
+
// email: config.email || '',
|
|
76
|
+
// phone_number: phone ? '+' + phone : '',
|
|
77
|
+
// })
|
|
78
|
+
|
|
79
|
+
// setup = true;
|
|
80
|
+
// }
|
|
81
|
+
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
|
|
3
|
+
// Variables
|
|
4
|
+
const serviceWorker = self;
|
|
5
|
+
|
|
6
|
+
// Class
|
|
7
|
+
function Manager() {
|
|
8
|
+
const self = this;
|
|
9
|
+
|
|
10
|
+
// Properties
|
|
11
|
+
self.extension = null;
|
|
12
|
+
|
|
13
|
+
// Defaults
|
|
14
|
+
self.config = {};
|
|
15
|
+
self.version = '{ version }';
|
|
16
|
+
self.brand = {
|
|
17
|
+
name: '{ brand.name }',
|
|
18
|
+
};
|
|
19
|
+
self.app = '{ app.id }';
|
|
20
|
+
self.environment = '{ environment }';
|
|
21
|
+
self.libraries = {
|
|
22
|
+
firebase: false,
|
|
23
|
+
messaging: false,
|
|
24
|
+
promoServer: false,
|
|
25
|
+
cachePolyfill: false,
|
|
26
|
+
};
|
|
27
|
+
self.cache = {
|
|
28
|
+
breaker: '',
|
|
29
|
+
name: ''
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Return
|
|
33
|
+
return self;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Initialize
|
|
37
|
+
Manager.prototype.initialize = function () {
|
|
38
|
+
const self = this;
|
|
39
|
+
|
|
40
|
+
return new Promise(function(resolve, reject) {
|
|
41
|
+
// Properties
|
|
42
|
+
self.extension = require('./lib/extension');
|
|
43
|
+
|
|
44
|
+
// Parse config file
|
|
45
|
+
parseConfiguration(self);
|
|
46
|
+
|
|
47
|
+
// Setup listeners
|
|
48
|
+
setupListeners(self);
|
|
49
|
+
|
|
50
|
+
// Import firebase
|
|
51
|
+
// importFirebase(self);
|
|
52
|
+
|
|
53
|
+
// Log
|
|
54
|
+
self.log('Initialized!', self.version, self.cache.name, self);
|
|
55
|
+
|
|
56
|
+
// Return
|
|
57
|
+
return resolve(self);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Setup logger
|
|
62
|
+
['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
|
|
63
|
+
Manager.prototype[method] = function() {
|
|
64
|
+
// Get arguments
|
|
65
|
+
const time = new Date().toLocaleTimeString('en-US', {
|
|
66
|
+
hour12: false,
|
|
67
|
+
hour: '2-digit',
|
|
68
|
+
minute: '2-digit',
|
|
69
|
+
second: '2-digit'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Add prefix
|
|
73
|
+
const args = [`[${time}] background:`, ...Array.from(arguments)];
|
|
74
|
+
|
|
75
|
+
// Call the original console method
|
|
76
|
+
console[method].apply(console, args);
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Parse configuration
|
|
81
|
+
function parseConfiguration(self) {
|
|
82
|
+
try {
|
|
83
|
+
// Log
|
|
84
|
+
self.cache.breaker = new Date().getTime();
|
|
85
|
+
self.cache.name = `${self.app}-${self.cache.breaker}`;
|
|
86
|
+
|
|
87
|
+
self.log('Parsed configuration', self.config);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
self.error('Error parsing configuration', e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Setup listeners
|
|
94
|
+
function setupListeners(self) {
|
|
95
|
+
// Force service worker to use the latest version
|
|
96
|
+
serviceWorker.addEventListener('install', (event) => {
|
|
97
|
+
event.waitUntil(serviceWorker.skipWaiting());
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
serviceWorker.addEventListener('activate', (event) => {
|
|
101
|
+
event.waitUntil(serviceWorker.clients.claim());
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Handle clicks on notifications
|
|
105
|
+
// Open the URL of the notification
|
|
106
|
+
// ⚠️⚠️⚠️ THIS MUST BE PLACED BEFORE THE FIREBASE IMPORTS HANDLER ⚠️⚠️⚠️
|
|
107
|
+
// https://stackoverflow.com/questions/78270541/cant-catch-fcm-notificationclick-event-in-background-using-firebase-messa
|
|
108
|
+
serviceWorker.addEventListener('notificationclick', (event) => {
|
|
109
|
+
// Get the properties of the notification
|
|
110
|
+
const notification = event.notification;
|
|
111
|
+
const data = (notification.data && notification.data.FCM_MSG ? notification.data.FCM_MSG.data : null) || {};
|
|
112
|
+
const payload = (notification.data && notification.data.FCM_MSG ? notification.data.FCM_MSG.notification : null) || {};
|
|
113
|
+
|
|
114
|
+
// Get the click action
|
|
115
|
+
const clickAction = payload.click_action || data.click_action || '/';
|
|
116
|
+
|
|
117
|
+
// Log
|
|
118
|
+
self.log('Event: notificationclick event', event);
|
|
119
|
+
self.log('Event: notificationclick data', data);
|
|
120
|
+
self.log('Event: notificationclick payload', payload);
|
|
121
|
+
self.log('Event: notificationclick clickAction', clickAction);
|
|
122
|
+
|
|
123
|
+
// Handle the click
|
|
124
|
+
event.waitUntil(
|
|
125
|
+
clients.openWindow(clickAction)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// Close the notification
|
|
129
|
+
notification.close();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Send messages: https://stackoverflow.com/questions/35725594/how-do-i-pass-data-like-a-user-id-to-a-web-worker-for-fetching-additional-push
|
|
133
|
+
// more messaging: http://craig-russell.co.uk/2016/01/29/background-messaging.html#.XSKpRZNKiL8
|
|
134
|
+
serviceWorker.addEventListener('message', (event) => {
|
|
135
|
+
try {
|
|
136
|
+
// Get the data
|
|
137
|
+
const data = event.data || {};
|
|
138
|
+
const response = {
|
|
139
|
+
status: 'success',
|
|
140
|
+
command: '',
|
|
141
|
+
data: {}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Parse the data
|
|
145
|
+
data.command = data.command || '';
|
|
146
|
+
data.args = data.args || {};
|
|
147
|
+
response.command = data.command;
|
|
148
|
+
|
|
149
|
+
// Quit if no command
|
|
150
|
+
if (data.command === '') { return };
|
|
151
|
+
|
|
152
|
+
// Log
|
|
153
|
+
self.log('Event: postMessage', data);
|
|
154
|
+
|
|
155
|
+
// Handle the command
|
|
156
|
+
if (data.command === 'function') {
|
|
157
|
+
data.args.function = data.args.function || function() {};
|
|
158
|
+
data.args.function();
|
|
159
|
+
} else if (data.command === 'debug') {
|
|
160
|
+
self.log('Debug data =', data);
|
|
161
|
+
event.ports[0].postMessage(response);
|
|
162
|
+
} else if (data.command === 'skipWaiting') {
|
|
163
|
+
self.skipWaiting();
|
|
164
|
+
event.ports[0].postMessage(response);
|
|
165
|
+
} else if (data.command === 'unregister') {
|
|
166
|
+
self.registration.unregister()
|
|
167
|
+
.then(() => {
|
|
168
|
+
event.ports[0].postMessage(response);
|
|
169
|
+
})
|
|
170
|
+
.catch(() => {
|
|
171
|
+
response.status = 'fail';
|
|
172
|
+
event.ports[0].postMessage(response);
|
|
173
|
+
});
|
|
174
|
+
} else if (data.command === 'cache') {
|
|
175
|
+
data.args.pages = data.args.pages || [];
|
|
176
|
+
var defaultPages =
|
|
177
|
+
[
|
|
178
|
+
'/',
|
|
179
|
+
'/index.html',
|
|
180
|
+
/* '/?homescreen=1', */
|
|
181
|
+
'/assets/css/main.css',
|
|
182
|
+
'/assets/js/main.js',
|
|
183
|
+
];
|
|
184
|
+
var pagesToCache = arrayUnique(data.args.pages.concat(defaultPages));
|
|
185
|
+
caches.open(SWManager.cache.name).then(cache => {
|
|
186
|
+
return cache.addAll(
|
|
187
|
+
pagesToCache
|
|
188
|
+
)
|
|
189
|
+
.then(() => {
|
|
190
|
+
self.log('Cached resources.');
|
|
191
|
+
event.ports[0].postMessage(response);
|
|
192
|
+
})
|
|
193
|
+
.catch(() => {
|
|
194
|
+
response.status = 'fail';
|
|
195
|
+
event.ports[0].postMessage(response);
|
|
196
|
+
self.log('Failed to cache resources.')
|
|
197
|
+
});
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
event.ports[0].postMessage(response);
|
|
202
|
+
} catch (e) {
|
|
203
|
+
// Set up a response
|
|
204
|
+
response.success = 'fail';
|
|
205
|
+
|
|
206
|
+
// Try to send a response
|
|
207
|
+
try { event.ports[0].postMessage(response) } catch (e) {}
|
|
208
|
+
|
|
209
|
+
// Log
|
|
210
|
+
self.log('Failed to receive message:', data, e);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Log
|
|
215
|
+
self.log('Set up listeners');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Import Firebase
|
|
219
|
+
function importFirebase(self) {
|
|
220
|
+
// Import Firebase libraries
|
|
221
|
+
// importScripts(
|
|
222
|
+
// 'https://www.gstatic.com/firebasejs/{ firebaseVersion }/firebase-app-compat.js',
|
|
223
|
+
// 'https://www.gstatic.com/firebasejs/{ firebaseVersion }/firebase-messaging-compat.js',
|
|
224
|
+
// 'https://www.gstatic.com/firebasejs/{ firebaseVersion }/firebase-database-compat.js',
|
|
225
|
+
// 'https://www.gstatic.com/firebasejs/{ firebaseVersion }/firebase-firestore-compat.js',
|
|
226
|
+
// );
|
|
227
|
+
console.error('---0');
|
|
228
|
+
console.error('---1', __dirname);
|
|
229
|
+
// const firebase = require('web-manager/node_modules/firebase/firebase-app-compat.js');
|
|
230
|
+
// const firebase = require('web-manager');
|
|
231
|
+
// const firebase = require('firebase/firebase-auth-compat.js');
|
|
232
|
+
console.error('---2', firebase);
|
|
233
|
+
|
|
234
|
+
// Initialize app
|
|
235
|
+
const app = firebase.initializeApp(self.config.firebase);
|
|
236
|
+
|
|
237
|
+
// Initialize messaging
|
|
238
|
+
self.libraries.messaging = firebase.messaging();
|
|
239
|
+
|
|
240
|
+
// Attach firebase to SWManager
|
|
241
|
+
self.libraries.firebase = firebase;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function arrayUnique(array) {
|
|
245
|
+
var a = array.concat();
|
|
246
|
+
|
|
247
|
+
// Loop through array
|
|
248
|
+
for(var i=0; i<a.length; ++i) {
|
|
249
|
+
for(var j=i+1; j<a.length; ++j) {
|
|
250
|
+
if(a[i] === a[j]) {
|
|
251
|
+
a.splice(j--, 1);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Return
|
|
257
|
+
return a;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Export
|
|
261
|
+
module.exports = Manager;
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const jetpack = require('fs-jetpack');
|
|
4
|
+
const JSON5 = require('json5');
|
|
5
|
+
const argv = require('yargs').argv;
|
|
6
|
+
const { force } = require('node-powertools');
|
|
7
|
+
|
|
8
|
+
// Class
|
|
9
|
+
function Manager() {
|
|
10
|
+
const self = this;
|
|
11
|
+
|
|
12
|
+
// Properties
|
|
13
|
+
self._logger = null;
|
|
14
|
+
|
|
15
|
+
// Return
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Initialize
|
|
20
|
+
Manager.prototype.initialize = function () {
|
|
21
|
+
console.log('initialize:');
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Logger
|
|
25
|
+
Manager.prototype.logger = function (name) {
|
|
26
|
+
// Create logger
|
|
27
|
+
if (!this._logger) {
|
|
28
|
+
this._logger = new (require('./lib/logger'))(name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this._logger;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// argv
|
|
35
|
+
Manager.getArguments = function () {
|
|
36
|
+
const options = argv || {};
|
|
37
|
+
|
|
38
|
+
// Fix
|
|
39
|
+
options._ = options._ || [];
|
|
40
|
+
options.browser = force(options.browser === undefined ? true : options.browser, 'boolean');
|
|
41
|
+
options.debug = force(options.debug === undefined ? false : options.debug, 'boolean');
|
|
42
|
+
|
|
43
|
+
// Return
|
|
44
|
+
return options;
|
|
45
|
+
};
|
|
46
|
+
Manager.prototype.getArguments = Manager.getArguments;
|
|
47
|
+
|
|
48
|
+
// isBuildMode: checks if the build mode is enabled
|
|
49
|
+
Manager.isBuildMode = function () {
|
|
50
|
+
return process.env.BXM_BUILD_MODE === 'true';
|
|
51
|
+
}
|
|
52
|
+
Manager.prototype.isBuildMode = Manager.isBuildMode;
|
|
53
|
+
|
|
54
|
+
// getEnvironment: returns the environment based on the build mode
|
|
55
|
+
Manager.getEnvironment = function () {
|
|
56
|
+
return Manager.isBuildMode()
|
|
57
|
+
? 'production'
|
|
58
|
+
: 'development';
|
|
59
|
+
}
|
|
60
|
+
Manager.prototype.getEnvironment = Manager.getEnvironment;
|
|
61
|
+
|
|
62
|
+
// getManifest: requires and parses config.yml
|
|
63
|
+
Manager.getManifest = function () {
|
|
64
|
+
return JSON5.parse(jetpack.read('src/manifest.json') || '{}');
|
|
65
|
+
}
|
|
66
|
+
Manager.prototype.getManifest = Manager.getManifest;
|
|
67
|
+
|
|
68
|
+
// getConfig: requires and parses config.json
|
|
69
|
+
Manager.getConfig = function () {
|
|
70
|
+
return JSON5.parse(jetpack.read(path.join(process.cwd(), 'config.json')));
|
|
71
|
+
}
|
|
72
|
+
Manager.prototype.getConfig = Manager.getConfig;
|
|
73
|
+
|
|
74
|
+
// getPackage: requires and parses package.json
|
|
75
|
+
Manager.getPackage = function (type) {
|
|
76
|
+
const basePath = type === 'project'
|
|
77
|
+
? process.cwd()
|
|
78
|
+
: path.resolve(__dirname, '..')
|
|
79
|
+
|
|
80
|
+
const pkgPath = path.join(basePath, 'package.json')
|
|
81
|
+
return JSON5.parse(jetpack.read(pkgPath))
|
|
82
|
+
}
|
|
83
|
+
Manager.prototype.getPackage = Manager.getPackage;
|
|
84
|
+
|
|
85
|
+
// Require
|
|
86
|
+
Manager.require = function (path) {
|
|
87
|
+
return require(path);
|
|
88
|
+
};
|
|
89
|
+
Manager.prototype.require = Manager.require;
|
|
90
|
+
|
|
91
|
+
// Export
|
|
92
|
+
module.exports = Manager;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const jetpack = require('fs-jetpack');
|
|
4
|
+
|
|
5
|
+
// Command Aliases
|
|
6
|
+
const DEFAULT = 'setup';
|
|
7
|
+
const ALIASES = {
|
|
8
|
+
clean: ['-c', '--clean'],
|
|
9
|
+
install: ['-i', 'i', '--install'],
|
|
10
|
+
setup: ['-s', '--setup'],
|
|
11
|
+
version: ['-v', '--version'],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Function to resolve command name from aliases
|
|
15
|
+
function resolveCommand(options) {
|
|
16
|
+
// Check if a command was explicitly passed via positional argument
|
|
17
|
+
if (options._.length > 0) {
|
|
18
|
+
const command = options._[0];
|
|
19
|
+
for (const [key, aliases] of Object.entries(ALIASES)) {
|
|
20
|
+
if (command === key || aliases.includes(command)) {
|
|
21
|
+
return key;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return command; // If not found in aliases, return as-is
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Check if any alias was passed as a flag (e.g., -g)
|
|
28
|
+
for (const [key, aliases] of Object.entries(ALIASES)) {
|
|
29
|
+
for (const alias of aliases) {
|
|
30
|
+
if (options[alias.replace(/^-+/, '')]) { // Remove leading `-`
|
|
31
|
+
return key;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return DEFAULT; // Fallback to default if no match is found
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Main Function
|
|
40
|
+
function Main() {}
|
|
41
|
+
|
|
42
|
+
Main.prototype.process = async function (options) {
|
|
43
|
+
// Fix options
|
|
44
|
+
options = options || {};
|
|
45
|
+
options._ = options._ || [];
|
|
46
|
+
|
|
47
|
+
// Determine the command (use default if not provided)
|
|
48
|
+
const command = resolveCommand(options);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
// Get the command file path
|
|
52
|
+
const commandFile = path.join(__dirname, 'commands', `${command}.js`);
|
|
53
|
+
|
|
54
|
+
// Check if the command file exists
|
|
55
|
+
if (!jetpack.exists(commandFile)) {
|
|
56
|
+
throw new Error(`Error: Command "${command}" not found.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Execute the command
|
|
60
|
+
const Command = require(commandFile);
|
|
61
|
+
await Command(options);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(`Error executing command "${command}": ${e.message}`);
|
|
64
|
+
|
|
65
|
+
// Exit with error
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = Main;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../build.js'));
|
|
3
|
+
const logger = Manager.logger('clean');
|
|
4
|
+
const jetpack = require('fs-jetpack');
|
|
5
|
+
|
|
6
|
+
// Load package
|
|
7
|
+
const package = Manager.getPackage('main');
|
|
8
|
+
const project = Manager.getPackage('project');
|
|
9
|
+
|
|
10
|
+
// Const dirs
|
|
11
|
+
const dirs = [
|
|
12
|
+
'.temp',
|
|
13
|
+
'dist',
|
|
14
|
+
'packaged',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
module.exports = async function (options) {
|
|
18
|
+
// Log
|
|
19
|
+
logger.log(`Cleaning up .temp, dist, and packaged directories...`);
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
// Loop through dirs
|
|
23
|
+
dirs.forEach((dir) => {
|
|
24
|
+
// Remove
|
|
25
|
+
jetpack.remove(dir);
|
|
26
|
+
|
|
27
|
+
// Create empty dir
|
|
28
|
+
jetpack.dir(dir);
|
|
29
|
+
});
|
|
30
|
+
} catch (e) {
|
|
31
|
+
logger.error(`Error clearing directories: ${e}`);
|
|
32
|
+
}
|
|
33
|
+
};
|