Created VSCode snippet data

Also some minor changes and updates to files all over the place
This commit is contained in:
Angelos Chalaris
2018-10-26 19:54:18 +03:00
parent 0614f8731c
commit 5968e2286b
11 changed files with 3754 additions and 381 deletions

View File

@ -90,5 +90,5 @@ let listingData = {
fs.writeFileSync(path.join(OUTPUT_PATH, 'snippets.json'), JSON.stringify(completeData, null, 2));
fs.writeFileSync(path.join(OUTPUT_PATH, 'snippetList.json'), JSON.stringify(listingData, null, 2));
// Display messages and time
console.log(`${chalk.green('SUCCESS!')} snippets.json and snippetsArchive.json files generated!`);
console.log(`${chalk.green('SUCCESS!')} snippets.json and snippetList.json files generated!`);
console.timeEnd('Extractor');

View File

@ -131,7 +131,7 @@ const getCodeBlocks = str => {
results = results.map(v => v.replace(/```js([\s\S]*?)```/g, '$1').trim());
return {
es6: results[0],
es5: babel.transformSync(results[0], { presets: ['@babel/preset-env'] }).code,
es5: babel.transformSync(results[0], { presets: ['@babel/preset-env'] }).code.replace('"use strict";\n\n',''),
example: results[1]
}
};

33
scripts/vscodegen.js Normal file
View File

@ -0,0 +1,33 @@
/*
This is the VSCode generator script that generates the vscode_snippets/snippets.json file.
Run using `npm run vscoder`.
*/
// Load modules
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
let snippetsData = require('../snippet_data/snippets.json');
// Paths
const OUTPUT_PATH = './vscode_snippets';
console.time('VSCoder');
// Read and format data
let vscodeData = snippetsData.data.filter(v => !v.meta.archived ).reduce((acc,v) => {
acc[v.id] = {
prefix: `30s_${v.id}`,
body: v.attributes.codeBlocks.es6.replace(/\r/g,'').split('\n'),
description: v.attributes.text.slice(0, v.attributes.text.indexOf('\r\n\r\n'))
};
return acc;
}, {});
// Write data
fs.writeFileSync(
path.join(OUTPUT_PATH, 'snippets.json'),
JSON.stringify(vscodeData, null, 2)
);
// Display messages and time
console.log(
`${chalk.green(
'SUCCESS!'
)} vscode_snippets/snippets.json file generated!`
);
console.timeEnd('VSCoder');