Skip to content

Commit

Permalink
Merge pull request #17 from neuralinterfaces/v0.0.55
Browse files Browse the repository at this point in the history
0.0.55 Release
  • Loading branch information
garrettmflynn authored Dec 5, 2024
2 parents 8f790e1 + 71f96d2 commit f4eae2e
Show file tree
Hide file tree
Showing 42 changed files with 527 additions and 402 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
title: "Commoners",
description: "Building Solidarity across Platforms",

head: [['link', { rel: 'icon', href: '/logo.png' }]],
head: [['link', { rel: 'icon', href: '/logo-min.png' }]],

themeConfig: {

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Follow the prompts to select your favorite framework and features.
After running `npm install`, add Commoners as a dependency:

```bash
npm install -D [email protected].54
npm install -D [email protected].55
```

## Configuring the `package.json` File
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default {
You can also use the included helper function to declare Python services:

```js
import { python } from '@commoners/solidarity/services'
import { services } from '@commoners/solidarity'

const pythonService = {
name: 'python-service',
Expand All @@ -75,6 +75,6 @@ const pythonService = {

export default {
// ...
services: python.services([ pythonService ])
services: services.python.services([ pythonService ])
}
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ hero:
name: Commoners
tagline: Cross-Platform Development for the Rest of Us
image:
src: /logo.png
src: /logo-min.png
alt: Commoners
actions:
- theme: brand
Expand Down
Binary file added docs/public/logo-min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/public/logo.png
Binary file not shown.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
"demo:launch": "commoners launch tests/demo"
},
"devDependencies": {
"@commoners/bluetooth": "0.0.52",
"@commoners/custom-protocol": "0.0.52",
"@commoners/serial": "0.0.52",
"@commoners/solidarity": "0.0.54",
"@commoners/splash-screen": "0.0.52",
"@commoners/testing": "0.0.54",
"@commoners/windows": "0.0.54",
"@commoners/bluetooth": "0.0.55",
"@commoners/custom-protocol": "0.0.55",
"@commoners/serial": "0.0.55",
"@commoners/solidarity": "0.0.55",
"@commoners/splash-screen": "0.0.55",
"@commoners/testing": "0.0.55",
"@commoners/windows": "0.0.55",
"@vitest/coverage-v8": "^2.0.3",
"search-insights": "^2.15.0",
"commoners": "0.0.54",
"commoners": "0.0.55",
"vite": "^5.3.4",
"vitepress": "^1.3.1",
"vitest": "^2.0.3"
Expand Down
54 changes: 26 additions & 28 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import {
build,
buildServices,

launch,
launchServices,
resolveServiceConfiguration,

start,

loadConfigFromFile,
format,

Expand All @@ -19,8 +25,7 @@ import { join } from "path";
const desktopTargets = ['desktop','electron', 'tauri']
const mobileTargets = ['mobile', 'android', 'ios']
const webTargets = ['web', 'pwa']
const serviceTargets = ['services']
const allTargets = [...serviceTargets, ...desktopTargets, ...mobileTargets, ...webTargets]
const allTargets = [...desktopTargets, ...mobileTargets, ...webTargets]

const reconcile = (userOpts = {}, cliOpts = {}, envOpts = {}) => Object.assign({}, envOpts, userOpts, cliOpts) // CLI —> User —> Environment

Expand Down Expand Up @@ -57,48 +62,42 @@ cli.command('launch [root]', 'Launch your build application in the specified dir

.action(async (root, options) => {

const { config: configPath, service, ...overrides } = options

const services = service
const isOnlyServices = (!overrides.target && services)
const { config: configPath, service, host, port, ...overrides } = options

await preprocessTarget(overrides.target)

const config = await loadConfigFromFile(getConfigPathFromOpts({ root, config: configPath }))

if (!config) return


// Services take priority if specified
const isOnlyServices = (!overrides.target && service)
if (isOnlyServices) {

delete config.target

// Do not use configuration options for servers
delete config.port
delete config.host

// NOTE: If passed, this simply wouldn't take effect
if (options.outDir) return await failed(`Cannot specify an output directory when launching services`)

const resolvedServices = typeof services === 'string' ? [services] : services

// If specified, this simply wouldn't take effect
if (Object.keys(resolvedServices).length > 1 && (options.port || options.host)) return await failed(`Cannot specify port or host when launching multiple services`)

// Flag invalid services
for (const service of resolvedServices) {
if (!config.services[service]) await failed(`Service '${service}' not found in configuration`)
const resolvedServices = typeof service === 'string' ? [ service ] : service
const nServices = Object.keys(resolvedServices).length
if (nServices > 1 && (port || host)) return await failed(`Cannot specify port or host when launching multiple services`)
if (nServices === 1) {
const serviceName = resolvedServices[0]
if (serviceName in config.services) {
const service = resolveServiceConfiguration(config.services[serviceName])
Object.assign(service, { host, port }) // Set host and port on single service
config.services[serviceName] = service
}
}

// Clear unspecified services
Object.keys(config.services).forEach(service => {
if (!resolvedServices.includes(service)) delete config.services[service]
})

const launchConfig = reconcile(config, overrides) as LaunchConfig
return await launchServices(launchConfig, { services: service })
}

// Ensure services are not specified with a target
else if (services) return await failed(`Cannot specify services without a target`)
else if (service) return await failed(`Cannot specify both services and a launch target`)

const launchConfig = reconcile(config, overrides) as LaunchConfig
launch(launchConfig, isOnlyServices)
Expand All @@ -117,20 +116,19 @@ cli.command('build [root]', 'Build the application in the specified directory',
const { config: configPath, service, ...overrides } = options
const { target } = overrides

const buildOnlyServices = !target && service
await preprocessTarget(target)


const config = await loadConfigFromFile(getConfigPathFromOpts({
root,
config: configPath
}))

if (!config) return

if (!target && service) return await buildServices(config, { services: service }) // Only build services

if (buildOnlyServices) delete config.target // Ensure services are built only

build(reconcile(config, overrides), { servicesToBuild: service })
build(reconcile(config, overrides))
})

// Start the application in development mode
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "commoners",
"description": "Cross-Platform Development for the Rest of Us",
"version": "0.0.54",
"version": "0.0.55",
"type": "module",
"license": "MIT",
"engines": {
Expand All @@ -18,7 +18,7 @@
"watch": "vite build --watch"
},
"dependencies": {
"@commoners/solidarity": "0.0.54",
"@commoners/solidarity": "0.0.55",
"cac": "^6.7.14"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/assets/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ runAppPlugins().then(() => {
app.whenReady().then(async () => {

// ------------------------ Service Creation ------------------------
const { active } = await services.createAll(config.services, {
const { services: active } = await services.createAll(config.services, {
target: 'desktop',
build: isProduction,
root: isProduction ? __dirname : join(__dirname, '..', '..'), // Back out of default outDir
Expand Down
Binary file modified packages/core/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 7 additions & 16 deletions packages/core/assets/onload.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import { asyncFilter, pluginErrorMessage, sanitizePluginProperties } from "./utils";
import { asyncFilter, isPluginSupported, pluginErrorMessage, sanitizePluginProperties } from "./utils";

const TEMP_COMMONERS = globalThis.__commoners ?? {}

// Set global variable
const ENV = commoners
const { __PLUGINS, DESKTOP, MOBILE, __READY } = ENV
delete ENV.__PLUGINS

const TARGET = DESKTOP ? 'desktop' : MOBILE ? 'mobile' : 'web'

if (DESKTOP) {
Object.assign(DESKTOP, {
quit: TEMP_COMMONERS.quit,
...TEMP_COMMONERS.args
})
}

if ( __PLUGINS ) {

const loaded = {}

asyncFilter(Object.entries(__PLUGINS), async ([id, plugin]) => {
asyncFilter(Object.entries(__PLUGINS), async ([ id, plugin ]) => {
try {
let { isSupported } = plugin

if (isSupported && typeof isSupported === 'object') isSupported = isSupported[TARGET]
if (typeof isSupported?.check === 'function') isSupported = isSupported.check

return (typeof isSupported === 'function') ? await isSupported.call(plugin, TARGET) : isSupported !== false
} catch {
return await isPluginSupported(plugin, TARGET)
} catch (e) {
return false
}
}).then(supported => {
Expand All @@ -42,6 +31,7 @@ if ( __PLUGINS ) {
loaded[id] = undefined // Register that all supported plugins are technically loaded

try {

if (load) {
const ctx = DESKTOP ? {
...DESKTOP,
Expand All @@ -54,6 +44,7 @@ if ( __PLUGINS ) {

loaded[id] = load.call(ctx, ENV)
}

} catch (e) {
pluginErrorMessage(id, "load", e)
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/assets/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const isValidURL = (s) => {
let processes = {}

export const resolveServiceConfiguration = (config) => {
if (typeof config === 'string') config = isValidURL(config) ? { url: config } : { src: config }
if (typeof config === 'string') return isValidURL(config) ? { url: config } : { src: config }
return config
}

Expand Down Expand Up @@ -319,7 +319,7 @@ export async function start(config, id, opts = {}) {

const resolvedFilepath = resolve((isExecutable(ext) && !ext && existsSync(filepath + '.exe')) ? filepath + '.exe' : filepath)

if (!existsSync(resolvedFilepath)) return await printServiceMessage(label, `Source file does not exist at ${resolvedFilepath}`, 'warn')
if (!existsSync(resolvedFilepath)) return await printServiceMessage(label, `File does not exist at ${resolvedFilepath}`, 'warn')

// Node Support
if (jsExtensions.includes(ext)) childProcess = fork(resolvedFilepath, [], { cwd, silent: true, env })
Expand Down Expand Up @@ -447,12 +447,12 @@ export async function resolveAll(servicesToResolve = {}, opts) {

export async function createAll(services = {}, opts) {

const instances = await resolveAll(services, opts)
const resolved = await resolveAll(services, opts)

await Promise.all(Object.entries(instances).map(([id, config]) => start(config, id, opts))) // Run sidecars automatically based on the configuration file
await Promise.all(Object.entries(resolved).map(([id, config]) => start(config, id, opts))) // Run sidecars automatically based on the configuration file

return {
active: instances,
services: resolved,
close
}
}
31 changes: 17 additions & 14 deletions packages/core/assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ export const asyncFilter = async (arr, predicate) => Promise.all(arr.map(predica
export const pluginErrorMessage = (name, type, e) => console.error(`[commoners] ${name} plugin (${type}) failed to execute:`, e)


const removablePluginProperties = [ 'load' ]
export const isPluginSupported = async (plugin, target) => {

const isDesktopBuild = target === 'desktop'

let { isSupported, desktop } = plugin
if (isSupported && typeof isSupported === 'object') isSupported = isSupported[target]
if (typeof isSupported === 'function') isSupported = await isSupported.call(plugin, target)
if (isSupported === false) return // Explicit removal

if (desktop) {
if (isDesktopBuild) return true
else return !!isSupported // Must be explicitly truthy
}

return isSupported !== false // Should just not be false
}

export const sanitizePluginProperties = (plugin, target) => {
const copy = {...plugin}
const copy = { ...plugin }

// Remove electron plugins if not the correct target
const assumeRemoval = 'desktop' in copy && target !== 'desktop'
if (assumeRemoval) delete copy.desktop

// Assume true if no desktop configuration; assume false if desktop configuration
const willRemove = (v) => assumeRemoval ? !v : v === false

// Remove any top-level properties that are flagged as unsupported
const isSupported = copy.isSupported?.[target] ?? copy.isSupported // Drill to the target

if (isSupported && typeof isSupported === 'object') {
removablePluginProperties.forEach(prop => {
if (willRemove(isSupported[prop])) delete copy[prop]
})
}

return copy
}
Loading

0 comments on commit f4eae2e

Please sign in to comment.