Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pgn-parser - experimenty s npm #7

Open
Bebul opened this issue Nov 4, 2020 · 3 comments
Open

pgn-parser - experimenty s npm #7

Bebul opened this issue Nov 4, 2020 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@Bebul
Copy link
Owner

Bebul commented Nov 4, 2020

Chci použít: https://github.com/mliebelt/pgn-parser

V IntelliJ build in terminal:

D:\dev\MondayFight>npm i @mliebelt/pgn-parser --save
npm WARN saveError ENOENT: no such file or directory, open 'D:\dev\MondayFight\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\dev\MondayFight\package.json'
npm WARN MondayFight No description
npm WARN MondayFight No repository field.
npm WARN MondayFight No README data
npm WARN MondayFight No license field.

+ @mliebelt/[email protected]
added 1 package from 1 contributor and audited 1 package in 4.836s
found 0 vulnerabilities

Zkoušel jsem předtím použít zdrojáky přes github clone. Ale řvalo to mnoho různých errorů, souvisejících s module, require atd.

@Bebul
Copy link
Owner Author

Bebul commented Nov 4, 2020

Uncaught SyntaxError: Cannot use import statement outside a module

@Bebul
Copy link
Owner Author

Bebul commented Nov 4, 2020

image

Řešením bylo použití Browserify. Je to tricky:

  • nainstaloval jsem Browserify zmíněným příkazem z IntelliJ terminálu příkazem npm
  • mám teď browserify přístupný z cmd.exe
  1. do jeho zdrojáků nechceme zasahovat a pgn-parser.js lze použít jen v nějakém module, rádoby Node.js stylu.
  2. proto si vyrobím vlastní skript, který vystěhuje to co potřebuju ven
    • hlavní trik: funkce se vystěhuje do window.mojeFunkce = funkceKterouChci

Napsal jsem to jako dokumentační issue přímo k tomu pgn-parser

@Bebul
Copy link
Owner Author

Bebul commented Nov 4, 2020

I had hard time to make the library possible to use in the client side application, Browser.

The successfull steps were at last:

  1. install Browserify
  2. store the parse function as window property
    File: parsePgn.js
   const parser =  require('./pgn-parser.js')
   window.parsePgn = parser.parse
  1. process newly created parsePgn.js through Browserify:
 browserify parsePgn.js -o pgn-bundle.js
  1. in the index.html then use
 <script type="text/javascript" src="pgn/pgn-bundle.js"></script>
  1. and the parsePgn is now available:
     let gameList = parsePgn('[White "Me"] [Black "Magnus"] 1. f4 e5 2. g4 Qh4#', {startRule: "game"});

@Bebul Bebul added the documentation Improvements or additions to documentation label Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant