Updated extractor, removed analyzer
This commit is contained in:
@ -29,59 +29,66 @@ snippets = util.readSnippets(SNIPPETS_PATH);
|
||||
archivedSnippets = util.readSnippets(SNIPPETS_ARCHIVE_PATH);
|
||||
tagDbData = util.readTags();
|
||||
// Extract snippet data
|
||||
let snippetData = {
|
||||
data: Object.keys(snippets).map(key => {
|
||||
return {
|
||||
id: key.slice(0, -3),
|
||||
type: 'snippet',
|
||||
attributes: {
|
||||
fileName: key,
|
||||
text: util.getTextualContent(snippets[key]).trim(),
|
||||
codeBlocks: util
|
||||
.getCodeBlocks(snippets[key])
|
||||
.map(v => v.replace(/```js([\s\S]*?)```/g, '$1').trim()),
|
||||
tags: tagDbData[key.slice(0, -3)]
|
||||
},
|
||||
meta: {
|
||||
archived: false,
|
||||
hash: util.hashData(snippets[key])
|
||||
}
|
||||
};
|
||||
}),
|
||||
let snippetData = Object.keys(snippets).map(key => {
|
||||
return {
|
||||
id: key.slice(0, -3),
|
||||
type: 'snippet',
|
||||
attributes: {
|
||||
fileName: key,
|
||||
text: util.getTextualContent(snippets[key]).trim(),
|
||||
codeBlocks: util.getCodeBlocks(snippets[key]),
|
||||
tags: tagDbData[key.slice(0, -3)]
|
||||
},
|
||||
meta: {
|
||||
archived: false,
|
||||
hash: util.hashData(snippets[key])
|
||||
}
|
||||
};
|
||||
});
|
||||
// Extract archived snippet data
|
||||
let snippetArchiveData = Object.keys(archivedSnippets).map(key => {
|
||||
return {
|
||||
id: key.slice(0, -3),
|
||||
type: 'snippet',
|
||||
attributes: {
|
||||
fileName: key,
|
||||
text: util.getTextualContent(archivedSnippets[key]).trim(),
|
||||
codeBlocks: util.getCodeBlocks(archivedSnippets[key]),
|
||||
tags: []
|
||||
},
|
||||
meta: {
|
||||
archived: true,
|
||||
hash: util.hashData(archivedSnippets[key])
|
||||
}
|
||||
};
|
||||
});
|
||||
const completeData = {
|
||||
data: [...snippetData, ...snippetArchiveData],
|
||||
meta: {
|
||||
specification: 'http://jsonapi.org/format/'
|
||||
}
|
||||
};
|
||||
// Extract archived snippet data
|
||||
let snippetArchiveData = {
|
||||
data: Object.keys(archivedSnippets).map(key => {
|
||||
return {
|
||||
id: key.slice(0, -3),
|
||||
type: 'snippet',
|
||||
let listingData = {
|
||||
data:
|
||||
completeData.data.map(v => ({
|
||||
id: v.id,
|
||||
type: 'snippetListing',
|
||||
attributes: {
|
||||
fileName: key,
|
||||
text: util.getTextualContent(archivedSnippets[key]).trim(),
|
||||
codeBlocks: util
|
||||
.getCodeBlocks(archivedSnippets[key])
|
||||
.map(v => v.replace(/```js([\s\S]*?)```/g, '$1').trim()),
|
||||
tags: []
|
||||
tags: v.attributes.tags,
|
||||
archived: v.meta.archived
|
||||
},
|
||||
meta: {
|
||||
archived: true,
|
||||
hash: util.hashData(archivedSnippets[key])
|
||||
hash: v.meta.hash
|
||||
}
|
||||
};
|
||||
}),
|
||||
}))
|
||||
,
|
||||
meta: {
|
||||
specification: 'http://jsonapi.org/format/'
|
||||
}
|
||||
};
|
||||
// Write files
|
||||
fs.writeFileSync(path.join(OUTPUT_PATH, 'snippets.json'), JSON.stringify(snippetData, null, 2));
|
||||
fs.writeFileSync(
|
||||
path.join(OUTPUT_PATH, 'snippetsArchive.json'),
|
||||
JSON.stringify(snippetArchiveData, null, 2)
|
||||
);
|
||||
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.timeEnd('Extractor');
|
||||
|
||||
Reference in New Issue
Block a user