@charlietango/react-docs-net
Advanced tools
Comparing version
@@ -11,2 +11,7 @@ // | ||
/** | ||
@@ -20,8 +25,2 @@ * Find all JSON files matching glob. | ||
) { | ||
if (!config.namespace) { | ||
throw new Error( | ||
'You need to set a namespace for the models, like "Dk.CharlieTango.ViewModel".' | ||
); | ||
} | ||
const files = await globby(globOrFiles); | ||
@@ -34,7 +33,20 @@ | ||
const models = files | ||
.map(file => { | ||
const name = path.basename(file, '.json'); | ||
const json = JSON.parse(fs.readFileSync(file, 'utf-8')); | ||
return createViewModel(name, json, config); | ||
const components = files.map(file => ({ | ||
name: path.basename(file, '.json'), | ||
docs: JSON.parse(fs.readFileSync(file, 'utf-8')), | ||
})); | ||
return createModels(components, config); | ||
} | ||
function createModels(sources , config ) { | ||
if (!config.namespace) { | ||
throw new Error( | ||
'You need to set a namespace for the models, like "Dk.CharlieTango.ViewModel".' | ||
); | ||
} | ||
const models = sources | ||
.map(source => { | ||
return createViewModel(source.name, source.docs, config); | ||
}) | ||
@@ -48,11 +60,11 @@ // Smoosh the array | ||
if (!config.quiet) { | ||
console.log(`Outputting models to\n${chalk.cyan(config.dest)}`); | ||
console.log(chalk.cyan('Output view models:')); | ||
} | ||
models.forEach(output => { | ||
if (!config.quiet) console.log(chalk.grey(` > Add ${output.name}.cs`)); | ||
fs.writeFileSync( | ||
path.join(config.dest, `${output.name}.cs`), | ||
output.source | ||
); | ||
const fileDest = path.join(config.dest, `${output.name}.cs`); | ||
if (!config.quiet) { | ||
console.log(chalk.grey(` > ${path.relative(process.cwd(), fileDest)}`)); | ||
} | ||
fs.writeFileSync(fileDest, output.source); | ||
}); | ||
@@ -109,2 +121,6 @@ } | ||
module.exports = docsFromJson; | ||
module.exports = { | ||
default: docsFromJson, | ||
fromJson: docsFromJson, | ||
createModels, | ||
}; |
{ | ||
"name": "@charlietango/react-docs-net", | ||
"description": "Package and publish a NuGet package to a custom feed.", | ||
"version": "1.1.9", | ||
"version": "1.1.10", | ||
"main": "lib/index.js", | ||
"bin": "bin/react-docs-net.js", | ||
"bin": { | ||
"ct-docs-net": "bin/ct-docs-net.js" | ||
}, | ||
"license": "MIT", | ||
@@ -21,4 +23,4 @@ "engines": { | ||
"scripts": { | ||
"build": "node tools/compile", | ||
"build:watch": "node tools/compile --watch", | ||
"build": "node ../../tools/compile", | ||
"build:watch": "node ../../tools/compile --watch", | ||
"pretty": "prettier '**/*.{js,css,md,json}' --write", | ||
@@ -40,4 +42,3 @@ "preversion": "yarn build", | ||
"chokidar": "^2.0.2", | ||
"flow-bin": "^0.66.0", | ||
"flow-remove-types": "^1.2.3", | ||
"flow-bin": "^0.67.1", | ||
"jest": "^22.4.2", | ||
@@ -44,0 +45,0 @@ "jest-plugin-fs": "^2.7.0", |
@@ -17,2 +17,3 @@ # React Docs Net | ||
* **Flow** Currently only supports extracting models from Flow Types. | ||
* **react-docgen** JSON files | ||
@@ -32,3 +33,3 @@ ## Usage | ||
docNet('src/models/**/*.json', { | ||
docNet.fromJson('src/models/**/*.json', { | ||
namespace: 'Dk.CharlieTango', | ||
@@ -35,0 +36,0 @@ dest: 'dist/models', // Add dest to write to files |
40599
77.97%8
-11.11%16
60%705
1.29%61
1.67%