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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('icons');
|
|
4
|
+
const { src, dest, watch, series } = require('gulp');
|
|
5
|
+
const glob = require('glob').globSync;
|
|
6
|
+
const responsive = require('gulp-responsive-modern');
|
|
7
|
+
|
|
8
|
+
// Load package
|
|
9
|
+
const package = Manager.getPackage('main');
|
|
10
|
+
const project = Manager.getPackage('project');
|
|
11
|
+
|
|
12
|
+
// Glob
|
|
13
|
+
const input = [
|
|
14
|
+
// Files to include
|
|
15
|
+
// 'src/assets/images/**/*.{jpg,jpeg,png}',
|
|
16
|
+
// 'src/assets/images/icons/**/*.{jpg,jpeg,png}',
|
|
17
|
+
'src/assets/images/icons/icon.png',
|
|
18
|
+
|
|
19
|
+
// Files to exclude
|
|
20
|
+
// '!dist/**',
|
|
21
|
+
];
|
|
22
|
+
const output = 'dist/assets/images/icons';
|
|
23
|
+
const delay = 250;
|
|
24
|
+
|
|
25
|
+
// Main task
|
|
26
|
+
function icons(complete) {
|
|
27
|
+
// Log
|
|
28
|
+
logger.log('Starting...');
|
|
29
|
+
|
|
30
|
+
// Use glob to get file count for matching files
|
|
31
|
+
const files = glob(input);
|
|
32
|
+
|
|
33
|
+
// If there's no files, complete
|
|
34
|
+
if (files.length === 0) {
|
|
35
|
+
// Log
|
|
36
|
+
logger.log('Found 0 images to process');
|
|
37
|
+
|
|
38
|
+
// Complete
|
|
39
|
+
return complete();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Log
|
|
43
|
+
logger.log(`Found ${files.length} images to process`, files);
|
|
44
|
+
|
|
45
|
+
// Filter out files that already exist in the destination
|
|
46
|
+
// const filesToProcess = files.filter(file => {
|
|
47
|
+
// const fileName = path.basename(file);
|
|
48
|
+
// const destFile = path.join(output, fileName);
|
|
49
|
+
// return !jetpack.exists(destFile);
|
|
50
|
+
// });
|
|
51
|
+
|
|
52
|
+
// If there's no files to process, complete
|
|
53
|
+
// if (filesToProcess.length === 0) {
|
|
54
|
+
// // Log
|
|
55
|
+
// logger.log('No new images to process');
|
|
56
|
+
|
|
57
|
+
// // Complete
|
|
58
|
+
// return complete();
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
// Log
|
|
62
|
+
// logger.log(`Processing ${filesToProcess.length} images`, filesToProcess);
|
|
63
|
+
|
|
64
|
+
// Process images: resize and convert to webp
|
|
65
|
+
return src(files)
|
|
66
|
+
.pipe(
|
|
67
|
+
responsive({
|
|
68
|
+
'**/*.{jpg,jpeg,png}': [
|
|
69
|
+
// 1024 resized version in original format
|
|
70
|
+
{
|
|
71
|
+
width: 1024,
|
|
72
|
+
rename: { suffix: '-1024x' }
|
|
73
|
+
},
|
|
74
|
+
// 512 resized version in original format
|
|
75
|
+
{
|
|
76
|
+
width: 512,
|
|
77
|
+
rename: { suffix: '-512x' }
|
|
78
|
+
},
|
|
79
|
+
// 256 resized version in original format
|
|
80
|
+
{
|
|
81
|
+
width: 256,
|
|
82
|
+
rename: { suffix: '-256x' }
|
|
83
|
+
},
|
|
84
|
+
// 128 resized version in original format
|
|
85
|
+
{
|
|
86
|
+
width: 128,
|
|
87
|
+
rename: { suffix: '-128x' }
|
|
88
|
+
},
|
|
89
|
+
// 48 resized version in original format
|
|
90
|
+
{
|
|
91
|
+
width: 48,
|
|
92
|
+
rename: { suffix: '-48x' }
|
|
93
|
+
},
|
|
94
|
+
// 32 resized version in original format
|
|
95
|
+
{
|
|
96
|
+
width: 32,
|
|
97
|
+
rename: { suffix: '-32x' }
|
|
98
|
+
},
|
|
99
|
+
// 16 resized version in original format
|
|
100
|
+
{
|
|
101
|
+
width: 16,
|
|
102
|
+
rename: { suffix: '-16x' }
|
|
103
|
+
},
|
|
104
|
+
// Original size in original format
|
|
105
|
+
{
|
|
106
|
+
rename: { suffix: '' }
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
}, {
|
|
110
|
+
quality: 100,
|
|
111
|
+
progressive: true,
|
|
112
|
+
withMetadata: false,
|
|
113
|
+
withoutEnlargement: false,
|
|
114
|
+
skipOnEnlargement: false,
|
|
115
|
+
})
|
|
116
|
+
)
|
|
117
|
+
.pipe(dest(output))
|
|
118
|
+
.on('end', () => {
|
|
119
|
+
// Log
|
|
120
|
+
logger.log('Finished!');
|
|
121
|
+
|
|
122
|
+
// Complete
|
|
123
|
+
return complete();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Watcher task
|
|
128
|
+
function iconsWatcher(complete) {
|
|
129
|
+
// Quit if in build mode
|
|
130
|
+
if (Manager.isBuildMode()) {
|
|
131
|
+
logger.log('[watcher] Skipping watcher in build mode');
|
|
132
|
+
return complete();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Log
|
|
136
|
+
logger.log('[watcher] Watching for changes...');
|
|
137
|
+
|
|
138
|
+
// Watch for changes
|
|
139
|
+
watch(input, { delay: delay }, icons)
|
|
140
|
+
.on('change', function(path) {
|
|
141
|
+
logger.log(`[watcher] File ${path} was changed`);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
// Complete
|
|
145
|
+
return complete();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Default Task
|
|
149
|
+
module.exports = series(icons, iconsWatcher);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('package');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const jetpack = require('fs-jetpack');
|
|
6
|
+
const { series, parallel, watch } = require('gulp');
|
|
7
|
+
const { execute, getKeys } = require('node-powertools');
|
|
8
|
+
const JSON5 = require('json5');
|
|
9
|
+
|
|
10
|
+
// Load package
|
|
11
|
+
const package = Manager.getPackage('main');
|
|
12
|
+
const project = Manager.getPackage('project');
|
|
13
|
+
|
|
14
|
+
// Glob
|
|
15
|
+
const input = [
|
|
16
|
+
// Files to include
|
|
17
|
+
'dist/**/*',
|
|
18
|
+
|
|
19
|
+
// Files to exclude
|
|
20
|
+
// '!dist/**',
|
|
21
|
+
];
|
|
22
|
+
const output = 'dist/assets/images/icons';
|
|
23
|
+
const delay = 250;
|
|
24
|
+
|
|
25
|
+
// Supported browsers
|
|
26
|
+
const BROWSERS = ['chrome', 'firefox', 'opera'];
|
|
27
|
+
|
|
28
|
+
// Environment Check
|
|
29
|
+
const targetBrowser = process.env.BROWSER;
|
|
30
|
+
const isSpecificBrowser = targetBrowser && BROWSERS.includes(targetBrowser);
|
|
31
|
+
|
|
32
|
+
// Special Compilation Task for manifest.json with default settings
|
|
33
|
+
async function compileManifest(browser, complete) {
|
|
34
|
+
try {
|
|
35
|
+
const manifestPath = path.join('dist', 'manifest.json');
|
|
36
|
+
const outputPath = path.join('packaged', browser, 'manifest.json');
|
|
37
|
+
const configPath = path.join(__dirname, '../../', 'config', 'manifest.json');
|
|
38
|
+
|
|
39
|
+
// Read and parse using JSON5
|
|
40
|
+
const manifest = JSON5.parse(jetpack.read(manifestPath));
|
|
41
|
+
const defaultConfig = JSON5.parse(jetpack.read(configPath));
|
|
42
|
+
|
|
43
|
+
// Apply defaults
|
|
44
|
+
getKeys(defaultConfig).forEach(key => {
|
|
45
|
+
const defaultValue = key.split('.').reduce((o, k) => (o || {})[k], defaultConfig);
|
|
46
|
+
const userValue = key.split('.').reduce((o, k) => (o || {})[k], manifest);
|
|
47
|
+
|
|
48
|
+
if (Array.isArray(defaultValue) && Array.isArray(userValue)) {
|
|
49
|
+
// Merge arrays
|
|
50
|
+
const mergedArray = Array.from(new Set([...defaultValue, ...userValue]));
|
|
51
|
+
key.split('.').reduce((o, k, i, arr) => {
|
|
52
|
+
if (i === arr.length - 1) o[k] = mergedArray;
|
|
53
|
+
else o[k] = o[k] || {};
|
|
54
|
+
return o[k];
|
|
55
|
+
}, manifest);
|
|
56
|
+
} else if (userValue === undefined) {
|
|
57
|
+
// Apply default if user value doesn't exist
|
|
58
|
+
key.split('.').reduce((o, k, i, arr) => {
|
|
59
|
+
if (i === arr.length - 1) o[k] = defaultValue;
|
|
60
|
+
else o[k] = o[k] || {};
|
|
61
|
+
return o[k];
|
|
62
|
+
}, manifest);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Save as regular JSON
|
|
67
|
+
jetpack.write(outputPath, JSON.stringify(manifest, null, 2));
|
|
68
|
+
|
|
69
|
+
logger.log(`Manifest compiled with defaults and saved for ${browser}`);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
logger.error(`Error compiling manifest for ${browser}`, e);
|
|
72
|
+
}
|
|
73
|
+
return complete();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Special Compilation Task for _locales
|
|
77
|
+
async function compileLocales(browser, complete) {
|
|
78
|
+
try {
|
|
79
|
+
const localesDir = path.join('dist', '_locales');
|
|
80
|
+
const outputDir = path.join('packaged', browser, '_locales');
|
|
81
|
+
|
|
82
|
+
// Ensure the directory exists
|
|
83
|
+
jetpack.dir(outputDir);
|
|
84
|
+
|
|
85
|
+
// Process each locale file
|
|
86
|
+
jetpack.find(localesDir, { matching: '**/*.json' }).forEach(filePath => {
|
|
87
|
+
const relativePath = path.relative(localesDir, filePath);
|
|
88
|
+
const outputPath = path.join(outputDir, relativePath);
|
|
89
|
+
|
|
90
|
+
// Read and parse using JSON5
|
|
91
|
+
const localeData = JSON5.parse(jetpack.read(filePath));
|
|
92
|
+
|
|
93
|
+
// Save as regular JSON
|
|
94
|
+
jetpack.write(outputPath, JSON.stringify(localeData, null, 2));
|
|
95
|
+
|
|
96
|
+
logger.log(`Locale compiled and saved: ${outputPath}`);
|
|
97
|
+
});
|
|
98
|
+
} catch (e) {
|
|
99
|
+
logger.error(`Error compiling locales for ${browser}`, e);
|
|
100
|
+
}
|
|
101
|
+
return complete();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Package Task for Each Browser
|
|
105
|
+
async function packageBrowser(browser, complete) {
|
|
106
|
+
// Log
|
|
107
|
+
logger.log(`Starting packaging for ${browser}...`);
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
const outputDir = `packaged/${browser}`;
|
|
111
|
+
|
|
112
|
+
// Ensure the directory exists
|
|
113
|
+
jetpack.dir(outputDir);
|
|
114
|
+
|
|
115
|
+
// Perform any browser-specific adjustments if needed
|
|
116
|
+
// await execute(`npx bxm setup --browser=${browser}`);
|
|
117
|
+
|
|
118
|
+
// Copy files to browser-specific directory
|
|
119
|
+
await execute(`cp -r dist/* ${outputDir}`);
|
|
120
|
+
|
|
121
|
+
// Compile manifest and locales
|
|
122
|
+
await compileManifest(browser, () => {});
|
|
123
|
+
await compileLocales(browser, () => {});
|
|
124
|
+
|
|
125
|
+
// Create packed extension (.zip)
|
|
126
|
+
await execute(`zip -r ${outputDir}.zip ${outputDir}`);
|
|
127
|
+
|
|
128
|
+
// Log completion
|
|
129
|
+
logger.log(`Finished packaging for ${browser}`);
|
|
130
|
+
} catch (e) {
|
|
131
|
+
logger.error(`Error packaging for ${browser}`, e);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return complete();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Generate tasks for each browser
|
|
138
|
+
const tasks = isSpecificBrowser
|
|
139
|
+
? [packageBrowser.bind(null, targetBrowser)]
|
|
140
|
+
: BROWSERS.map((browser) => packageBrowser.bind(null, browser));
|
|
141
|
+
|
|
142
|
+
// Watcher Task
|
|
143
|
+
function packageWatcher(complete) {
|
|
144
|
+
// Quit if in build mode
|
|
145
|
+
if (Manager.isBuildMode()) {
|
|
146
|
+
logger.log('[watcher] Skipping watcher in build mode');
|
|
147
|
+
return complete();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Log
|
|
151
|
+
logger.log('[watcher] Watching for changes...');
|
|
152
|
+
|
|
153
|
+
// Watch for changes in the dist folder
|
|
154
|
+
watch(input, { delay: delay }, series(parallel(...tasks)))
|
|
155
|
+
.on('change', function (path) {
|
|
156
|
+
logger.log(`[watcher] File ${path} was changed`);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Complete
|
|
160
|
+
return complete();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Export tasks
|
|
164
|
+
module.exports = series(
|
|
165
|
+
parallel(...tasks),
|
|
166
|
+
packageWatcher
|
|
167
|
+
);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('sass');
|
|
4
|
+
const { src, dest, watch, series } = require('gulp');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const compiler = require('gulp-sass')(require('sass'));
|
|
7
|
+
const cleanCSS = require('gulp-clean-css');
|
|
8
|
+
const rename = require('gulp-rename');
|
|
9
|
+
|
|
10
|
+
// Load package
|
|
11
|
+
const package = Manager.getPackage('main');
|
|
12
|
+
const project = Manager.getPackage('project');
|
|
13
|
+
|
|
14
|
+
// Glob
|
|
15
|
+
const input = [
|
|
16
|
+
// Files to include
|
|
17
|
+
'src/assets/css/**/*.{css,scss,sass}',
|
|
18
|
+
|
|
19
|
+
// Main files
|
|
20
|
+
// `${__dirname}/../../assets/css/main.scss`,
|
|
21
|
+
// path.join(__dirname, '..', '..', 'assets/css/main.scss'),
|
|
22
|
+
`${path.join(__dirname, '..', '..', 'assets/css')}/**/*`
|
|
23
|
+
|
|
24
|
+
// Files to exclude
|
|
25
|
+
// '!dist/**',
|
|
26
|
+
];
|
|
27
|
+
const output = 'dist/assets/css';
|
|
28
|
+
const delay = 250;
|
|
29
|
+
|
|
30
|
+
// SASS Compilation Task
|
|
31
|
+
function sass(complete) {
|
|
32
|
+
// Log
|
|
33
|
+
logger.log('Starting...');
|
|
34
|
+
|
|
35
|
+
// Compile
|
|
36
|
+
return src(input)
|
|
37
|
+
.pipe(compiler({ outputStyle: 'compressed' }).on('error', compiler.logError))
|
|
38
|
+
.pipe(cleanCSS())
|
|
39
|
+
.pipe(rename((path) => {
|
|
40
|
+
path.basename += '.bundle';
|
|
41
|
+
}))
|
|
42
|
+
.pipe(dest(output))
|
|
43
|
+
.on('end', () => {
|
|
44
|
+
// Log
|
|
45
|
+
logger.log('Finished!');
|
|
46
|
+
|
|
47
|
+
// Complete
|
|
48
|
+
return complete();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Watcher Task
|
|
53
|
+
function sassWatcher(complete) {
|
|
54
|
+
// Quit if in build mode
|
|
55
|
+
if (Manager.isBuildMode()) {
|
|
56
|
+
logger.log('[watcher] Skipping watcher in build mode');
|
|
57
|
+
return complete();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Log
|
|
61
|
+
logger.log('[watcher] Watching for changes...');
|
|
62
|
+
|
|
63
|
+
// Watch for changes
|
|
64
|
+
watch(input, { delay: delay }, sass)
|
|
65
|
+
.on('change', function(path) {
|
|
66
|
+
logger.log(`[watcher] File ${path} was changed`);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Complete
|
|
70
|
+
return complete();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Default Task
|
|
74
|
+
module.exports = series(sass, sassWatcher);
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('serve');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const browserSync = require('browser-sync').create();
|
|
6
|
+
|
|
7
|
+
// Load package
|
|
8
|
+
const package = Manager.getPackage('main');
|
|
9
|
+
const project = Manager.getPackage('project');
|
|
10
|
+
|
|
11
|
+
// Local URL
|
|
12
|
+
let localUrl;
|
|
13
|
+
let externalUrl;
|
|
14
|
+
|
|
15
|
+
// BrowserSync settings
|
|
16
|
+
const settings = {
|
|
17
|
+
port: 4000,
|
|
18
|
+
browser: 'default',
|
|
19
|
+
cors: true,
|
|
20
|
+
open: false,
|
|
21
|
+
ghostMode: false,
|
|
22
|
+
server: {
|
|
23
|
+
// TODO: FIX?
|
|
24
|
+
// baseDir: '_site',
|
|
25
|
+
baseDir: '_site',
|
|
26
|
+
middleware: async function (req, res, next) {
|
|
27
|
+
const url = new URL(`${localUrl}${req.url}`);
|
|
28
|
+
const pathname = url.pathname;
|
|
29
|
+
|
|
30
|
+
// Set the query object
|
|
31
|
+
req.query = {};
|
|
32
|
+
req.body = {};
|
|
33
|
+
|
|
34
|
+
// If the file has no ext, log it
|
|
35
|
+
if (!path.extname(pathname)) {
|
|
36
|
+
logger.log(`Serving ${pathname}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Process the post request
|
|
40
|
+
if (pathname.match(/\/_process/)) {
|
|
41
|
+
const qsUrl = url.searchParams.get('url');
|
|
42
|
+
let lib;
|
|
43
|
+
|
|
44
|
+
// Set query
|
|
45
|
+
url.searchParams.forEach((value, key) => {
|
|
46
|
+
req.query[key] = value;
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// Set body
|
|
50
|
+
if (req.method === 'POST') {
|
|
51
|
+
req.body = await receiveRequestBody(req);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Try to load the library
|
|
55
|
+
try {
|
|
56
|
+
// Clear the cache
|
|
57
|
+
delete require.cache[require.resolve(`../${qsUrl}`)];
|
|
58
|
+
|
|
59
|
+
// Load the library
|
|
60
|
+
lib = require(`../${qsUrl}`);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// Log the error
|
|
63
|
+
logger.error(`Error processing ${qsUrl}`);
|
|
64
|
+
|
|
65
|
+
// Set the status code
|
|
66
|
+
res.statusCode = 500;
|
|
67
|
+
|
|
68
|
+
// Return an error
|
|
69
|
+
return res.write(`Cannot find ${qsUrl}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Log
|
|
73
|
+
logger.log(`Processing ${qsUrl}`);
|
|
74
|
+
|
|
75
|
+
// Process the library
|
|
76
|
+
return await lib({
|
|
77
|
+
req: req,
|
|
78
|
+
res: res,
|
|
79
|
+
})
|
|
80
|
+
.then((r) => {
|
|
81
|
+
// Set the status code
|
|
82
|
+
res.statusCode = 200;
|
|
83
|
+
|
|
84
|
+
// Write the response (if it's JSON, set the content type)
|
|
85
|
+
try {
|
|
86
|
+
r = JSON.stringify(r);
|
|
87
|
+
res.setHeader('Content-Type', 'application/json');
|
|
88
|
+
} catch (e) {
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// End the response
|
|
92
|
+
res.write(r);
|
|
93
|
+
res.end();
|
|
94
|
+
})
|
|
95
|
+
.catch((e) => {
|
|
96
|
+
// Set the status code
|
|
97
|
+
res.statusCode = 500;
|
|
98
|
+
|
|
99
|
+
// Write the error
|
|
100
|
+
res.write(`Error processing ${qsUrl}: ${e}`);
|
|
101
|
+
res.end();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Check if the URL is missing a trailing slash and does not have an extension
|
|
106
|
+
if (!pathname.endsWith('/') && !path.extname(pathname)) {
|
|
107
|
+
// Get the new URL
|
|
108
|
+
const newURL = `${pathname}.html`;
|
|
109
|
+
|
|
110
|
+
// Log
|
|
111
|
+
// logger.log(`Rewriting ${pathname} to ${newURL}`);
|
|
112
|
+
|
|
113
|
+
// Rewrite it to serve the .html extension
|
|
114
|
+
req.url = newURL;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Special case: Rewrite /blog/ to blog.html since Jekyll fucks it up locally
|
|
118
|
+
if (pathname === '/blog/') {
|
|
119
|
+
req.url = '/blog.html';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Continue
|
|
123
|
+
return next();
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Task
|
|
129
|
+
module.exports = function serve(complete) {
|
|
130
|
+
// Log
|
|
131
|
+
logger.log('Starting...');
|
|
132
|
+
|
|
133
|
+
// Initialize browserSync
|
|
134
|
+
browserSync.init(settings, async (e, instance) => {
|
|
135
|
+
if (e) {
|
|
136
|
+
return logger.error(e);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Get URLs
|
|
140
|
+
localUrl = instance.options.get('urls').get('local');
|
|
141
|
+
externalUrl = instance.options.get('urls').get('external');
|
|
142
|
+
|
|
143
|
+
// Write the config file
|
|
144
|
+
// jetpack.write('.temp/_config_browsersync.yml', `url: ${externalUrl}`);
|
|
145
|
+
|
|
146
|
+
// Set global variable to access browserSync in other files
|
|
147
|
+
global.browserSync = browserSync;
|
|
148
|
+
|
|
149
|
+
// Log
|
|
150
|
+
logger.log('Finished!');
|
|
151
|
+
|
|
152
|
+
// Complete
|
|
153
|
+
return complete();
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
function receiveRequestBody(req) {
|
|
158
|
+
return new Promise((resolve, reject) => {
|
|
159
|
+
let body = [];
|
|
160
|
+
|
|
161
|
+
// Listen for data
|
|
162
|
+
req.on('data', (chunk) => {
|
|
163
|
+
body.push(chunk.toString());
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Listen for errors
|
|
167
|
+
req.on('error', (err) => {
|
|
168
|
+
return reject(err);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// Listen for the end of the request
|
|
172
|
+
req.on('end', () => {
|
|
173
|
+
body = body.join('');
|
|
174
|
+
|
|
175
|
+
// Attempt to parse the body as JSON
|
|
176
|
+
try {
|
|
177
|
+
return resolve(JSON.parse(body));
|
|
178
|
+
} catch (e) {
|
|
179
|
+
return resolve(body);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Libraries
|
|
2
|
+
const Manager = new (require('../../build.js'));
|
|
3
|
+
const logger = Manager.logger('test');
|
|
4
|
+
|
|
5
|
+
// Load package
|
|
6
|
+
const package = Manager.getPackage('main');
|
|
7
|
+
const project = Manager.getPackage('project');
|
|
8
|
+
|
|
9
|
+
// Task
|
|
10
|
+
module.exports = function test(complete) {
|
|
11
|
+
// Log
|
|
12
|
+
logger.log('Starting test...');
|
|
13
|
+
|
|
14
|
+
// Complete
|
|
15
|
+
return complete();
|
|
16
|
+
}
|