diff --git a/.travis.yml b/.travis.yml index bc37bc4..a64880c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,6 @@ os: - windows - linux - osx -env: YARN_GPG=no \ No newline at end of file +env: YARN_GPG=no + +script: yarn test:ci \ No newline at end of file diff --git a/docs/banner.png b/docs/banner.png new file mode 100644 index 0000000..243a54e Binary files /dev/null and b/docs/banner.png differ diff --git a/syntax.md b/docs/syntax.md similarity index 65% rename from syntax.md rename to docs/syntax.md index 5296765..52c393b 100644 --- a/syntax.md +++ b/docs/syntax.md @@ -6,6 +6,7 @@ - [Directives](#directives) - [keepalive directive](#keepalive-directive) - [singleton directive](#singleton-directive) + - [static directive](#static-directive) - [functions](#functions) - [restore](#restore) - [Links](#links) @@ -13,7 +14,7 @@ ## Basic System Structure -A Vogue system is a database of interlinked instances and their persistent data. Two things are required to start: A group (usually a directory) of vogue modules that a system knows, and a database to load from or create (usually in the form of a single file). +A Vogue system is a database of interlinked instances and their persistent data. Only one thing is required to start a vogue system: The list of modules to be included in the system. At the initial creation of a Vogue system, if there is no database to load from, any template module with the [singleton directive](#singleton-directive) will have an instance created of itself, without any predefined parameters. @@ -21,6 +22,8 @@ When a database is loaded, all instances who's template module has the [keepaliv ## Keepalive Directive +`WARNING: the keepalive directive is not fully implemented. You may include it in your module files, however their existence in memory is not yet guaranteed.` + The keepalive directive is used to describe that a module should always remain in memory. This directive applies only to instances. This means that if no instances exist of a particular template module with the keepalive directive, then no instances will be restored. ```vogue @@ -37,9 +40,27 @@ The singleton directive implies the keepalive directive. singleton; ``` +## Static Directive + +The static directive is like the singleton directive, except it makes the created instance available to all other instances in the system. These can be thought of as global variables. For example, `console` in vogue refers to the static instance (as a [link](#links)) of the console module. + +The identifier after the static keyword is the name that is globally injected. + +``` +static util; + +foo { + console.log('I can be called from anywhere!'); +} + +restore { + util.foo(); +} +``` + ## Functions -functions can be referred to in other functions with or without the `this.` prefix. Use the prefix to disambiguate if local variables exist with the same identifier. +Functions are declared with an identifier, parameters (optional) and a javascript code block. ```vogue functionName (param1, param2) { diff --git a/package.json b/package.json index 6289719..4cf8a39 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "vogue-runtime", "version": "0.2.0", - "main": "index.js", + "main": "out/run.js", "license": "MIT", "type": "module", + "types": "./out/run.d.ts", "bin": { "vogue": "out/run.js" }, @@ -18,7 +19,9 @@ "debug:watch": "supervisor -t -w out,test/system/**/*.v,lib -n exit --exec yarn -- debug", "compile": "tsc", "compile:watch": "yarn compile --watch --preserveWatchOutput", - "postinstall": "yarn compile && cd examples/test && yarn" + "postinstall": "yarn compile && cd examples/test && yarn", + "test:ci": "yarn test && codecov", + "prepublish": "yarn compile" }, "devDependencies": { "@types/chai": "^4.2.18", @@ -35,6 +38,7 @@ "c8": "^7.7.2", "chai": "^4.3.4", "chai-as-promised": "^7.1.1", + "codecov": "^3.8.2", "cross-env": "^7.0.3", "mocha": "^8.4.0", "mocha-lcov-reporter": "^1.3.0", diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..86b720a --- /dev/null +++ b/readme.md @@ -0,0 +1,57 @@ +![](/docs/banner.png) +![Travis (.com)](https://img.shields.io/travis/com/marcus13345/vogue) +![Codecov](https://img.shields.io/codecov/c/github/marcus13345/vogue) +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarcus13345%2Fvogue.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarcus13345%2Fvogue?ref=badge_shield) +![npm bundle size](https://img.shields.io/bundlephobia/minzip/vogue) +[![NPM](https://nodei.co/npm/vogue-runtime.png?downloads=true&downloadRank=true)](https://nodei.co/npm/vogue-runtime/) + +Vogue is a programming language that leverages javascript to create no-config graph systems. + +# Getting Started + +To create a vogue system, create a vogue module file in a new folder: +`example/main.v` +``` +singleton; + +restore { + console.log('Hellow Vogue!'); +} +``` +then run your system with `vogue example`. + +# NPM Integration + +your vogue system folder may have a `package.json` and a `node_modules` folder. If they do, you can import javascript modules into your vogue module. + +``` +example +|-- package.json +|-- main.v +`-- node_modules + `-- package + |-- package.json + `-- index.js +``` +``` +singleton; + +import package from 'package'; + +restore { + console.log(package.foo()); +} +``` + +# Persistence + +Vogue systems automagically persist their data, unless otherwise specified. This data is stored inside the `.system` directory. + +# Documentation + +For the full spec of vogue module syntax, see: [syntax](docs/syntax.md). + +To see some common examples and programming patterns, see [examples](examples). + +# License +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmarcus13345%2Fvogue.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmarcus13345%2Fvogue?ref=badge_shield) \ No newline at end of file diff --git a/src/System.ts b/src/System.ts index 82911ea..68f4be0 100644 --- a/src/System.ts +++ b/src/System.ts @@ -2,7 +2,7 @@ import Instance, { Link, SerializedInstance } from './Instance.js'; import _ from 'lodash'; import Module from './Module.js'; import debug from 'debug'; -import { lstatSync, readdirSync, readFileSync, writeFileSync } from 'fs'; +import { readdirSync, readFileSync, writeFileSync } from 'fs'; import { resolve } from 'path'; import { ensureDirSync } from 'fs-extra'; import * as uuid from 'uuid'; diff --git a/yarn.lock b/yarn.lock index df18114..212e6d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -50,6 +50,10 @@ version "0.7.1" resolved "https://registry.yarnpkg.com/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz#8da5c6530915653f3a1f38fd5f101d8c3f8079c5" +"@tootallnate/once@1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" + "@types/chai-as-promised@^7.1.4": version "7.1.4" resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.4.tgz#caf64e76fb056b8c8ced4b761ed499272b737601" @@ -157,6 +161,12 @@ version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" +agent-base@6: + version "6.0.2" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-6.0.2.tgz#49fff58577cfee3f37176feab4c22e00f86d7f77" + dependencies: + debug "4" + ansi-colors@4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" @@ -194,10 +204,20 @@ arg@^4.1.0: version "4.1.3" resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089" +argparse@^1.0.7: + version "1.0.10" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911" + dependencies: + sprintf-js "~1.0.2" + argparse@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" +argv@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab" + assertion-error@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" @@ -310,6 +330,16 @@ clone@^1.0.2: version "1.0.4" resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" +codecov@^3.8.2: + version "3.8.2" + resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.8.2.tgz#ab24f18783998c39e809ea210af899f8dbcc790e" + dependencies: + argv "0.0.2" + ignore-walk "3.0.3" + js-yaml "3.14.1" + teeny-request "7.0.1" + urlgrey "0.4.4" + color-convert@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" @@ -373,7 +403,7 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.1: shebang-command "^2.0.0" which "^2.0.1" -debug@4.3.1, debug@^4.3.1: +debug@4, debug@4.3.1, debug@^4.3.1: version "4.3.1" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee" dependencies: @@ -423,6 +453,10 @@ escape-string-regexp@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34" +esprima@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" + event-transmitter@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/event-transmitter/-/event-transmitter-2.0.0.tgz#7d58aeb72abb47c1e7eab0d7bf78033c0de33493" @@ -533,6 +567,27 @@ html-escaper@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" +http-proxy-agent@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" + dependencies: + "@tootallnate/once" "1" + agent-base "6" + debug "4" + +https-proxy-agent@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2" + dependencies: + agent-base "6" + debug "4" + +ignore-walk@3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.3.tgz#017e2447184bfeade7c238e4aefdd1e8f95b1e37" + dependencies: + minimatch "^3.0.4" + inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -624,6 +679,13 @@ jest-get-type@^26.3.0: version "26.3.0" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0" +js-yaml@3.14.1: + version "3.14.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537" + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + js-yaml@4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.0.0.tgz#f426bc0ff4b4051926cd588c71113183409a121f" @@ -767,6 +829,10 @@ nise@^4.1.0: just-extend "^4.0.2" path-to-regexp "^1.7.0" +node-fetch@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" @@ -967,6 +1033,16 @@ split@~0.3.2: dependencies: through "2" +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + +stream-events@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/stream-events/-/stream-events-1.0.5.tgz#bbc898ec4df33a4902d892333d47da9bf1c406d5" + dependencies: + stubs "^3.0.0" + "string-width@^1.0.2 || 2": version "2.1.1" resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" @@ -1015,6 +1091,10 @@ strip-json-comments@3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006" +stubs@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/stubs/-/stubs-3.0.0.tgz#e8d2ba1fa9c90570303c030b6900f7d5f89abe5b" + subarg@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/subarg/-/subarg-1.0.0.tgz#f62cf17581e996b48fc965699f54c06ae268b8d2" @@ -1037,6 +1117,16 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +teeny-request@7.0.1: + version "7.0.1" + resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-7.0.1.tgz#bdd41fdffea5f8fbc0d29392cb47bec4f66b2b4c" + dependencies: + http-proxy-agent "^4.0.0" + https-proxy-agent "^5.0.0" + node-fetch "^2.6.1" + stream-events "^1.0.5" + uuid "^8.0.0" + test-exclude@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-6.0.0.tgz#04a8698661d805ea6fa293b6cb9e63ac044ef15e" @@ -1098,11 +1188,15 @@ unparse-args@1.0.1, unparse-args@~1.0.1: dependencies: shell-escape "~0.1.0" +urlgrey@0.4.4: + version "0.4.4" + resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f" + util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" -uuid@^8.3.2: +uuid@^8.0.0, uuid@^8.3.2: version "8.3.2" resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"