Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/raw/
/dist/
/.bynix-build-*/
/node_modules/
*.js
!js/*.js
/.trash/
*.tgz
*.tgz
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ npm install -g bynixscript
### Using NPM <a name="using-npm-get-started"></a>
Run a BynixScript file:
```
bsr path/to/script.bs
bynix run path/to/script.bys
```
Compile a BynixScript file:
```
bst path/to/script.bs
bynix compile path/to/script.bys
```
To print a BynixScript file to console:
The compiled JavaScript is written next to the source file (`script.js`, or `script.mjs` for `.mbs`).
To print translated JavaScript without running it:
```
bsp path/to/script.bs
bynix print path/to/script.bys
```
To delete a file
To delete a file (an explicit file path is required):
```
bsd path/to/script.bs
bynix delete path/to/script.bys
```
Run `bynix --help` or `bynix run --help` for usage. The default supported extensions are `.bys`, `.bynixscript`, and `.mbs`.

To build the packaged executable from source while developing:
```
npm ci
npm run build
npm test
```
### Using CDN <a name="using-cdn-get-started"></a>
```html
Expand Down
61 changes: 15 additions & 46 deletions docs/markdown/command.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,16 @@
# Command
BynixScript has commands that can help you use BynixScript more easily.
1. **Execution command**
- **bsr command**:
This command is used to run BynixScript without compiling first:
```
bsr path/to/script.bs
```
- **bst command**:
This command is used to compile the BynixScript file:
```
bst path/to/script.bs
```
- **bsp command**:
This command is used to print the results of the translation of the BynixScript code to the cli:
```
bsp path/to/script.bs
```
- **bsd command**:
This command is used to delete files:
```
bsd path/to/script.bs
```
2. **Help command**
- **Display help**:
If you want to see help, you can write:
```
bynixscript --help

# or shorter
bs -h
```
- **Display version**:
If you want to see the current version of BynixScript you are using, you can see it with the command:
```
bynixscript --version

# or shorter
bs -v
```
- **Display download**:
```
bynixscript --download [--day, --week, --month]

# or shorter
bs -d [-d, -w, -m]
```

After `npm install -g bynixscript`, use the installed `bynix` executable:

| Command | Action |
| --- | --- |
| `bynix run path/to/script.bys` | Translate and run a BynixScript file. |
| `bynix compile path/to/script.bys` | Write translated JavaScript beside the source file (`.js`, or `.mjs` for `.mbs`). Does not run the file. |
| `bynix print path/to/script.bys` | Print translated JavaScript without running the file. |
| `bynix delete path/to/script.bys` | Delete the specified file. A path is always required. |

By default, input files use `.bys`, `.bynixscript`, or `.mbs`. Paths are relative to the current directory, or may be absolute. Invalid paths and unsupported extensions produce an error and a nonzero exit status.

Use `bynix --help` for all commands, `bynix <command> --help` for command-specific help, and `bynix --version` for the version. The earlier option forms `bynix -r <file>`, `bynix -c <file>`, `bynix -p <file>`, and `bynix -d <file>` remain available.

For development, run `npm ci` followed by `npm run build` to produce `dist/index.min.cjs`. `npm test` builds it and runs the CLI tests.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"browser": "js/browser.js",
"main": "./index.js",
"scripts": {
"test": "node index.js"
"build": "node scripts/build.cjs",
"prepack": "npm run build",
"test": "npm run build && node --test tests/*.test.cjs"
},
"alias": {
"test": "npm run test"
Expand Down
52 changes: 52 additions & 0 deletions scripts/build.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const fs = require('node:fs')
const path = require('node:path')
const { build } = require('esbuild')
const { parseCode, addSemicolons } = require('../js/parser.js')
const { funcReplace } = require('bynixscript/dist/parser/funcDecl.js')

const root = path.resolve(__dirname, '..')
const temporary = fs.mkdtempSync(path.join(root, '.bynix-build-'))
const source = path.join(root, 'src')
const output = path.join(root, 'dist', 'index.min.cjs')

function translateParser(sourceCode) {
return funcReplace(addSemicolons(parseCode(sourceCode))).replace(/\.change\(/g, '.replace(')
}

async function main() {
try {
for (const name of fs.readdirSync(source, { withFileTypes: true })) {
if (name.isFile() && name.name.endsWith('.bs')) {
fs.writeFileSync(path.join(temporary, name.name.replace(/\.bs$/, '.js')),
fs.readFileSync(path.join(source, name.name), 'utf8'))
}
}

const parserOutput = path.join(temporary, 'parser')
fs.mkdirSync(parserOutput)
for (const name of fs.readdirSync(path.join(source, 'parser'))) {
if (name.endsWith('.bs')) {
const code = fs.readFileSync(path.join(source, 'parser', name), 'utf8')
fs.writeFileSync(path.join(parserOutput, name.replace(/\.bs$/, '.js')), translateParser(code))
}
}

await build({
entryPoints: [path.join(temporary, 'index.js')],
outfile: output,
platform: 'node',
format: 'cjs',
bundle: true,
minify: true,
target: 'node20'
})
fs.chmodSync(output, 0o755)
} finally {
fs.rmSync(temporary, { recursive: true, force: true })
}
}

main().catch(error => {
console.error(error)
process.exitCode = 1
})
24 changes: 8 additions & 16 deletions src/bsd.bs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const { defaultConfig, config, readFolder, extensions } = require('../js/bsc.js')
const fs = require('node:fs')
const { resolveFile } = require('./translate.js')

func bsdCommand(locate):
const directory = str(readFolder)
const fileFrom = path.join(directory, locate)

handle:
fs.unlinkSync(fileFrom)
print("Successfully deleted " + locate + " file")
recovery (err):
print("Error:", err.message)
end
end
function bsdCommand(file) {
const filePath = resolveFile(file)
fs.unlinkSync(filePath)
console.log(`Deleted ${file}`)
}

module.exports = { bsdCommand }
module.exports = { bsdCommand }
73 changes: 6 additions & 67 deletions src/bsp.bs
Original file line number Diff line number Diff line change
@@ -1,69 +1,8 @@
#!/usr/bin/env node
const fs = require('fs')
const vm = require('vm')
const path = require('path')
const { extensions, toFolder, readFolder, translate } = require('../js/bsc.js')
const { parsing, parsingMsg, parseCode, addSemicolons } = require('../js/parser.js')
const { funcReplace, condReplace, forEachReplace, reassignReplace, assignReplace, logReplace, interactReplace, mathReplace, domReplace, commentReplace, utilityReplace, asyncReplace, flowReplace, forReplace, convReplace, checkReplace, oopReplace, excepReplace, expReplace, otherReplace } = require('./parser/parsingDecl.js')
const { stackParsing } = require('../js/error.js')
const { readSource, translate } = require('./translate.js')

const sandbox = {
console: {
log: () => {}
},
require: require,
process: process
};
function bspCommand(file) {
const { source } = readSource(file)
console.log(translate(source))
}

func bspCommand(locate):
const directory = str(readFolder)
var fileFrom = path.join(directory, locate)

var code
handle:
var box = fs.readFileSync(fileFrom, 'utf-8')
if locate.is_end(extensions.primary) || locate.is_end(extensions.secondary) || locate.is_end(extensions.module):
code = parseCode(box)
code = addSemicolons(code)
const parsingResults = parsing(code)

if parsingResults === false:
print("Error:", parsingMsg.message)
else:
code = flowReplace(code)
code = utilityReplace(code)
code = funcReplace(code)
code = condReplace(code)
code = forEachReplace(code)
code = reassignReplace(code)
code = assignReplace(code)
code = logReplace(code)
code = interactReplace(code)
code = mathReplace(code)
code = commentReplace(code)
code = asyncReplace(code)
code = forReplace(code)
code = convReplace(code)
code = checkReplace(code)
code = oopReplace(code)
code = excepReplace(code)
code = domReplace(code)

vm.runInNewContext(code, sandbox);
print(code)
end
else:
print(`Error: Unsupported file extension. Please use a ${extensions.primary}, ${extensions.secondary}, or ${extensions.module} file.`)
end
recovery (err):
const msg = err.message
if msg.is_includes('module'):
print(code)
else:
const stackMsg = err.stack
print(stackParsing(locate, err.message, stackMsg, box, err.name, fileFrom))
end
end
end

module.exports = { bspCommand }
module.exports = { bspCommand }
78 changes: 13 additions & 65 deletions src/bsr.bs
Original file line number Diff line number Diff line change
@@ -1,67 +1,15 @@
#!/usr/bin/env node
const fs = require('fs')
const vm = require('vm')
const path = require('path')
const { defaultConfig, config, readFolder, extensions } = require('../js/bsc.js')
const { parsing, parsingMsg, parseCode, addSemicolons } = require('../js/parser.js')
const { funcReplace, condReplace, forEachReplace, reassignReplace, assignReplace, logReplace, interactReplace, mathReplace, domReplace, commentReplace, utilityReplace, asyncReplace, flowReplace, forReplace, convReplace, checkReplace, oopReplace, excepReplace, expReplace, otherReplace } = require('./parser/parsingDecl.js')
const { stackParsing } = require('../js/error.js')
const vm = require('node:vm')
const { createRequire } = require('node:module')
const { readSource, translate } = require('./translate.js')

func bsrCommand(locate):
print(locate)
const directory = str(readFolder)
var fileFrom = path.join(directory, locate)

const sandbox = {
require: require,
console: console,
process: process,
}

var code
handle:
var box = fs.readFileSync(fileFrom, 'utf-8')
if locate.is_end(extensions.primary) || locate.is_end(extensions.secondary) || locate.is_end(extensions.module):
code = parseCode(box)
code = addSemicolons(code)
var parsingResults = parsing(code)

if parsingResults === false:
print("Error:", parsingMsg.message)
else:
code = flowReplace(code)
code = utilityReplace(code)
code = funcReplace(code)
code = condReplace(code)
code = forEachReplace(code)
code = reassignReplace(code)
code = assignReplace(code)
code = logReplace(code)
code = interactReplace(code)
code = mathReplace(code)
code = commentReplace(code)
code = asyncReplace(code)
code = forReplace(code)
code = convReplace(code)
code = checkReplace(code)
code = oopReplace(code)
code = excepReplace(code)
code = domReplace(code)

vm.runInNewContext(code, sandbox, { filename: locate});
end
else:
print(`Error: Unsupported file extension. Please use a ${extensions.primary}, ${extensions.secondary}, or ${extensions.module} file.`)
end
recovery (err):
const msg = err.message
if msg.is_includes('module'):
print("Sorry, you cannot using module right now.")
else:
const stackMsg = err.stack
print(stackParsing(locate, err.message, stackMsg, box, err.name, fileFrom))
end
end
end
function bsrCommand(file) {
const { source, filePath } = readSource(file)
const code = translate(source)
vm.runInNewContext(code, {
console,
process,
require: createRequire(filePath)
}, { filename: filePath })
}

module.exports = { bsrCommand };
module.exports = { bsrCommand }
Loading
Loading