Skip to content

Commit

Permalink
remove provider and config.yml support
Browse files Browse the repository at this point in the history
  • Loading branch information
smellman committed Sep 2, 2024
1 parent 609afb8 commit ed52654
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 223 deletions.
6 changes: 0 additions & 6 deletions docs/source/usage/commandline_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ Build `style.json` from `style.yml`
-u, --sprite-url [<sprite url>] url to set as the sprite in style.json
-i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon source> is `icons/`
-o, --sprite-output [<icon output directory>] directory path to output icon files. The default <icons destination> is the current directory
--provider [provider] your map service. e.g. `geolonia`
-h, --help display help for command
Realtime editor on browser
Expand All @@ -92,7 +91,6 @@ Realtime editor on browser
serve your map locally
Options:
--provider [provider] your map service. e.g. `geolonia`
-i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon
source> is `icons/`
--sdf Allows to use SDF sprite in charites
Expand All @@ -101,10 +99,6 @@ Realtime editor on browser
Charites has three options for `serve` command.
- ``--provider`` - `geolonia`, or `default`. When not specified, default or the value in the configuration file will be used.
- `geolonia` and `default` - the format linter runs against the MapLibre GL JS compatible specification.
- ``--sprite-input`` - If you are building icon spritesheets with Charites, you can specify the directory of SVG files to compile here. See the ``build`` command for more information.
- ``--sdf`` - if this option is used together with ``--sprite-input``, the viewer will generate SDF sprite. If the option is not specified, non SDF sprite will be generated.
Expand Down
19 changes: 0 additions & 19 deletions docs/source/usage/global_options.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/source/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Usage
:maxdepth: 1

commandline_interface
global_options
examples
example2
7 changes: 1 addition & 6 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@ const config: PlaywrightTestConfig = {
browserName: 'chromium',
headless: true,
},
workers: 3,
workers: 1,
webServer: [
{
command: 'dist/cli.js serve test/data/style.yml --port 8080',
port: 8080,
},
{
command:
'dist/cli.js serve test/data/style.yml --provider geolonia --port 8088',
port: 8088,
},
],
}
export default config
File renamed without changes.
30 changes: 30 additions & 0 deletions provider/default/shared.js → provider/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,34 @@
}
},
}

const { style, center, zoom } = await window._charites.parseMapStyle()
const options = {
container: 'map',
hash: true,
maxPitch: 85,
style,
}
if (center) options.center = center
if (zoom) options.zoom = zoom
const map = new maplibregl.Map(options)

window._charites.initializeWebSocket(map)

map.addControl(new maplibregl.NavigationControl(), 'top-right')

map.addControl(
new MaplibreLegendControl.MaplibreLegendControl(
{},
{
showDefault: true,
showCheckbox: true,
onlyRendered: true,
reverseOrder: true,
},
),
'bottom-left',
)

window._charites.setupDebugCheckboxes(map)
})()
31 changes: 0 additions & 31 deletions provider/default/app.js

This file was deleted.

28 changes: 0 additions & 28 deletions provider/geolonia/app.js

This file was deleted.

22 changes: 0 additions & 22 deletions provider/geolonia/index.html

This file was deleted.

File renamed without changes.
10 changes: 0 additions & 10 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Command } from 'commander'
import { build, buildOptions, buildWatch } from '../commands/build.js'
import { error } from '../lib/error.js'
import { defaultSettings } from '../lib/defaultValues.js'
import fs from 'fs'
import path from 'path'

Expand All @@ -24,11 +23,9 @@ program
'-o, --sprite-output [<icon output directory>]',
'directory path to output icon files. The default <icons destination> is the current directory',
)
.option('--provider [provider]', 'your map service. e.g. `geolonia`')
.action(
async (source: string, destination: string, buildOptions: buildOptions) => {
const options = program.opts()
options.provider = buildOptions.provider
options.compactOutput = buildOptions.compactOutput
options.spriteUrl = buildOptions.spriteUrl
options.spriteOutput = buildOptions.spriteOutput || process.cwd()
Expand All @@ -41,13 +38,6 @@ program
options.spriteInput = spriteInputDefault
}

if (!fs.existsSync(defaultSettings.configFile)) {
fs.writeFileSync(
defaultSettings.configFile,
`provider: ${options.provider || 'default'}`,
)
}

if (buildOptions.watch) {
try {
console.log('Start watching...')
Expand Down
10 changes: 0 additions & 10 deletions src/cli/serve.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { Command } from 'commander'
import { serve, serveOptions } from '../commands/serve.js'
import { error } from '../lib/error.js'
import { defaultSettings } from '../lib/defaultValues.js'
import fs from 'fs'

const program = new Command()
program
.name('serve')
.arguments('<source>')
.description('serve your map locally')
.option('--provider [provider]', 'your map service. e.g. `geolonia`')
.option(
'-i, --sprite-input [<icon input directory>]',
'directory path of icon source to build icons. The default <icon source> is `icons/`',
Expand All @@ -19,17 +16,10 @@ program
.option('--no-open', "Don't open the preview in the default browser")
.action(async (source: string, serveOptions: serveOptions) => {
const options: serveOptions = program.opts()
options.provider = serveOptions.provider
options.port = serveOptions.port
options.spriteInput = serveOptions.spriteInput
options.open = serveOptions.open
options.sdf = serveOptions.sdf
if (!fs.existsSync(defaultSettings.configFile)) {
fs.writeFileSync(
defaultSettings.configFile,
`provider: ${options.provider || 'default'}`,
)
}
try {
await serve(source, program.opts())
} catch (e) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
import watch from 'node-watch'

export interface buildOptions {
provider?: string
compactOutput?: boolean
watch?: boolean
spriteUrl?: string
Expand Down
36 changes: 5 additions & 31 deletions src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import watch from 'node-watch'

import { parser } from '../lib/yaml-parser.js'
import { validateStyle } from '../lib/validate-style.js'
import { defaultValues } from '../lib/defaultValues.js'
import { providerDir } from '../lib/defaultValues.js'
import { buildSprite } from '../lib/build-sprite.js'

export interface serveOptions {
provider?: string
port?: string
spriteInput?: string
open?: boolean
Expand All @@ -26,11 +25,6 @@ export async function serve(source: string, options: serveOptions) {
}
let sourcePath = path.resolve(process.cwd(), source)

let provider = defaultValues.provider
if (options.provider) {
provider = options.provider
}

// The `source` is absolute path.
if (source.match(/^\//)) {
sourcePath = source
Expand Down Expand Up @@ -58,8 +52,6 @@ export async function serve(source: string, options: serveOptions) {

const server = http.createServer(async (req, res) => {
const url = (req.url || '').replace(/\?.*/, '')
const defaultProviderDir = path.join(defaultValues.providerDir, 'default')
const providerDir = path.join(defaultValues.providerDir, provider)

if (
typeof spriteOut !== 'undefined' &&
Expand Down Expand Up @@ -109,32 +101,15 @@ export async function serve(source: string, options: serveOptions) {
case '/app.css':
res.statusCode = 200
res.setHeader('Content-Type', 'text/css; charset=UTF-8')
const css = fs.readFileSync(
path.join(defaultProviderDir, 'app.css'),
'utf-8',
)
const css = fs.readFileSync(path.join(providerDir, 'app.css'), 'utf-8')
res.end(css)
break
case `/shared.js`:
res.statusCode = 200
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
const shared = fs.readFileSync(
path.join(defaultProviderDir, 'shared.js'),
'utf-8',
)
const js = shared.replace('___PORT___', `${port}`)
res.end(js)
break
case `/app.js`:
res.statusCode = 200
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
try {
const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
const js = app.replace('___PORT___', `${port}`)
res.end(js)
} catch (_) {
throw `Invalid provider: ${provider}`
}
const app = fs.readFileSync(path.join(providerDir, 'app.js'), 'utf-8')
const js = app.replace('___PORT___', `${port}`)
res.end(js)
break
default:
res.statusCode = 404
Expand All @@ -145,7 +120,6 @@ export async function serve(source: string, options: serveOptions) {
})

server.listen(port, () => {
console.log(`Provider: ${provider}`)
console.log(`Loading your style: ${sourcePath}`)
console.log(`Your map is running on http://localhost:${port}/\n`)
if (options.open) {
Expand Down
37 changes: 4 additions & 33 deletions src/lib/defaultValues.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
import { fileURLToPath } from 'url'
import { dirname } from 'path'
import path from 'path'
import os from 'os'
import fs from 'fs'
import YAML from 'js-yaml'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

interface Config {
provider: string
providerDir: string
}

const homedir = os.homedir()
const defaultProvider = 'default'

const configDir = path.join(homedir, '.charites')
fs.mkdirSync(configDir, { recursive: true })

const configFile = path.join(configDir, 'config.yml')
let config: Config = { provider: '', providerDir: '' }

try {
const yaml = fs.readFileSync(configFile, 'utf-8')
config = YAML.load(yaml) as Config
} catch (_) {
// nothing to do
}

export const defaultValues: Config = {
provider: config.provider || defaultProvider,
providerDir: path.join(path.dirname(path.dirname(__dirname)), 'provider'),
}

export const defaultSettings = {
configFile: configFile,
}
export const providerDir = path.join(
path.dirname(path.dirname(__dirname)),
'provider',
)
Loading

0 comments on commit ed52654

Please sign in to comment.