charrismatic / atom-advanced-search

Search, sort, and filtering tool for Atom apm package manager
4 stars 1 forks source link

Does not work on portable mode! #1

Closed TigersWay closed 5 years ago

TigersWay commented 5 years ago
Searching apm (packages) for: lint
'apm' is not recognized as an internal or external command,
operable program or batch file.
exec error: Error: Command failed: apm search --json  lint
'apm' is not recognized as an internal or external command,
operable program or batch file.
...

Maybe there is a way to make it work anyway? Any advice is welcome

charrismatic commented 5 years ago

The command executes 'apm search' in a child process and gets the results as JSON so if you are to run the command in the same window then it should work.

I suppose a better would be to look for the full path to apm in your login session. What operating system are you using?

Also did you install from NPM? The source files wont able to run without building the package since I used Rollup to package it into a single executable.

TigersWay commented 5 years ago

So yes, basic information: Windows 10, node 12.x last & atom 1.40.1 "atom-advanced-search" install with npm, globally.

I wrote a simple batch to call apm (\<path>apm %*) and ran "apm-search" from the same folder... and now I get:

exec error: SyntaxError: Unexpected token D in JSON at position 0
C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2
const help=()=>{console.log([["\n Atom Advanced Search","search, sort, and filtering tool for Atom apm packages"].join(" - "),["\n [USAGE]","apm-search [options] <name>"].join("\n   "),["\n [SELECT OPTIONS]",["  --select-packages","Get packages (default)"].join("\t"),["  --select-themes","Get themes"].join("\t"),["  --select-featured","Get featured packages/themes (ignores name argument)"].join("\t")].join("\n   "),["\n [SORT OPTIONS]",["
--sort-stars","Sort by stars (default)"].join("\t"),["  --sort-downloads","Sort by downloads"].join("\t")].join("\n   "),["\n [GENRAL OPTIONS]",["
--help       ","Show this help menu"].join("\t"),["  --verbose    ","Show more information"].join("\t"),["  --nocolor    ","Disable color printing on output"].join("\t"),["  --version    ","Output package version number"].join("\t")].join("\n   "),[""]].join("\n"))},__DEBUG__=!!process.env.NODE_DEBUG_LOGGING,debug=(...e)=>{__DEBUG__&&console.lo

TypeError: Cannot read property 'sort' of undefined
    at render (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:4504)
    at main (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:4977)
    at Object.<anonymous> (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:5555)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11

I'd really love to make it work :-)

charrismatic commented 5 years ago

Theres probably a difference in the character escaping at the command line. One unwritten feature is that the command accepts data piped in from stdin. This is how I tested it first while I was build the program. I would, see if you can get the apm command working first, then make sure it works on its own with the --json flag and then you can try passing that into the command as:

apm search --json fun-plugin | apm-search 

The error that's showing is a weird combination of the exec command and the help printout being read in like to the command line. I'll have to see what the standards are for character escaping and color formatting on windows are. You should also try adding the --nocolor mode and see if that works, and also make sure the --help command and version actually work

TigersWay commented 5 years ago

Help & version seem to be working

D:\>apm-search --help

 Atom Advanced Search - search, sort, and filtering tool for Atom apm packages

 [USAGE]
   apm-search [options] <name>

 [SELECT OPTIONS]
     --select-packages  Get packages (default)
     --select-themes    Get themes
     --select-featured  Get featured packages/themes (ignores name argument) ........
D:\>apm-search --version
atom-advanced-search v1.0.0

"apm search --json" gives a clear json

D:\>apm search --json fun-plugin

D:\>D:\TigersWay\Portables\Atom\resources\app\apm\bin\apm search --json fun-plugin
[{"name":"dsp-atom-plugin","main":"./lib/index","version":"1.0.2","description":"DSP Atom Plugin","keywords":[],"activationCommands":{},"repository":"https://github.com/AAHP/dsp-atom-plugin","license":"MIT","engines":{"atom":">=1.0.0 <2.0.0"},"scripts":{},"dependencies":{"archiver":"^2.1.1","atom-package-deps":"^4.6.2","axios":"^0.17.1","chokidar":"2","doc-ready":"^1.0.4","fs":"^0.0.1-security","js-base64":"^2.4.0","mkdirp":"^0.5.1","path-parse":"^1.0.5","rimraf":"^2.6.2","thrift":"^0.10.0","touch":"^3.1.0","websocket":"^1.0.25"},"package-deps":["browser-plus"],"devDependencies":{},"readme":"# Atom dsp plugin #\n\n## Start app ##\n\n  ```\n
git clone https://github.com/AAHP/dsp-atom-plugin.git\n

But "D:>D:\TigersWay\Portables\Atom\resources\app\apm\bin\apm search --json fun-plugin | apm-search" just gives me the help message

Not sure how many people use the "portable mode" but I couldn't live without. Anything I can try....

charrismatic commented 5 years ago

On Linux there's no such thing as "Portable mode" everything is already portable. It sound like you would enjoy using a real shell if you got off from windows for a few weeks. I think the issue though is caused by the command prompt not parsing the single quotes and backticks correctly. I published an update that tried to remove those in all the places that interfaced with the prompt. (1.0.3) https://www.npmjs.com/package/atom-advanced-search

You can read more about the specific issue on the node docs page here.

https://nodejs.org/api/all.html#child_process_shell_requirements

On Windows, using cmd.exe a single quote will not work correctly because it only recognizes double " for quoting. In Powershell or Git bash both \' and \" are usable

TigersWay commented 5 years ago

Just tried v1.0.2... And great changes!

D:\>apm-search fun-plugin
Searching apm ( packages ) for: fun-plugin
exec error:  SyntaxError: Unexpected token D in JSON at position 0
    at JSON.parse (<anonymous>)
    at get_packages (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:2584)
    at main (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:5022)
    at Object.<anonymous> (C:\Users\ben\AppData\Roaming\npm\node_modules\atom-advanced-search\bin\apm-search:2:5670)
    at Module._compile (internal/modules/cjs/loader.js:945:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:962:10)
    at Module.load (internal/modules/cjs/loader.js:798:32)
    at Function.Module._load (internal/modules/cjs/loader.js:711:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1014:10)
    at internal/main/run_main_module.js:17:11
No packages listed

but with the complete path and json option:

D:\>D:\TigersWay\Portables\Atom\resources\app\apm\bin\apm search --json fun-plugin | apm-search
Stars Downloads Package Description
-----------------------------------
4  319 atoum-plugin (0.5.0) atoum integration: run your PHP unit tests and get feedback right in Atom editor
2 1795 nsis-plugins (2.1.1) Atom snippets for NSIS plug-ins
2  141 instacodes-plugin (0.0.2) A simple Atom package to upload code to Instacod.es
1  209 hoa-compiler-plugin (0.1.0) PP —the grammar description language from Hoa\Compiler— support in Atom.
1 3990 composer-atom-plugin (0.7.1) Adds syntax highlighting and snippets for Hyperledger Composer in Atom
0   36 try-make-plugins-word-count (0.1.0) A short description of your package
0  153 autocomplete-sceneKitPlugin (8.0.0) Scene Kit Plugin autocomplete package
0  276 atom-xterm-plugin (0.3.0) A short description of your package

So I can start to use it!

charrismatic commented 5 years ago

@TigersWay I posted another update this weekend, I wanted to see if there was any improvement running on the windows shell. I stripped out all the characters that arent compatible cross platform and fixed a couple bugs leftover from the first update.

If you still have issues I built out some more detailed debug logging to see where the issue is.

TigersWay commented 5 years ago

First of all, thanks to keep working on this. Despite the fact Atom seems to be sleeping more and more. I updated it:

D:\>apm-search --version
atom-advanced-search v1.0.5

And after moving to the right path, I got a nice result with colors:

D:\TigersWay\Portables\Atom\resources\app\apm\bin>apm-search markdown
Searching apm ( packages ) for: markdown
COLORTERM environment variable not set, continuing to display with color.
Set NOCOLOR in the environment or --nocolor in the commandline if there are issues
Stars Downloads Package Description
-----------------------------------
 878 261643 markdown-pdf (2.2.0) Convert markdown to pdf, png or jpeg on the fly.
 611 667225 markdown-writer (2.11.9) Make Atom a better Markdown editor and an easier static blogging tool.
 335 140854 markdown-scroll-sync (2.1.2) Auto-scroll markdown-preview tab to match markdown source
 275 345947 language-markdown (0.37.0) Adds grammar support for Markdown (including Github flavored, AtomDoc, Markdown Extra, CriticMark, Y
 202 119734 linter-markdown (5.2.10) Lint markdown on the fly, using remark-lint
...

It's good for me!

charrismatic commented 5 years ago

Ah nice, I'm happy to get the feedback. I picked this to work on so I could build out a few pieces that I could use as a template for command line programs. The feedback on windows compat is very helpful since I haven't used it in a long time.