Skip to content

Commit

Permalink
add pkg-json translater (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
FineArchs authored Jan 4, 2024
1 parent bb89d13 commit 75c4c20
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/.vscode
/coverage
/temp
/src/pkg.ts
/src/parser/parser.js
/src/parser/parser.mjs
npm-debug.log
Expand Down
3 changes: 3 additions & 0 deletions etc/aiscript.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type AddAssign_2 = NodeBase_2 & {
expr: Expression_2;
};

// @public (undocumented)
export const AISCRIPT_VERSION: "0.17.0";

// @public (undocumented)
abstract class AiScriptError extends Error {
constructor(message: string, info?: any);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ts": "npm run ts-esm && npm run ts-dts",
"ts-esm": "tsc --outDir built/esm",
"ts-dts": "tsc --outDir built/dts --declaration true --emitDeclarationOnly true --declarationMap true",
"build": "npm run peg && npm run ts",
"build": "node scripts/gen-pkg-ts.mjs && npm run peg && npm run ts",
"build-debug": "npm run peg-debug && tsc",
"api": "npx api-extractor run --local --verbose",
"api-prod": "npx api-extractor run --verbose",
Expand Down
4 changes: 2 additions & 2 deletions playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div id="root">
<h1>AiScript (v{{ std['Core:v'].value }}) Playground</h1>
<h1>AiScript (v{{ AISCRIPT_VERSION }}) Playground</h1>
<div id="grid1">
<div id="editor" class="container">
<header>Input<div class="actions"><button @click="setCode">FizzBuzz</button></div></header>
Expand Down Expand Up @@ -42,7 +42,7 @@

<script setup>
import { ref, watch } from 'vue';
import { Interpreter, Parser, utils } from '@syuilo/aiscript';
import { AISCRIPT_VERSION, Interpreter, Parser, utils } from '@syuilo/aiscript';
import { std } from '@syuilo/aiscript/interpreter/lib/std';
import { PrismEditor } from 'vue-prism-editor';
Expand Down
15 changes: 15 additions & 0 deletions scripts/gen-pkg-ts.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { writeFile } from 'node:fs/promises';
import pkg from '../package.json' assert { type: 'json' };

await writeFile('./src/pkg.ts',
`/*
This file is automatically generated by scripts/gen-pkg-ts.js.
DO NOT edit this file. To change it's behavior, edit scripts/gen-pkg-ts.js instead.
*/
/* eslint-disable quotes */
/* eslint-disable comma-dangle */
export const pkg = ${ JSON.stringify({
version: pkg.version,
}, undefined, '\t')} as const;
`
);
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { pkg } from './pkg.js';
export const AISCRIPT_VERSION = pkg.version;
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Parser, ParserPlugin, PluginType } from './parser/index.js';
import * as Cst from './parser/node.js';
import * as errors from './error.js';
import * as Ast from './node.js';
import { AISCRIPT_VERSION } from './constants.js';
export { Interpreter };
export { Scope };
export { utils };
Expand All @@ -20,3 +21,4 @@ export { PluginType };
export { Cst };
export { errors };
export { Ast };
export { AISCRIPT_VERSION };
3 changes: 2 additions & 1 deletion src/interpreter/lib/std.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import seedrandom from 'seedrandom';
import { NUM, STR, FN_NATIVE, FALSE, TRUE, ARR, NULL, BOOL, OBJ, ERROR } from '../value.js';
import { assertNumber, assertString, assertBoolean, valToJs, jsToVal, assertFunction, assertObject, eq, expectAny, assertArray, reprValue } from '../util.js';
import { AiScriptRuntimeError } from '../../error.js';
import { AISCRIPT_VERSION } from '../../constants.js';
import { textDecoder } from '../../const.js';
import type { Value } from '../value.js';

export const std: Record<string, Value> = {
'help': STR('SEE: https://github.com/syuilo/aiscript/blob/master/docs/get-started.md'),

//#region Core
'Core:v': STR('0.16.0'), // TODO: package.jsonを参照
'Core:v': STR(AISCRIPT_VERSION),

'Core:ai': STR('kawaii'),

Expand Down

0 comments on commit 75c4c20

Please sign in to comment.