Comparing version 1.0.0 to 1.1.0
@@ -23,3 +23,3 @@ #!/usr/bin/env node | ||
stdin.on('end', function () { | ||
if(data.trim().length === 0) { | ||
if (data.trim().length === 0) { | ||
headers.NgBarrel(); | ||
@@ -47,15 +47,5 @@ log.error("No input received."); | ||
const possiblePlaces = getPossibilities(directory, config.barrel); | ||
const closestBarrel = possiblePlaces.find(path => fs.existsSync(path)); | ||
headers.NgBarrel(); | ||
if (closestBarrel !== undefined) { | ||
const closestBarrelPath = strings.trimEnd(config.barrel, closestBarrel); | ||
const fromPath = strings.trimStart(closestBarrelPath, directory + moduleName); | ||
const exportStatement = strings.exportStatement(fromPath); | ||
fs.appendFileSync(closestBarrel, `${exportStatement}\n`); | ||
log.fileWriteEvent(exportStatement, closestBarrel); | ||
} else if (config.create !== undefined) { | ||
if (config.create !== undefined) { | ||
const p = path.join(directory, config.create); | ||
@@ -67,6 +57,25 @@ const newFile = path.join(p, config.barrel); | ||
fs.writeFileSync(newFile, `${exportStatement}\n`); | ||
log.fileWriteEvent(exportStatement, newFile, 'NEW'); | ||
const fileExists = fs.existsSync(newFile); | ||
if (fileExists) { | ||
fs.appendFileSync(newFile, `${exportStatement}\n`); | ||
} else { | ||
fs.writeFileSync(newFile, `${exportStatement}\n`); | ||
} | ||
log.fileWriteEvent(exportStatement, newFile, fileExists ? 'UPDATE' : 'NEW'); | ||
} else { | ||
log.error(`No barrel file named '${config.barrel}' found in tree. No --create/-c argument set either.`); | ||
const possiblePlaces = getPossibilities(directory, config.barrel); | ||
const closestBarrel = possiblePlaces.find(path => fs.existsSync(path)); | ||
if (closestBarrel !== undefined) { | ||
const closestBarrelPath = strings.trimEnd(config.barrel, closestBarrel); | ||
const fromPath = strings.trimStart(closestBarrelPath, directory + moduleName); | ||
const exportStatement = strings.exportStatement(fromPath); | ||
fs.appendFileSync(closestBarrel, `${exportStatement}\n`); | ||
log.fileWriteEvent(exportStatement, closestBarrel); | ||
} else { | ||
log.error(`No barrel file named '${config.barrel}' found in tree. No --create/-c argument set either.`); | ||
} | ||
} | ||
@@ -73,0 +82,0 @@ } |
{ | ||
"name": "ng-barrel", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "CLI tool to add generated Angular files to barrel files", | ||
@@ -5,0 +5,0 @@ "main": "ng-barrel.js", |
@@ -48,3 +48,2 @@ [![npm version](https://badge.fury.io/js/ng-barrel.svg)](https://badge.fury.io/js/ng-barrel) | ||
export * from './example/example.component'; | ||
``` | ||
@@ -69,6 +68,10 @@ | ||
You can also pass `--create / -c` to specify where a barrel file should be created, | ||
when no barrel file was found in the whole tree! | ||
It takes a relative path, which will be combined with the path of the newly added element. | ||
You can also pass `--create / -c` to specify where a barrel file should be created. | ||
If this option is specified it takes priority over tree traversing. | ||
If a barrel file at the specified path already exists, the export will be appended. | ||
Otherwise a new file will be written. | ||
`--create` takes a relative path, which will be combined with the path of the newly added files. | ||
```bash | ||
@@ -75,0 +78,0 @@ $ ng g s foo/services/Data data | ng-barrel -c ./ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8002
112
97