Linted scripts
This commit is contained in:
@ -15,27 +15,17 @@ const SNIPPETS_PATH = './snippets';
|
||||
const SNIPPETS_ARCHIVE_PATH = './snippets_archive';
|
||||
const STATIC_PARTS_PATH = './static-parts';
|
||||
|
||||
if (
|
||||
util.isTravisCI() &&
|
||||
/^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])
|
||||
) {
|
||||
if (util.isTravisCI() && /^Travis build: \d+/g.test(process.env['TRAVIS_COMMIT_MESSAGE'])) {
|
||||
console.log(
|
||||
`${chalk.green(
|
||||
'NOBUILD'
|
||||
)} README build terminated, parent commit is a Travis build!`
|
||||
`${chalk.green('NOBUILD')} README build terminated, parent commit is a Travis build!`
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
if (
|
||||
util.isTravisCI() &&
|
||||
(process.env['TRAVIS_EVENT_TYPE'] === 'cron' ||
|
||||
process.env['TRAVIS_EVENT_TYPE'] === 'api')
|
||||
(process.env['TRAVIS_EVENT_TYPE'] === 'cron' || process.env['TRAVIS_EVENT_TYPE'] === 'api')
|
||||
) {
|
||||
console.log(
|
||||
`${chalk.green(
|
||||
'ARCHIVE'
|
||||
)} Cron job or custom build, building archive README!`
|
||||
);
|
||||
console.log(`${chalk.green('ARCHIVE')} Cron job or custom build, building archive README!`);
|
||||
console.time('Builder');
|
||||
let snippets = {};
|
||||
// Synchronously read all snippets from snippets_archive folder and sort them as necessary (case-insensitive)
|
||||
@ -45,10 +35,7 @@ if (
|
||||
.sort((a, b) => a.toLowerCase() - b.toLowerCase());
|
||||
// Store the data read from each snippet in the appropriate object
|
||||
for (const name of snippetFilenames.filter(s => s !== 'README.md')) {
|
||||
snippets[name] = fs.readFileSync(
|
||||
path.join(SNIPPETS_ARCHIVE_PATH, name),
|
||||
'utf8'
|
||||
);
|
||||
snippets[name] = fs.readFileSync(path.join(SNIPPETS_ARCHIVE_PATH, name), 'utf8');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`${chalk.red('ERROR!')} During snippet loading: ${err}`);
|
||||
@ -76,23 +63,18 @@ if (
|
||||
data.slice(data.lastIndexOf('```js'), data.lastIndexOf('```')) +
|
||||
data.slice(data.lastIndexOf('```'))
|
||||
);
|
||||
output += data + '\n<br>' + misc.link('⬆ Back to top', misc.anchor('Table of Contents')) + '\n\n';
|
||||
output +=
|
||||
data + '\n<br>' + misc.link('⬆ Back to top', misc.anchor('Table of Contents')) + '\n\n';
|
||||
}
|
||||
|
||||
// Write to the README file of the archive
|
||||
fs.writeFileSync(path.join(SNIPPETS_ARCHIVE_PATH, 'README.md'), output);
|
||||
} catch (err) {
|
||||
console.log(
|
||||
`${chalk.red(
|
||||
'ERROR!'
|
||||
)} During README generation for snippets archive: ${err}`
|
||||
);
|
||||
console.log(`${chalk.red('ERROR!')} During README generation for snippets archive: ${err}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${chalk.green('SUCCESS!')} README file generated for snippets archive!`
|
||||
);
|
||||
console.log(`${chalk.green('SUCCESS!')} README file generated for snippets archive!`);
|
||||
console.timeEnd('Builder');
|
||||
}
|
||||
let snippets = {};
|
||||
@ -124,14 +106,8 @@ snippets = util.readSnippets(SNIPPETS_PATH);
|
||||
|
||||
// Load static parts for the README file
|
||||
try {
|
||||
startPart = fs.readFileSync(
|
||||
path.join(STATIC_PARTS_PATH, 'README-start.md'),
|
||||
'utf8'
|
||||
);
|
||||
endPart = fs.readFileSync(
|
||||
path.join(STATIC_PARTS_PATH, 'README-end.md'),
|
||||
'utf8'
|
||||
);
|
||||
startPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-start.md'), 'utf8');
|
||||
endPart = fs.readFileSync(path.join(STATIC_PARTS_PATH, 'README-end.md'), 'utf8');
|
||||
} catch (err) {
|
||||
console.log(`${chalk.red('ERROR!')} During static part loading: ${err}`);
|
||||
process.exit(1);
|
||||
@ -170,9 +146,10 @@ try {
|
||||
const taggedSnippets = Object.entries(tagDbData).filter(v => v[1][0] === tag);
|
||||
output += headers.h3((EMOJIS[tag] || '') + ' ' + capitalizedTag).trim();
|
||||
|
||||
output += misc.collapsible(
|
||||
output +=
|
||||
misc.collapsible(
|
||||
'View contents',
|
||||
lists.ul(taggedSnippets, (snippet) =>
|
||||
lists.ul(taggedSnippets, snippet =>
|
||||
misc.link(
|
||||
`\`${snippet[0]}\``,
|
||||
`${misc.anchor(snippet[0])}${snippet[1].includes('advanced') ? '-' : ''}`
|
||||
@ -199,14 +176,18 @@ try {
|
||||
snippet = snippet.join('\n');
|
||||
}
|
||||
|
||||
snippet = snippet.slice(0, snippet.lastIndexOf('```js')).trim() +
|
||||
snippet =
|
||||
snippet.slice(0, snippet.lastIndexOf('```js')).trim() +
|
||||
misc.collapsible(
|
||||
'Examples',
|
||||
snippet.slice(snippet.lastIndexOf('```js'), snippet.lastIndexOf('```')) +
|
||||
snippet.slice(snippet.lastIndexOf('```'))
|
||||
);
|
||||
|
||||
output += `${snippet}\n<br>${misc.link('⬆ Back to top', misc.anchor('Table of Contents'))}\n\n`;
|
||||
output += `${snippet}\n<br>${misc.link(
|
||||
'⬆ Back to top',
|
||||
misc.anchor('Table of Contents')
|
||||
)}\n\n`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -165,15 +165,17 @@ try {
|
||||
'</h4>';
|
||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag))
|
||||
output += md
|
||||
.render(`[${taggedSnippet[0]}](./${tag == 'array' ?'index' : tag}#${taggedSnippet[0].toLowerCase()})\n`)
|
||||
.render(
|
||||
`[${taggedSnippet[0]}](./${
|
||||
tag == 'array' ? 'index' : tag
|
||||
}#${taggedSnippet[0].toLowerCase()})\n`
|
||||
)
|
||||
.replace(/<p>/g, '')
|
||||
.replace(/<\/p>/g, '')
|
||||
.replace(/<a/g, `<a tags="${taggedSnippet[1].join(',')}"`)
|
||||
;
|
||||
.replace(/<a/g, `<a tags="${taggedSnippet[1].join(',')}"`);
|
||||
output += '\n';
|
||||
}
|
||||
output +=
|
||||
'</nav><main class="col-centered">';
|
||||
output += '</nav><main class="col-centered">';
|
||||
output += '<span id="top"><br/><br/></span>';
|
||||
// Loop over tags and snippets to create the list of snippets
|
||||
for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1][0]))]
|
||||
@ -196,17 +198,20 @@ try {
|
||||
for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag))
|
||||
localOutput +=
|
||||
'<div class="card code-card">' +
|
||||
`<div class="corner ${taggedSnippet[1].includes('advanced') ? 'advanced' : taggedSnippet[1].includes('beginner') ? 'beginner' : 'intermediate'}"></div>` +
|
||||
`<div class="corner ${
|
||||
taggedSnippet[1].includes('advanced')
|
||||
? 'advanced'
|
||||
: taggedSnippet[1].includes('beginner')
|
||||
? 'beginner'
|
||||
: 'intermediate'
|
||||
}"></div>` +
|
||||
md
|
||||
.render(`\n${snippets[taggedSnippet[0] + '.md']}`)
|
||||
.replace(
|
||||
/<h3/g,
|
||||
`<div class="section card-content"><h4 id="${taggedSnippet[0].toLowerCase()}"`
|
||||
)
|
||||
.replace(
|
||||
/<\/h3>/g,
|
||||
'</h4>'
|
||||
)
|
||||
.replace(/<\/h3>/g, '</h4>')
|
||||
.replace(
|
||||
/<pre><code class="language-js">/m,
|
||||
'</div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre><code class="language-js">'
|
||||
@ -220,7 +225,10 @@ try {
|
||||
)}</pre>`
|
||||
)
|
||||
.replace(/<\/div>\s*<pre class="/g, '</div><pre class="section card-code ')
|
||||
.replace(/<\/pre>\s+<pre class="/g, '</pre><label class="collapse">examples</label><pre class="section card-examples ') +
|
||||
.replace(
|
||||
/<\/pre>\s+<pre class="/g,
|
||||
'</pre><label class="collapse">examples</label><pre class="section card-examples '
|
||||
) +
|
||||
'</div>';
|
||||
// Add the ending static part
|
||||
localOutput += `\n${endPart + '\n'}`;
|
||||
@ -262,8 +270,13 @@ try {
|
||||
removeStyleLinkTypeAttributes: false,
|
||||
trimCustomFragments: true
|
||||
});
|
||||
fs.writeFileSync(path.join(docsPath, (page.tag == 'array' ? 'index' : page.tag) + '.html'), page.content);
|
||||
console.log(`${chalk.green('SUCCESS!')} ${page.tag == 'array' ? 'index' : page.tag}.html file generated!`);
|
||||
fs.writeFileSync(
|
||||
path.join(docsPath, (page.tag == 'array' ? 'index' : page.tag) + '.html'),
|
||||
page.content
|
||||
);
|
||||
console.log(
|
||||
`${chalk.green('SUCCESS!')} ${page.tag == 'array' ? 'index' : page.tag}.html file generated!`
|
||||
);
|
||||
});
|
||||
} catch (err) {
|
||||
// Handle errors (hopefully not!)
|
||||
@ -377,14 +390,8 @@ try {
|
||||
'<div class="card code-card">' +
|
||||
md
|
||||
.render(`\n${filteredArchivedSnippets[snippet[0]]}`)
|
||||
.replace(
|
||||
/<h3/g,
|
||||
`<div class="section card-content"><h4 id="${snippet[0].toLowerCase()}"`
|
||||
)
|
||||
.replace(
|
||||
/<\/h3>/g,
|
||||
'</h4>'
|
||||
)
|
||||
.replace(/<h3/g, `<div class="section card-content"><h4 id="${snippet[0].toLowerCase()}"`)
|
||||
.replace(/<\/h3>/g, '</h4>')
|
||||
.replace(
|
||||
/<pre><code class="language-js">/m,
|
||||
'</div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre><code class="language-js">'
|
||||
@ -398,7 +405,10 @@ try {
|
||||
)}</pre>`
|
||||
)
|
||||
.replace(/<\/div>\s*<pre class="/g, '</div><pre class="section card-code ')
|
||||
.replace(/<\/pre>\s+<pre class="/g, '</pre><label class="collapse">examples</label><pre class="section card-examples ') +
|
||||
.replace(
|
||||
/<\/pre>\s+<pre class="/g,
|
||||
'</pre><label class="collapse">examples</label><pre class="section card-examples '
|
||||
) +
|
||||
'</div>';
|
||||
|
||||
// Optimize punctuation nodes
|
||||
@ -468,14 +478,8 @@ try {
|
||||
'<div class="card code-card"><div class="section card-content">' +
|
||||
md
|
||||
.render(`\n${filteredGlossarySnippets[snippet[0]]}`)
|
||||
.replace(
|
||||
/<h3/g,
|
||||
`<h4 id="${snippet[0].toLowerCase()}"`
|
||||
)
|
||||
.replace(
|
||||
/<\/h3>/g,
|
||||
'</h4>'
|
||||
) +
|
||||
.replace(/<h3/g, `<h4 id="${snippet[0].toLowerCase()}"`)
|
||||
.replace(/<\/h3>/g, '</h4>') +
|
||||
'</div></div>';
|
||||
|
||||
glossaryOutput += `${glossaryEndPart}`;
|
||||
@ -523,7 +527,10 @@ try {
|
||||
}
|
||||
// Copy contributing.html
|
||||
try {
|
||||
fs.copyFileSync(path.join(staticPartsPath, 'contributing.html'), path.join(docsPath, 'contributing.html'));
|
||||
fs.copyFileSync(
|
||||
path.join(staticPartsPath, 'contributing.html'),
|
||||
path.join(docsPath, 'contributing.html')
|
||||
);
|
||||
console.log(`${chalk.green('SUCCESS!')} contributing.html file copied!`);
|
||||
} catch (err) {
|
||||
console.log(`${chalk.red('ERROR!')} During contributing.html copying: ${err}`);
|
||||
|
||||
Reference in New Issue
Block a user