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

feat: add create package for simpler project init #235

Merged
merged 23 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1543a6a
feat: checkpoint work on new create package
chrispcampbell Sep 19, 2022
a801e83
feat: add template-default using sources from sir example project
chrispcampbell Sep 19, 2022
bb6c5e6
fix: copy template files without overwriting existing files
chrispcampbell Sep 21, 2022
e0f6a1b
fix: allow user to choose mdl if there are multiple
chrispcampbell Sep 21, 2022
012ca85
feat: add support for installing Emscripten SDK
chrispcampbell Sep 21, 2022
34c36ce
refactor: split index file into separate modules, one per step
chrispcampbell Sep 21, 2022
cd7d9a3
test: rename test to match source name
chrispcampbell Sep 21, 2022
4e75726
fix: use exit code 0 since tool is interactive and exit code is less …
chrispcampbell Sep 21, 2022
321a0c2
fix: handle errors in install deps step
chrispcampbell Sep 21, 2022
43b4247
refactor: make --dry-run handling consistent
chrispcampbell Sep 21, 2022
ad9bc62
fix: remove accidental exit
chrispcampbell Sep 21, 2022
ab9cd71
fix: add workspaces to template-default package.json
chrispcampbell Sep 21, 2022
331bf9f
fix: change colors in template-default
chrispcampbell Sep 21, 2022
7a1cd26
fix: change model name placeholders in template-default
chrispcampbell Sep 21, 2022
5b61fab
feat: add support for generating graphs.csv and inputs.csv
chrispcampbell Sep 21, 2022
2cdea13
fix: update model.csv using initial/final time values from mdl
chrispcampbell Sep 21, 2022
5cca7bc
fix: write pnpm-workspace.yaml if pnpm is detected
chrispcampbell Sep 22, 2022
68010a4
fix: allow for overriding commit/branch on command line
chrispcampbell Sep 22, 2022
008ed5c
fix: add a sample mdl file if none found
chrispcampbell Sep 22, 2022
dae3e17
fix: simplify ora calls
chrispcampbell Sep 22, 2022
a0de607
feat: add minimal template
chrispcampbell Sep 22, 2022
1112275
fix: generate sample .check.yaml file and include check-core as depen…
chrispcampbell Sep 22, 2022
4a94ff6
fix: remove incorrectly copied CHANGELOG
chrispcampbell Sep 22, 2022
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
41 changes: 41 additions & 0 deletions examples/sir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# sir

This example directory contains the class SIR (Susceptible-Infectious-Recovered) model of
infectious disease.
It is intended to demonstrate the use of the `@sdeverywhere/create` package to quickly
set up a new project that uses the provided config files to generate a simple web application.

## Quick Start

The quickest way to get started using the `sir` example project is to copy
it into a separate directory (outside of the `SDEverywhere` working copy).
This will allow you to install the `@sdeverywhere/*` packages using your
package manager of choice (npm, yarn, or pnpm).

```sh
# Change to the parent of your SDEverywhere working copy
cd <parentdir>

# Copy the example to a separate directory
cp -rf SDEverywhere/examples/sir .

# Change to the copied directory
cd ./sir

# Create a new project (you can also use yarn or pnpm here, if preferred).
# Be sure to choose the "Default" template, which will make use of the
# existing files in the `config` directory.
npm create @sdeverywhere

# Enter development mode for the sample model. This will start a live
# development environment that will build a WebAssembly version of the
# sample model and run checks on it any time you make changes to:
# - the config files
# - the Vensim model file (sir.mdl)
# - the checks file (sir.check.yaml)
npm run dev
```

## License

SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
4 changes: 4 additions & 0 deletions examples/template-default/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sde-prep
*.vdf
*.vdfx
*.3vmfx
39 changes: 39 additions & 0 deletions examples/template-default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# template-default

This is a template that is used by the `@sdeverywhere/create` package to generate a
new project that uses SDEverywhere.

The project includes:

- a build process that converts a Vensim model to a WebAssembly module that
can run the model in any web browser or in a Node.js application
- a `config` directory that contains CSV files for configuring the generated
model and application
- a "core" package that provides a clean JavaScript / TypeScript API around the
WebAssembly model
- an "app" package containing a simple JavaScript / jQuery-based web application
that can be used to exercise the model
- a local development mode (`npm run dev`) that allows for rapid prototyping
of the model and app
- a "model-check" setup that allows for running checks and comparison tests using
the generated model

## Quick Start

```sh
# Create a new project (you can also use yarn or pnpm here, if preferred).
# Be sure to choose the "Default" template.
npm create @sdeverywhere

# Enter development mode for your model. This will start a live
# development environment that will build a WebAssembly version of the
# model and run checks on it any time you make changes to:
# - the config files
# - the Vensim model file (<name>.mdl)
# - the checks file (<name>.check.yaml)
npm run dev
```

## License

SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
6 changes: 6 additions & 0 deletions examples/template-default/config/colors.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id,hex code,name,comment
blue,#0072b2,,
red,#d33700,,
green,#53bb37,,
gray,#a7a9ac,,
black,#000000,,
1 change: 1 addition & 0 deletions examples/template-default/config/graphs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id,side,parent menu,graph title,menu title,mini title,vensim graph,kind,modes,units,alternate,unused 1,unused 2,unused 3,x axis min,x axis max,x axis label,unused 4,unused 5,y axis min,y axis max,y axis soft max,y axis label,y axis format,unused 6,unused 7,plot 1 variable,plot 1 source,plot 1 style,plot 1 label,plot 1 color,plot 1 unused 1,plot 1 unused 2,plot 2 variable,plot 2 source,plot 2 style,plot 2 label,plot 2 color,plot 2 unused 1,plot 2 unused 2,plot 3 variable,plot 3 source,plot 3 style,plot 3 label,plot 3 color,plot 3 unused 1,plot 3 unused 2,plot 4 variable,plot 4 source,plot 4 style,plot 4 label,plot 4 color,plot 4 unused 1,plot 4 unused 2,plot 5 variable,plot 5 source,plot 5 style,plot 5 label,plot 5 color,plot 5 unused 1,plot 5 unused 2,plot 6 variable,plot 6 source,plot 6 style,plot 6 label,plot 6 color,plot 6 unused 1,plot 6 unused 2,plot 7 variable,plot 7 source,plot 7 style,plot 7 label,plot 7 color,plot 7 unused 1,plot 7 unused 2,plot 8 variable,plot 8 source,plot 8 style,plot 8 label,plot 8 color,plot 8 unused 1,plot 8 unused 2,plot 9 variable,plot 9 source,plot 9 style,plot 9 label,plot 9 color,plot 9 unused 1,plot 9 unused 2,plot 10 variable,plot 10 source,plot 10 style,plot 10 label,plot 10 color,plot 10 unused 1,plot 10 unused 2,plot 11 variable,plot 11 source,plot 11 style,plot 11 label,plot 11 color,plot 11 unused 1,plot 11 unused 2,plot 12 variable,plot 12 source,plot 12 style,plot 12 label,plot 12 color,plot 12 unused 1,plot 12 unused 2,plot 13 variable,plot 13 source,plot 13 style,plot 13 label,plot 13 color,plot 13 unused 1,plot 13 unused 2,plot 14 variable,plot 14 source,plot 14 style,plot 14 label,plot 14 color,plot 14 unused 1,plot 14 unused 2,plot 15 variable,plot 15 source,plot 15 style,plot 15 label,plot 15 color,plot 15 unused 1,plot 15 unused 2
1 change: 1 addition & 0 deletions examples/template-default/config/inputs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id,input type,viewid,varname,label,view level,group name,slider min,slider max,slider/switch default,slider step,units,format,reversed,range 2 start,range 3 start,range 4 start,range 5 start,range 1 label,range 2 label,range 3 label,range 4 label,range 5 label,enabled value,disabled value,controlled input ids,listing label,description
2 changes: 2 additions & 0 deletions examples/template-default/config/model.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
model start time,model end time,graph default min time,graph default max time,model dat files
0,100,0,100,
1 change: 1 addition & 0 deletions examples/template-default/config/outputs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
variable name
2 changes: 2 additions & 0 deletions examples/template-default/config/strings.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,string
__model_name,My Model
24 changes: 24 additions & 0 deletions examples/template-default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "project",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "sde bundle",
"dev": "sde dev",
"start": "sde dev"
},
"workspaces": [
"packages/core",
"packages/app"
],
"dependencies": {
"@sdeverywhere/check-core": "^0.1.0",
"@sdeverywhere/cli": "^0.7.0",
"@sdeverywhere/plugin-check": "^0.1.0",
"@sdeverywhere/plugin-config": "^0.1.0",
"@sdeverywhere/plugin-vite": "^0.1.1",
"@sdeverywhere/plugin-wasm": "^0.1.0",
"@sdeverywhere/plugin-worker": "^0.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sir-app",
"name": "app",
"version": "1.0.0",
"private": true,
"type": "module",
Expand All @@ -15,8 +15,7 @@
"dependencies": {
"bootstrap-slider": "10.6.2",
"chart.js": "^2.9.4",
"jquery": "^3.5.1",
"sir-core": "^1.0.0"
"jquery": "^3.5.1"
},
"devDependencies": {
"@types/chart.js": "^2.9.34",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Configure path aliases
"paths": {
// The following lines enable path aliases within the app
"@core": ["../sir-core/src"],
"@core-strings": ["../sir-core/strings"],
"@core": ["../core/src"],
"@core-strings": ["../core/strings"],
"@prep/*": ["../../sde-prep/*"]
},
// XXX: The following two lines work around a TS/VSCode issue where this config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default defineConfig(env => {

resolve: {
alias: {
'@core': resolve(appDir, '..', 'sir-core', 'src'),
'@core-strings': resolve(appDir, '..', 'sir-core', 'strings'),
'@core': resolve(appDir, '..', 'core', 'src'),
'@core-strings': resolve(appDir, '..', 'core', 'strings'),
'@prep': resolve(projDir, 'sde-prep')
}
},
Expand All @@ -57,8 +57,8 @@ export default defineConfig(env => {
},

server: {
// Run the dev server at `localhost:8091` by default
port: 8091,
// Run the dev server at `localhost:8080` by default
port: 8080,

// Open the app in the browser by default
open: '/index.html'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sir-core",
"name": "core",
"version": "1.0.0",
"private": true,
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import { vitePlugin } from '@sdeverywhere/plugin-vite'
import { wasmPlugin } from '@sdeverywhere/plugin-wasm'
import { workerPlugin } from '@sdeverywhere/plugin-worker'

const baseName = 'sir'
const __dirname = dirname(fileURLToPath(import.meta.url))
const configDir = joinPath(__dirname, 'config')
const packagePath = (...parts) => joinPath(__dirname, 'packages', ...parts)
const appPath = (...parts) => packagePath(`${baseName}-app`, ...parts)
const corePath = (...parts) => packagePath(`${baseName}-core`, ...parts)
const appPath = (...parts) => packagePath('app', ...parts)
const corePath = (...parts) => packagePath('core', ...parts)

export async function config() {
return {
// Specify the Vensim model to read
modelFiles: ['model/sir.mdl'],
modelFiles: ['MODEL_NAME.mdl'],

// The following files will be hashed to determine whether the model needs
// to be rebuilt when watch mode is active
modelInputPaths: ['model/*.mdl'],
modelInputPaths: ['MODEL_NAME.mdl'],

// The following files will cause the model to be rebuilt when watch mode is
// is active. Note that these are globs so we use forward slashes regardless
// of platform.
watchPaths: ['config/**', 'model/*.mdl'],
watchPaths: ['config/**', 'MODEL_NAME.mdl'],

// Read csv files from `config` directory
modelSpec: configProcessor({
Expand All @@ -48,7 +47,7 @@ export async function config() {

// Build or serve the model explorer app
vitePlugin({
name: `${baseName}-app`,
name: 'app',
apply: {
development: 'serve'
},
Expand Down
1 change: 1 addition & 0 deletions examples/template-minimal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sde-prep
34 changes: 34 additions & 0 deletions examples/template-minimal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# template-minimal

This is a template that is used by the `@sdeverywhere/create` package to generate a
new project that uses SDEverywhere.

The generated project is more minimal than the "default" template, but may be
useful if you don't want to generate a library or app around your model and
if you are more interested in just running the "model-check" tool.

Note that unlike the "default" template, this template does not use config files
(e.g., CSV files read from the `config` directory), so you can edit the
`sde.config.js` file to configure the input and output variables.

(If you decide later to use config files, refer to `template-default` to see how
to add the `@sdeverywhere/plugin-config` package to your project.)

## Quick Start

```sh
# Create a new project (you can also use yarn or pnpm here, if preferred).
# Be sure to choose the "Minimal" template.
npm create @sdeverywhere

# Enter development mode for your model. This will start a live
# development environment that will build a WebAssembly version of the
# model and run checks on it any time you make changes to:
# - the Vensim model file (<name>.mdl)
# - the checks file (<name>.check.yaml)
npm run dev
```

## License

SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sir",
"name": "project",
"version": "1.0.0",
"private": true,
"type": "module",
Expand All @@ -8,10 +8,9 @@
"dev": "sde dev"
},
"dependencies": {
"@sdeverywhere/check-core": "^0.1.0",
"@sdeverywhere/cli": "^0.7.0",
"@sdeverywhere/plugin-check": "^0.1.0",
"@sdeverywhere/plugin-config": "^0.1.0",
"@sdeverywhere/plugin-vite": "^0.1.1",
"@sdeverywhere/plugin-wasm": "^0.1.0",
"@sdeverywhere/plugin-worker": "^0.1.0"
}
Expand Down
42 changes: 42 additions & 0 deletions examples/template-minimal/sde.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { checkPlugin } from '@sdeverywhere/plugin-check'
import { wasmPlugin } from '@sdeverywhere/plugin-wasm'
import { workerPlugin } from '@sdeverywhere/plugin-worker'

export async function config() {
return {
modelFiles: ['MODEL_NAME.mdl'],

modelSpec: async () => {
return {
// TODO: Change these values as desired (usually they will be the same as
// the `INITIAL TIME` and `FINAL TIME` values from the mdl, but you can
// use different values here)
startTime: 2000,
endTime: 2100,
inputs: [
// TODO: List your input variables here
{ varName: 'Y', defaultValue: 0, minValue: -10, maxValue: 10 }
],
outputs: [
// TODO: List your output variables here
{ varName: 'Z' }
],
datFiles: [
// TODO: If your mdl refers to vdfx files, list dat files here (first
// convert vdfx to dat, since SDEverywhere only supports dat format)
]
}
},

plugins: [
// Generate a `wasm-model.js` file containing the Wasm model
wasmPlugin(),

// Generate a `worker.js` file that runs the Wasm model in a worker
workerPlugin(),

// Run model check
checkPlugin()
]
}
}
1 change: 1 addition & 0 deletions packages/create/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
3 changes: 3 additions & 0 deletions packages/create/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['../../.eslintrc-ts-common.cjs']
}
2 changes: 2 additions & 0 deletions packages/create/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
tests/fixtures/empty-dir
1 change: 1 addition & 0 deletions packages/create/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
1 change: 1 addition & 0 deletions packages/create/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
21 changes: 21 additions & 0 deletions packages/create/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2022 Climate Interactive / New Venture Fund

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions packages/create/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# @sdeverywhere/create

Create a new SDEverywhere project with minimal configuration.

## Quick Start

```sh
# with npm
npm create @sdeverywhere

# with pnpm
pnpm create @sdeverywhere

# with yarn
yarn create @sdeverywhere
```

## License

SDEverywhere is distributed under the MIT license. See `LICENSE` for more details.
14 changes: 14 additions & 0 deletions packages/create/bin/create-sde.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
'use strict'

const currentVersion = process.versions.node
const requiredMajorVersion = parseInt(currentVersion.split('.')[0], 10)
const minimumMajorVersion = 14

if (requiredMajorVersion < minimumMajorVersion) {
console.error(`Node.js v${currentVersion} is not supported by SDEverywhere.`)
console.error(`Please use Node.js v${minimumMajorVersion} or higher.`)
process.exit(1)
}

import('../dist/index.js').then(({ main }) => main())
Loading