Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/utils/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import WebSocket from "ws"

// Third party imports
import pkg from "electron"
const { app, dialog } = pkg
import { getPort } from "get-port-please"
import isElectron from "is-electron"
import pTimeout from "p-timeout"
Expand All @@ -24,12 +22,13 @@
return script_path
}

function executable_path(microservice_path) {
async function executable_path(microservice_path) {
if (isElectron()) {
if (app.isPackaged) {
const electron = await import("electron")
if (electron.app.isPackaged) {
return process.resourcesPath

Check warning on line 29 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-else-return)

Unnecessary `else` after `return`.

Check warning on line 29 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-else-return)

Unnecessary `else` after `return`.
} else {
return venv_script_path(app.getAppPath(), microservice_path)
return venv_script_path(electron.app.getAppPath(), microservice_path)
}
} else {
return venv_script_path(process.cwd(), microservice_path)
Expand Down Expand Up @@ -66,61 +65,62 @@
})
}

async function run_script(
executable_name,
executable_path,
args,
expected_response,
timeout_seconds = 30,
) {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject("Timed out after " + timeout_seconds + " seconds")
}, timeout_seconds * 1000)

const command = commandExistsSync(executable_name)
? executable_name
: path.join(executable_path, executable_name)
console.log("run_script", command, args)
const child = child_process.spawn(command, args, {
encoding: "utf8",
shell: true,
})

// You can also use a variable to save the output for when the script closes later
child.stderr.setEncoding("utf8")
child.on("error", (error) => {
dialog.showMessageBox({
child.on("error", async (error) => {
const electron = await import("electron")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dans un isElectron() ? on fait des run_script en mode browser non ?

electron.dialog.showMessageBox({
title: "Title",
type: "warning",
message: "Error occured.\r\n" + error,
})
})
child.stdout.setEncoding("utf8")
child.stdout.on("data", (data) => {
//Here is the output
data = data.toString()
if (data.includes(expected_response)) {
resolve(child)
}
console.log(data)
})

child.stderr.on("data", (data) => {
console.log(data)
})

child.on("close", (_code) => {
//Here you can get the exit code of the script
console.log("Child Process exited with code " + _code)
})
child.on("kill", () => {
console.log("Child Process killed")
})
child.name = command.replace(/^.*[\\/]/, "")
return child
})
}

Check warning on line 123 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-lines-per-function)

The async function `run_script` has too many lines (56). Maximum allowed is 50.

async function run_back(
executable_name,
Expand All @@ -130,7 +130,7 @@
upload_folder_path: undefined,
},
) {
return new Promise(async (resolve, reject) => {

Check warning on line 133 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-async-promise-executor)

Promise executor functions should not be `async`.
let upload_folder_path = args.upload_folder_path
if (!args.upload_folder_path) {
upload_folder_path = path.join(args.project_folder_path, "uploads")
Expand Down Expand Up @@ -162,7 +162,7 @@
executable_path,
args = { project_folder_path },
) {
return new Promise(async (resolve, reject) => {

Check warning on line 165 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-async-promise-executor)

Promise executor functions should not be `async`.
const port = await get_available_port()
const viewer_args = [
"--port " + port,
Expand All @@ -186,7 +186,7 @@
return
}
try {
for (const i = 0; i <= 5; i++) {

Check warning on line 189 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-const-assign)

Unexpected re-assignment of `const` variable i.
console.log(`Deleting folder: ${data_folder_path}`)
fs.rmSync(data_folder_path, { recursive: true, force: true })
console.log(`Deleted folder: ${data_folder_path}`)
Expand Down Expand Up @@ -269,70 +269,70 @@
)
}

async function run_browser(
script_name,
microservices_options = {
back: { executable_name, executable_path, args: { project_folder_path } },
viewer: { executable_name, executable_path, args: { project_folder_path } },
},
) {
console.log("microservices_options", microservices_options)
const back_promise = run_back(
microservices_options.back.executable_name,
microservices_options.back.executable_path,
{
...microservices_options.back.args,
},
)
console.log("back_promise", back_promise)

const viewer_promise = run_viewer(
microservices_options.viewer.executable_name,
microservices_options.viewer.executable_path,
{
...microservices_options.viewer.args,
},
)
console.log("viewer_promise", viewer_promise)

const [back_port, viewer_port] = await Promise.all([
back_promise,
viewer_promise,
])
process.env.GEODE_PORT = back_port
process.env.VIEWER_PORT = viewer_port
console.log("back_port", back_port)
console.log("viewer_port", viewer_port)

process.env.BROWSER = true
process.on("SIGINT", async () => {
console.log("Shutting down microservices")
await Promise.all([kill_back(back_port), kill_viewer(viewer_port)])
console.log("Quitting App...")
process.exit(0)
})

const nuxt_process = child_process.spawn("npm", ["run", script_name], {
shell: true,
FORCE_COLOR: true,
})

return new Promise((resolve) => {
nuxt_process.stdout.on("data", function (data) {
const output = data.toString()
const portMatch = output.match(
/Accepting\ connections\ at\ http:\/\/localhost:(\d+)/,
)
console.log("Nuxt: ", output)
if (portMatch) {
const nuxt_port = portMatch[1]
process.env.NUXT_PORT = nuxt_port
resolve({ geode_port: back_port, viewer_port, nuxt_port })
return
}
})
})
}

Check warning on line 335 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-lines-per-function)

The async function `run_browser` has too many lines (64). Maximum allowed is 50.

export {
create_path,
Expand All @@ -346,4 +346,4 @@
run_back,
run_viewer,
run_browser,
}

Check warning on line 349 in app/utils/local.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-lines)

File has too many lines (349).
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"uuid": "11.1.0",
"vue3-carousel": "0.3.4",
"vuetify": "3.10.11",
"vuetify-nuxt-module": "0.18.7",
"ws": "8.18.3",
"wslink": "1.12.4"
},
Expand Down Expand Up @@ -61,6 +62,9 @@
"vitest": "4.0.15",
"vitest-environment-nuxt": "1.0.1"
},
"peerDependencies": {
"electron": "36.4.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

faut pas aussi rendre optionel l'import electron dans le code ? là c'est juste que le code client va pas réussir a s'executer si il n'a pas electron

},
"overrides": {
"vue": "latest"
},
Expand Down
1 change: 0 additions & 1 deletion tests/integration/microservices/back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in
#

opengeodeweb-back==5.*,>=5.14.3
1 change: 0 additions & 1 deletion tests/integration/microservices/viewer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in
#

opengeodeweb-viewer==1.*,>=1.13.2
6 changes: 4 additions & 2 deletions tests/integration/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Local imports
import { useGeodeStore } from "@ogw_front/stores/geode"
import { useViewerStore } from "@ogw_front/stores/viewer"

Check warning on line 13 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint-plugin-import(max-dependencies)

File has too many dependencies (19). Maximum allowed is 10.
import { useInfraStore } from "@ogw_front/stores/infra"
import { appMode } from "@ogw_front/utils/app_mode"
import { importFile } from "@ogw_front/utils/file_import_workflow"
Expand All @@ -25,14 +25,14 @@
// Local constants
const data_folder = path.join("tests", "integration", "data")

async function setupIntegrationTests(file_name, geode_object) {
const pinia = createTestingPinia({
stubActions: false,
createSpy: vi.fn,
})
setActivePinia(pinia)
const geodeStore = useGeodeStore()
// const hybridViewerStore = useHybridViewerStore()

Check failure on line 35 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(capitalized-comments)

Comments should not begin with a lowercase letter
const infraStore = useInfraStore()
const viewerStore = useViewerStore()
infraStore.app_mode = appMode.BROWSER
Expand All @@ -40,9 +40,11 @@
const microservices_path = path.join("tests", "integration", "microservices")
const project_folder_path = path.join(data_folder, uuidv4())
const upload_folder_path = path.join(__dirname, "data", "uploads")
const back_path = executable_path(path.join(microservices_path, "back"))
const back_path = await executable_path(path.join(microservices_path, "back"))
const back_name = executable_name("opengeodeweb-back")
const viewer_path = executable_path(path.join(microservices_path, "viewer"))
const viewer_path = await executable_path(
path.join(microservices_path, "viewer"),
)
const viewer_name = executable_name("opengeodeweb-viewer")
const [back_port, viewer_port] = await Promise.all([
run_back(back_name, back_path, {
Expand All @@ -53,26 +55,26 @@
project_folder_path: project_folder_path,
}),
])
console.log("back_port", back_port)

Check failure on line 58 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
console.log("viewer_port", viewer_port)

Check failure on line 59 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.

geodeStore.default_local_port = back_port
viewerStore.default_local_port = viewer_port
console.log("after ports")

Check failure on line 63 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.
await viewerStore.ws_connect()
// await hybridViewerStore.initHybridViewer()

Check failure on line 65 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(capitalized-comments)

Comments should not begin with a lowercase letter
console.log("after hybridViewerStore.initHybridViewer")

Check failure on line 66 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(no-console)

Unexpected console statement.

// await viewerStore.ws_connect()

Check failure on line 68 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(capitalized-comments)

Comments should not begin with a lowercase letter
const id = await importFile(file_name, geode_object)
expect(viewerStore.status).toBe(Status.CONNECTED)
console.log("end of setupIntegrationTests")
return { id, back_port, viewer_port, project_folder_path }
}

Check failure on line 73 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-statements)

function `setupIntegrationTests` has too many statements (25). Maximum allowed is 10.

Check failure on line 73 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(func-style)

Expected a function expression.

const mockLockRequest = vi.fn().mockImplementation(async (name, callback) => {
return callback({ name })
})

Check warning on line 77 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(require-await)

Async function has no 'await' expression.

Check failure on line 77 in tests/integration/setup.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(arrow-body-style)

Unexpected block statement surrounding arrow body.

vi.stubGlobal("navigator", {
...navigator,
Expand Down