collectronic
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,5 +0,11 @@ | ||
export interface CollectronicConfig { | ||
filePatterns: string[]; | ||
#!/usr/bin/env node | ||
interface CollectronicConfig { | ||
inputs: string[]; | ||
tag?: string; | ||
hooks?: { | ||
beforePrint?: (collectedData: any) => any; | ||
}; | ||
} | ||
declare const collect: () => Promise<void>; | ||
export type { CollectronicConfig }; | ||
export { collect }; |
@@ -0,1 +1,2 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
@@ -11,12 +12,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
const concat_arrays_1 = require("./utils/concat-arrays"); | ||
const options_defaults_1 = require("options-defaults"); | ||
const collect = async () => { | ||
const configPath = path.join(process.cwd(), `.config/collectronic.ts`); | ||
const config = (await tsImport.load(configPath)).default; | ||
const filePaths = await fastGlob(config.filePatterns); | ||
const localConfig = (await tsImport.load(configPath)).default; | ||
const config = (0, options_defaults_1.defaults)({ | ||
tag: `metadata`, | ||
}, localConfig); | ||
const filePaths = await fastGlob(config.inputs); | ||
const findingComments = filePaths.map(async (filePath) => { | ||
const fileContent = await fs.promises.readFile(filePath, `utf-8`); | ||
const comments = commentParser.parse(fileContent); | ||
const jsons = comments.map((comment) => { | ||
const jsons = comments | ||
.map((comment) => { | ||
const metadataTags = comment.tags.filter((tag) => { | ||
return tag.tag === `metadata`; | ||
return tag.tag === config.tag; | ||
}); | ||
@@ -27,3 +33,4 @@ const metadataJsons = metadataTags.map((metadataTag) => { | ||
return metadataJsons; | ||
}).flat(); | ||
}) | ||
.flat(); | ||
return jsons; | ||
@@ -33,5 +40,6 @@ }); | ||
const foundJsons = foundJsonsInComments.flat(); | ||
const output = _.mergeWith({}, ...foundJsons, concat_arrays_1.concatArrays); | ||
const jsonOutput = JSON.stringify(output, undefined, 4); | ||
console.log(jsonOutput); | ||
let output = _.mergeWith({}, ...foundJsons, concat_arrays_1.concatArrays); | ||
output = config.hooks?.beforePrint?.(output); | ||
const collectedData = JSON.stringify(output, undefined, 4); | ||
console.log(collectedData); | ||
}; | ||
@@ -38,0 +46,0 @@ exports.collect = collect; |
{ | ||
"name": "collectronic", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/main.js", | ||
@@ -13,3 +13,4 @@ "types": "dist/main.d.ts", | ||
"lodash": "4.17.21", | ||
"ts-import": "3.0.0-beta.3", | ||
"options-defaults": "2.0.40", | ||
"ts-import": "4.0.0-beta.2", | ||
"tslib": "2.4.0" | ||
@@ -19,6 +20,6 @@ }, | ||
"@radrat-scripts/package": "2.0.46", | ||
"@radrat/cli": "3.0.0-beta.2", | ||
"@radrat/cli": "3.0.0-beta.4", | ||
"@types/lodash": "4.14.182", | ||
"@types/node": "16.11.7", | ||
"typescript": "4.7.3" | ||
"@types/node": "16.11.41", | ||
"typescript": "4.7.4" | ||
}, | ||
@@ -25,0 +26,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31287
69
6
+ Addedoptions-defaults@2.0.40
+ Addedoptions-defaults@2.0.40(transitive)
+ Addedts-import@4.0.0-beta.2(transitive)
- Removedts-import@3.0.0-beta.3(transitive)
Updatedts-import@4.0.0-beta.2