Skip to content

Conversation

@designfrontier
Copy link
Owner

This lets you pass in the publish script's location as
a command line argument. Also fixes some bugs that were found in doing that work.

closes #15

designfrontier and others added 2 commits May 11, 2018 14:07
This lets you pass in the publish script's location as
a command line argument.
@designfrontier
Copy link
Owner Author

@rwstauner @phallstrom If you guys want to put this through its paces...

@designfrontier
Copy link
Owner Author

The test are breaking for other reasons... that are unrelated

@rwstauner
Copy link
Contributor

it needs at least:

diff --git a/modules/check-ownership.js b/modules/check-ownership.js
index 1196f41..7eca67f 100644
--- a/modules/check-ownership.js
+++ b/modules/check-ownership.js
@@ -1,4 +1,5 @@
 const cp = require('child_process')
+      fs = require('fs')
       path = require('path');
 
 module.exports = (details, publish) => {
@@ -6,12 +7,12 @@ module.exports = (details, publish) => {
   const ownership = (ownedLines / size) * 100;
   const publishFile = path.join(process.cwd(), config.publish);
 
-  if (ownership >= config.threshold /*&& author !== currentAuthor*/) {
+  if (ownership >= config.threshold && author !== currentAuthor) {
     if (publish)  {
       try {
         fs.statSync(publishFile).isFile();
       } catch (e) {
-        console.log('Your publish script does not seem to exist?');
+        console.log(`Your publish script (${publishFile}) does not seem to exist: ${e}`);
         process.exit(1);
       }

@rwstauner
Copy link
Contributor

possibly

diff --git a/modules/check-ownership.js b/modules/check-ownership.js
index 1196f41..7a017c3 100644
--- a/modules/check-ownership.js
+++ b/modules/check-ownership.js
@@ -1,17 +1,18 @@
 const cp = require('child_process')
+      fs = require('fs')
       path = require('path');
 
 module.exports = (details, publish) => {
   const { size, ownedLines, author, filePath, currentAuthor, config } = details;
   const ownership = (ownedLines / size) * 100;
-  const publishFile = path.join(process.cwd(), config.publish);
+  const publishFile = config.publish;
 
-  if (ownership >= config.threshold /*&& author !== currentAuthor*/) {
+  if (ownership >= config.threshold && author !== currentAuthor) {
     if (publish)  {
       try {
         fs.statSync(publishFile).isFile();
       } catch (e) {
-        console.log('Your publish script does not seem to exist?');
+        console.log(`Your publish script (${publishFile}) does not seem to exist: ${e}`);
         process.exit(1);
       }
 
diff --git a/modules/read-config.js b/modules/read-config.js
index 5a270c9..47813fe 100644
--- a/modules/read-config.js
+++ b/modules/read-config.js
@@ -7,7 +7,8 @@ module.exports = ({ location = '.pythia-config', publish}) => {
   const configFile = fs.existsSync(filePath) ? readFile(filePath) : {};
   const exclude = configFile.exclude ? readFile(filePath).exclude : {};
   const threshold = configFile.threshold || 20;
-  const publishFinal = publish || configFile.publish || '.pythia-publish';
+  const publishBase = publish || configFile.publish || '.pythia-publish';
+  const publishPath = path.isAbsolute(publishBase) ? publishBase : path.join(process.cwd(), publishBase);
 
   ['users', 'directories', 'files'].forEach((item) => {
     if (typeof exclude[item] === 'undefined') {
@@ -15,11 +16,11 @@ module.exports = ({ location = '.pythia-config', publish}) => {
     }
   });
 
-  if (publish) {
+  if (publishPath) {
     try {
-      fs.statSync(path.join(process.cwd(), publish)).isFile();
+      fs.statSync(publishPath).isFile();
     } catch (e) {
-      console.log('Please provide a file with your --publish or -p flag');
+      console.log(`Please provide a file with your --publish or -p flag (${publishPath} does not exist)`);
       process.exit(1);
     }
   }
@@ -27,6 +28,6 @@ module.exports = ({ location = '.pythia-config', publish}) => {
   return {
   	exclude,
     threshold,
-    publish: publishFinal
+    publish: publishPath
   };
 };

@designfrontier
Copy link
Owner Author

Can't believe I left that author line commented out. Added your suggestions and centralized handling of the publish file existence to a single location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow for passing in the publish script name/location

3 participants