mod-build 4.0.80-beta.6 → 4.0.80
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/CHANGELOG.md +3 -2
- package/package.json +1 -1
- package/tasks/{add-files-to-gitignore.js → add-jsdocs-to-gitignore.js} +11 -14
- package/tasks/clean.js +12 -1
- package/tasks/grab-jsdoc.js +111 -0
- package/tasks/serve.js +2 -2
- package/tasks/grab-global-fonts.js +0 -97
package/CHANGELOG.md
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## 4.0.80
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
5
|
+
- Add `grab-jsdoc` task to serve process
|
|
6
|
+
- Add `add-jsdocs-to-gitignore` task to automatically add JSDoc generated files (`jsdoc-types/` and `modform.jsdoc.js`) to `.gitignore`
|
|
7
|
+
- Update `clean` task to remove JSDoc generated files (`./jsdoc-types` and `./modform.jsdoc.js`)
|
|
7
8
|
|
|
8
9
|
## 4.0.79
|
|
9
10
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* @returns {Promise<void>}
|
|
9
|
-
*/
|
|
10
|
-
export default async function addFilesToGitignore(entries, comment) {
|
|
11
|
-
const gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
4
|
+
const entriesToAdd = [
|
|
5
|
+
'jsdoc-types/',
|
|
6
|
+
'modform.jsdoc.js'
|
|
7
|
+
];
|
|
12
8
|
|
|
9
|
+
export default async function addJsdocsToGitignore() {
|
|
10
|
+
const gitignorePath = path.join(process.cwd(), '.gitignore');
|
|
11
|
+
|
|
13
12
|
let content = '';
|
|
13
|
+
|
|
14
14
|
try {
|
|
15
15
|
content = await fs.promises.readFile(gitignorePath, 'utf8');
|
|
16
16
|
} catch (err) {
|
|
@@ -20,10 +20,10 @@ export default async function addFilesToGitignore(entries, comment) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const existingEntries = new Set(content.split('\n').map(line => line.trim()));
|
|
23
|
-
const entriesToAppend =
|
|
23
|
+
const entriesToAppend = entriesToAdd.filter(entry => !existingEntries.has(entry));
|
|
24
24
|
|
|
25
25
|
if (entriesToAppend.length === 0) {
|
|
26
|
-
console.log('.gitignore already contains
|
|
26
|
+
console.log('.gitignore already contains jsdoc entries');
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -32,12 +32,9 @@ export default async function addFilesToGitignore(entries, comment) {
|
|
|
32
32
|
? (content.endsWith('\n') ? '\n' : '\n\n')
|
|
33
33
|
: '';
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
contentToAppend += `# ${comment}\n`;
|
|
37
|
-
}
|
|
35
|
+
contentToAppend += '# JSDoc generated files\n';
|
|
38
36
|
contentToAppend += entriesToAppend.join('\n') + '\n';
|
|
39
37
|
|
|
40
38
|
await fs.promises.appendFile(gitignorePath, contentToAppend, 'utf8');
|
|
41
39
|
console.log(`Added to .gitignore: ${entriesToAppend.join(', ')}`);
|
|
42
40
|
}
|
|
43
|
-
|
package/tasks/clean.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
const foldersToDelete = ['./src/resources', './src/accessible-components', './src/shared-components', './src/.tmp', './src/temp', './public/resources', './
|
|
3
|
+
const foldersToDelete = ['./src/resources', './src/accessible-components', './src/shared-components', './src/.tmp', './src/temp', './public/resources', './jsdoc-types'];
|
|
4
|
+
|
|
5
|
+
const filesToDelete = ['./modform.jsdoc.js'];
|
|
4
6
|
|
|
5
7
|
foldersToDelete.forEach(async (folder) => {
|
|
6
8
|
try {
|
|
@@ -10,3 +12,12 @@ foldersToDelete.forEach(async (folder) => {
|
|
|
10
12
|
// fail silently
|
|
11
13
|
}
|
|
12
14
|
});
|
|
15
|
+
|
|
16
|
+
filesToDelete.forEach(async (file) => {
|
|
17
|
+
try {
|
|
18
|
+
await fs.promises.rm(file);
|
|
19
|
+
console.log(`File ${file} deleted successfully`);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
// fail silently
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { defaultSettings } from '../src/data/config.js';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import fs, { createWriteStream } from 'node:fs';
|
|
4
|
+
import * as stream from 'node:stream';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { responseInterceptor } from '../src/scripts/retry-axios.js';
|
|
8
|
+
import addJSDocsToGitignore from './add-jsdocs-to-gitignore.js';
|
|
9
|
+
|
|
10
|
+
const resourcePath = 'quote/resources/mod-form/form';
|
|
11
|
+
const axiosInstance = axios.create();
|
|
12
|
+
const jsdocAxiosInstance = axios.create();
|
|
13
|
+
responseInterceptor(axiosInstance);
|
|
14
|
+
responseInterceptor(jsdocAxiosInstance);
|
|
15
|
+
|
|
16
|
+
// Helper to stream a JSDoc file to the destination directory
|
|
17
|
+
const streamToDestination = async (filePath) => {
|
|
18
|
+
if (!filePath) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const finished = promisify(stream.finished);
|
|
23
|
+
// Add cachebuster to avoid server/browser caching issues
|
|
24
|
+
const cachebuster = Math.round(Date.now() / 1000);
|
|
25
|
+
const url = `https://${defaultSettings.nodeEnv}/${resourcePath}/${filePath}?cb=${cachebuster}`;
|
|
26
|
+
const fileName = path.basename(filePath);
|
|
27
|
+
const dirPath = path.dirname(filePath);
|
|
28
|
+
|
|
29
|
+
// Create directory if it doesn't exist
|
|
30
|
+
if (dirPath !== '.' && !fs.existsSync(dirPath)) {
|
|
31
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fileFullPath = path.join(dirPath, fileName);
|
|
35
|
+
|
|
36
|
+
// if file exists, do not create it again
|
|
37
|
+
if (fs.existsSync(fileFullPath)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const writer = createWriteStream(fileFullPath);
|
|
42
|
+
const options = {
|
|
43
|
+
url,
|
|
44
|
+
method: 'get',
|
|
45
|
+
responseType: 'stream'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const resp = await axiosInstance(options);
|
|
50
|
+
|
|
51
|
+
if (resp.status !== 200) {
|
|
52
|
+
throw new Error(`${resp.status}: Error while fetching ${url}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
resp.data.pipe(writer);
|
|
56
|
+
console.log(`${fileFullPath} created...`);
|
|
57
|
+
await finished(writer);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(error);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
} finally {
|
|
62
|
+
axiosInstance.interceptors.response.eject(responseInterceptor);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function getJSDocFiles() {
|
|
67
|
+
// Add cachebuster to avoid server/browser caching issues
|
|
68
|
+
const cachebuster = Math.round(Date.now() / 1000);
|
|
69
|
+
const options = {
|
|
70
|
+
url: `https://${defaultSettings.nodeEnv}/${resourcePath}/jsdoc.json?cb=${cachebuster}`,
|
|
71
|
+
method: 'get'
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const resp = await jsdocAxiosInstance(options);
|
|
76
|
+
|
|
77
|
+
if (resp.status !== 200) {
|
|
78
|
+
throw new Error(`${resp.status}: Error while fetching ${options.url}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// axios may parse JSON automatically, so check if it's already an object
|
|
82
|
+
if (typeof resp.data === 'string') {
|
|
83
|
+
return JSON.parse(resp.data);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return resp.data;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error(error);
|
|
89
|
+
throw error;
|
|
90
|
+
} finally {
|
|
91
|
+
jsdocAxiosInstance.interceptors.response.eject(responseInterceptor);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default async function grabJSDoc() {
|
|
96
|
+
const { nodeEnv, isLocal } = defaultSettings;
|
|
97
|
+
|
|
98
|
+
if (!isLocal) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!nodeEnv) {
|
|
103
|
+
throw new Error('Missing environment variables. Did you start with gulp instead of npm run...?');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const files = await getJSDocFiles();
|
|
107
|
+
const filesPromiseMap = files.map(filePath => streamToDestination(filePath));
|
|
108
|
+
await Promise.all(filesPromiseMap);
|
|
109
|
+
await addJSDocsToGitignore();
|
|
110
|
+
}
|
|
111
|
+
|
package/tasks/serve.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import addEditorConfig from './add-editorconfig.js';
|
|
2
|
-
import grabGlobalFonts from './grab-global-fonts.js';
|
|
3
2
|
import grabSharedComponents from './grab-shared-components.js';
|
|
4
3
|
import grabSharedScripts from './grab-shared-scripts.js';
|
|
5
4
|
import grabCdn from './grab-cdn.js';
|
|
6
5
|
import grabB2BData from './grab-b2b-data.js';
|
|
7
6
|
import getDefaultTradeQuestions from './get-default-trade-questions.js';
|
|
8
7
|
import grabFormHelpers from './grab-form-helpers.js';
|
|
8
|
+
import grabJSDoc from './grab-jsdoc.js';
|
|
9
9
|
import templates from './templates.js';
|
|
10
10
|
import { createStylelintFile, updateConfig } from '../src/scripts/plugins.js';
|
|
11
11
|
|
|
12
12
|
export async function startModBuild(config) {
|
|
13
13
|
addEditorConfig();
|
|
14
14
|
createStylelintFile();
|
|
15
|
-
grabGlobalFonts();
|
|
16
15
|
await grabB2BData(config);
|
|
17
16
|
await grabCdn(config);
|
|
18
17
|
await getDefaultTradeQuestions(config);
|
|
19
18
|
await Promise.all([
|
|
20
19
|
grabSharedComponents(config),
|
|
21
20
|
grabFormHelpers(config),
|
|
21
|
+
grabJSDoc(),
|
|
22
22
|
templates(config)
|
|
23
23
|
]).then(async () => {
|
|
24
24
|
await grabSharedScripts(config);
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { defaultSettings } from '../src/data/config.js';
|
|
2
|
-
import axios from 'axios';
|
|
3
|
-
import { createWriteStream } from 'node:fs';
|
|
4
|
-
import * as stream from 'node:stream';
|
|
5
|
-
import { promisify } from 'node:util';
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import { responseInterceptor } from '../src/scripts/retry-axios.js';
|
|
8
|
-
import addFilesToGitignore from './add-files-to-gitignore.js';
|
|
9
|
-
|
|
10
|
-
const resourcePath = 'quote/resources/mod-site/fonts';
|
|
11
|
-
|
|
12
|
-
// Global font names
|
|
13
|
-
const fontNames = [
|
|
14
|
-
'roboto',
|
|
15
|
-
'montserrat'
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
// Font variants and extensions to download for each font
|
|
19
|
-
const fontVariants = ['regular', 'bold'];
|
|
20
|
-
const fontExtensions = ['ttf', 'woff2'];
|
|
21
|
-
|
|
22
|
-
// Generate array of all font files needed for download
|
|
23
|
-
const fontFiles = fontNames.flatMap(fontName => {
|
|
24
|
-
return fontVariants.flatMap(variant => {
|
|
25
|
-
return fontExtensions.map(ext => {
|
|
26
|
-
return `${fontName}/${fontName}-${variant}.${ext}`;
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const axiosInstance = axios.create();
|
|
32
|
-
responseInterceptor(axiosInstance);
|
|
33
|
-
|
|
34
|
-
const streamFontToDestination = (defaultSettings, fontPath) => {
|
|
35
|
-
const finished = promisify(stream.finished);
|
|
36
|
-
|
|
37
|
-
return new Promise(resolve => {
|
|
38
|
-
const filePath = `${defaultSettings.publicFolder}/${defaultSettings.fontsSubfolder}/${fontPath}`;
|
|
39
|
-
const folderPath = filePath.split('/').slice(0, -1).join('/');
|
|
40
|
-
|
|
41
|
-
// Create directory if it doesn't exist
|
|
42
|
-
if (!fs.existsSync(folderPath)) {
|
|
43
|
-
fs.mkdirSync(folderPath, { recursive: true });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// if file exists, do not create it again
|
|
47
|
-
if (fs.existsSync(filePath)) {
|
|
48
|
-
resolve();
|
|
49
|
-
} else {
|
|
50
|
-
const writer = createWriteStream(filePath);
|
|
51
|
-
const options = {
|
|
52
|
-
url: `https://${defaultSettings.nodeEnv}/${resourcePath}/${fontPath}`,
|
|
53
|
-
method: 'get',
|
|
54
|
-
responseType: 'stream'
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
axios(options).then(resp => {
|
|
58
|
-
if (resp.status !== 200) {
|
|
59
|
-
throw new Error(`${resp.status}: Error while fetching ${options.url}`);
|
|
60
|
-
}
|
|
61
|
-
console.log(`${filePath} copied...`);
|
|
62
|
-
resp.data.pipe(writer);
|
|
63
|
-
return finished(writer);
|
|
64
|
-
}).then(() => {
|
|
65
|
-
resolve();
|
|
66
|
-
}).catch(error => {
|
|
67
|
-
console.error(error);
|
|
68
|
-
throw new Error(`${error?.response?.statusText} [${error?.status}]: Error while fetching ${options.url}`);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const updateGitignore = async () => {
|
|
75
|
-
const fontEntries = fontNames.map(fontName =>
|
|
76
|
-
`${defaultSettings.publicFolder}/${defaultSettings.fontsSubfolder}/${fontName}/`
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
await addFilesToGitignore(fontEntries, 'Global fonts');
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export default function() {
|
|
83
|
-
const fontsPath = `${defaultSettings.publicFolder}/${defaultSettings.fontsSubfolder}`;
|
|
84
|
-
if (!fs.existsSync(fontsPath)) {
|
|
85
|
-
fs.mkdirSync(fontsPath, { recursive: true });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Download all font files
|
|
89
|
-
const fontPromises = fontFiles.map(fontPath => {
|
|
90
|
-
return streamFontToDestination(defaultSettings, fontPath);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
return Promise.all(fontPromises).then(async () => {
|
|
94
|
-
// Update .gitignore after fonts are downloaded
|
|
95
|
-
await updateGitignore();
|
|
96
|
-
});
|
|
97
|
-
}
|