Giter VIP home page Giter VIP logo

Comments (6)

sverweij avatar sverweij commented on June 13, 2024

Hi @chenxinfeng4 it's probably easiest to use the command line interface for that. It runs on node.js and can be installed with node.js's default package manager.

I have no experience with calling node programs from python or c++, but I guess the thing that enables calling executables from an os or system package should do the trick.

state-machine-cat.js.org doesn't run an API - it's only a 'static' website...

from state-machine-cat.

chenxinfeng4 avatar chenxinfeng4 commented on June 13, 2024

Is it possible to deploy all the dependence into one folder? I can just access the smcat.exe to get all the functions. I don't want consumer to manully install the nodejs or npm. It's easy to deploy python program or java program, I have no idea how to deploy nodejs.

from state-machine-cat.

sverweij avatar sverweij commented on June 13, 2024

Hi @chenxinfeng4 I've heard of solutions that bundle node applications, including the node.js run time & libs into single executables, but I have no experience with them.

from state-machine-cat.

chenxinfeng4 avatar chenxinfeng4 commented on June 13, 2024

Sad, something went wrong when I packaged the cmcat.
$ npm install --global pkg
$ pkg -t node18 bin\smcat.mjs -d

[email protected]
[debug] Bytecode of C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin\smcat.mjs is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin\smcat.mjs is added to queue.
Warning Babel parse has failed: 'await' is only allowed within async functions and at the top levels of modules. (5:0)
[debug] Directory C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin is added to queue.
[debug] Directory C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat is added to queue.
[debug] Directory C:\Users\666\AppData\Roaming\npm\node_modules is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming\npm\node_modules is added to queue.
[debug] Directory C:\Users\666\AppData\Roaming\npm is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming\npm is added to queue.
[debug] Directory C:\Users\666\AppData\Roaming is added to queue.
[debug] Stat info of C:\Users\666\AppData\Roaming is added to queue.
[debug] Directory C:\Users\666\AppData is added to queue.
[debug] Stat info of C:\Users\666\AppData is added to queue.
[debug] Directory C:\Users\666 is added to queue.
[debug] Stat info of C:\Users\666 is added to queue.
[debug] Directory C:\Users is added to queue.
[debug] Stat info of C:\Users is added to queue.
[debug] Directory C:\ is added to queue.
[debug] Stat info of C:\ is added to queue.
[debug] Deleting record file : C:
[debug] Deleting record file : C:\Users
[debug] Deleting record file : C:\Users\666
[debug] Deleting record file : C:\Users\666\AppData
[debug] Deleting record file : C:\Users\666\AppData\Roaming
[debug] Deleting record file : C:\Users\666\AppData\Roaming\npm
[debug] Deleting record file : C:\Users\666\AppData\Roaming\npm\node_modules
[debug] The file was included as bytecode (no sources)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin\smcat.mjs
[debug] The file was included as bytecode (no sources)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin\smcat.mjs
[debug] files & folders deduped =
smcat.mjs
[debug] The directory files list was included (1 item)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin
[debug] The directory files list was included (1 item)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\bin
[debug] files & folders deduped =
bin
[debug] The directory files list was included (1 item)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat
[debug] The directory files list was included (1 item)
C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat
[debug] Targets:
[
{
"nodeRange": "node18",
"platform": "win",
"arch": "x64",
"output": "C:\Users\666\AppData\Roaming\npm\node_modules\state-machine-cat\smcat.exe",
"forceBuild": false,
"fabricator": {
"nodeRange": "node18",
"platform": "win",
"arch": "x64",
"binaryPath": "C:\Users\666\.pkg-cache\v3.4\fetched-v18.5.0-win-x64"
},
"binaryPath": "C:\Users\666\.pkg-cache\v3.4\fetched-v18.5.0-win-x64"
}
]
C:\snapshot\node_modules\state-machine-cat\bin\smcat.mjs:3
import executeCommandLine from "../dist/cli/execute-command-line.mjs";
^^^^^^

SyntaxError: Cannot use import statement outside a module
at new Script (node:vm:102:7)
at Socket. ([eval]:18:19)
at Socket.emit (node:events:537:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

Node.js v18.5.0

from state-machine-cat.

sverweij avatar sverweij commented on June 13, 2024

Hi @chenxinfeng4 it seems that pkg doesn't support modern javascript. As state-machine-cat uses modern javascript, that probably means pkg is not suitable to package it.

I've searched a bit for alternatives for single executable applications on nodejs, but it turns out none of the ones I found will work.

  • nexe is one, but that hasn't seen maintenance in a while.
  • node.js has experimental support to generate single executable applications out of the box as well, however it's limited to old-fashioned javascript only at the moment (from https://nodejs.org/api/single-executable-applications.html: The single executable application feature currently only supports running a single embedded script using the CommonJS module system.)

Alternatively, if you want to run a modern node module from a single folder this should work:

  • install the module (e.g. npm i state-machine-cat) in that folder
  • copy the node executable to that folder (which, on windows, you apparently do like this: node -e "require('fs').copyFileSync(process.execPath, 'my-node.exe')" - source: node.js documentation )

All you need to run state-machine-cat should now be in that folder. To run it, in that folder:

my-node.exe node_modules/state-machine-cat/bin/smcat.mjs

Note

I have tried this on my own machine only, which is not a windows machine

hope this helps.

from state-machine-cat.

chenxinfeng4 avatar chenxinfeng4 commented on June 13, 2024

That seems a great solution, thanks for your kind help.

from state-machine-cat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.