@spideythedev/simple-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/simplejs ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { run } from '../src/index.js'
4
+
5
+ run(process.argv.slice(2))
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@spideythedev/simple-js",
3
+ "version": "0.1.0",
4
+ "description": "JavaScript, gentle. Compiles to standard JS. 1 month to learn.",
5
+ "type": "module",
6
+ "bin": {
7
+ "simple-js": "./bin/simplejs"
8
+ },
9
+ "keywords": [
10
+ "javascript",
11
+ "compiler",
12
+ "simple",
13
+ "language",
14
+ "learn"
15
+ ],
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/spideythedev/Simple.js"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ }
24
+ }
package/src/build.js ADDED
@@ -0,0 +1,18 @@
1
+ import { compile } from '@simplejs/compiler'
2
+ import { readFileSync, writeFileSync, existsSync } from 'fs'
3
+ import { resolve } from 'path'
4
+
5
+ export function build(input, output) {
6
+ const inputPath = resolve(input)
7
+ const outputPath = output ? resolve(output) : inputPath.replace('.sjs', '.js')
8
+
9
+ if (!existsSync(inputPath)) {
10
+ console.error(`File not found: ${input}`)
11
+ process.exit(1)
12
+ }
13
+
14
+ const source = readFileSync(inputPath, 'utf8')
15
+ const js = compile(source)
16
+ writeFileSync(outputPath, js, 'utf8')
17
+ console.log(`Compiled: ${input} → ${outputPath}`)
18
+ }
package/src/index.js ADDED
@@ -0,0 +1,35 @@
1
+ import { build } from './build.js'
2
+ import { watchFile } from './watch.js'
3
+ import { init } from './init.js'
4
+
5
+ export function run(args) {
6
+ const command = args[0]
7
+
8
+ if (!command) {
9
+ console.log('Simple.js — JavaScript, gentle.')
10
+ console.log('')
11
+ console.log('Commands:')
12
+ console.log(' init <name> Create a new project')
13
+ console.log(' build <input> Compile .sjs to .js')
14
+ console.log(' watch <input> Watch and recompile')
15
+ console.log('')
16
+ console.log('Example:')
17
+ console.log(' simplejs init my-app')
18
+ console.log(' simplejs build app.sjs')
19
+ return
20
+ }
21
+
22
+ switch (command) {
23
+ case 'build':
24
+ build(args[1], args[2])
25
+ break
26
+ case 'watch':
27
+ watchFile(args[1], args[2])
28
+ break
29
+ case 'init':
30
+ init(args[1])
31
+ break
32
+ default:
33
+ console.log(`Unknown command: ${command}`)
34
+ }
35
+ }
package/src/init.js ADDED
@@ -0,0 +1,24 @@
1
+ import { writeFileSync, mkdirSync, existsSync } from 'fs'
2
+ import { resolve } from 'path'
3
+
4
+ export function init(name) {
5
+ const projectPath = resolve(name || 'simplejs-app')
6
+
7
+ if (existsSync(projectPath)) {
8
+ console.error(`Directory already exists: ${name}`)
9
+ process.exit(1)
10
+ }
11
+
12
+ mkdirSync(projectPath, { recursive: true })
13
+
14
+ const appContent = `name = "World"
15
+ greet() { "Hello " + name }
16
+ log@console(greet())
17
+ `
18
+
19
+ writeFileSync(resolve(projectPath, 'app.sjs'), appContent, 'utf8')
20
+
21
+ console.log(`Project created: ${name}`)
22
+ console.log(` cd ${name}`)
23
+ console.log(` simplejs build app.sjs`)
24
+ }
package/src/watch.js ADDED
@@ -0,0 +1,19 @@
1
+ import { watch } from 'fs'
2
+ import { resolve, extname } from 'path'
3
+ import { build } from './build.js'
4
+
5
+ export function watchFile(input, output) {
6
+ const inputPath = resolve(input)
7
+ const outputPath = output ? resolve(output) : inputPath.replace('.sjs', '.js')
8
+
9
+ console.log(`Watching: ${input}`)
10
+
11
+ build(input, output)
12
+
13
+ watch(inputPath, (eventType) => {
14
+ if (eventType === 'change') {
15
+ console.log(`File changed, recompiling...`)
16
+ build(input, output)
17
+ }
18
+ })
19
+ }