lilact 0.0.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/Icon/r +0 -0
- package/LICENSE.TXT +26 -0
- package/README.md +116 -0
- package/bin/copy-demo.js +26 -0
- package/bin/transpile-dir.js +112 -0
- package/bin/transpile.js +137 -0
- package/dist/lilact.development.js +9344 -0
- package/dist/lilact.development.js.map +1 -0
- package/dist/lilact.production.min.js +63 -0
- package/dist/lilact.production.min.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +71 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/accessories.ErrorBoundary.html +37 -0
- package/docs/classes/accessories.Suspense.html +41 -0
- package/docs/classes/components.Component.html +45 -0
- package/docs/classes/components.HTMLComponent.html +32 -0
- package/docs/classes/components.RootComponent.html +32 -0
- package/docs/classes/transition.Transition.html +31 -0
- package/docs/functions/accessories.Spinner.html +9 -0
- package/docs/functions/components.createComponent.html +8 -0
- package/docs/functions/components.createRoot.html +5 -0
- package/docs/functions/components.render.html +5 -0
- package/docs/functions/hooks.createContext.html +3 -0
- package/docs/functions/hooks.useActionState.html +3 -0
- package/docs/functions/hooks.useCallback.html +5 -0
- package/docs/functions/hooks.useContext.html +3 -0
- package/docs/functions/hooks.useDeferredValue.html +4 -0
- package/docs/functions/hooks.useEffect.html +3 -0
- package/docs/functions/hooks.useHook.html +5 -0
- package/docs/functions/hooks.useId.html +4 -0
- package/docs/functions/hooks.useLayoutEffect.html +3 -0
- package/docs/functions/hooks.useLocalStorage.html +4 -0
- package/docs/functions/hooks.useMemo.html +4 -0
- package/docs/functions/hooks.useReducer.html +6 -0
- package/docs/functions/hooks.useRef.html +4 -0
- package/docs/functions/hooks.useState.html +3 -0
- package/docs/functions/hooks.useTransition.html +3 -0
- package/docs/functions/jsx.transpileJSX.html +6 -0
- package/docs/functions/misc.Fragment.html +3 -0
- package/docs/functions/misc.classNames.html +2 -0
- package/docs/functions/misc.deepEqual.html +3 -0
- package/docs/functions/misc.findDOMNode.html +3 -0
- package/docs/functions/misc.getComponentByPointer.html +3 -0
- package/docs/functions/misc.isAsync.html +3 -0
- package/docs/functions/misc.isClass.html +3 -0
- package/docs/functions/misc.isEmpty.html +3 -0
- package/docs/functions/misc.isError.html +3 -0
- package/docs/functions/misc.isThenable.html +3 -0
- package/docs/functions/misc.isValidElement.html +3 -0
- package/docs/functions/misc.shallowEqual.html +3 -0
- package/docs/functions/redux.Provider.html +5 -0
- package/docs/functions/redux.connect.html +5 -0
- package/docs/functions/redux.useDispatch.html +3 -0
- package/docs/functions/redux.useSelector.html +5 -0
- package/docs/functions/redux.useStore.html +3 -0
- package/docs/functions/router.HashRouter.html +5 -0
- package/docs/functions/router.Link.html +12 -0
- package/docs/functions/router.NavLink.html +10 -0
- package/docs/functions/router.Route.html +6 -0
- package/docs/functions/router.Routes.html +4 -0
- package/docs/functions/router.useLocation.html +3 -0
- package/docs/functions/router.useNavigate.html +3 -0
- package/docs/functions/run.require.html +14 -0
- package/docs/functions/run.run.html +13 -0
- package/docs/functions/run.runScripts.html +7 -0
- package/docs/functions/run.traceError.html +6 -0
- package/docs/functions/timers.animationFramePromise.html +3 -0
- package/docs/functions/timers.clearInterval.html +2 -0
- package/docs/functions/timers.clearTimeout.html +2 -0
- package/docs/functions/timers.grabTimers.html +3 -0
- package/docs/functions/timers.pauseTimers.html +2 -0
- package/docs/functions/timers.releaseTimers.html +2 -0
- package/docs/functions/timers.resetTimers.html +2 -0
- package/docs/functions/timers.resumeTimers.html +2 -0
- package/docs/functions/timers.setInterval.html +5 -0
- package/docs/functions/timers.setTimeout.html +4 -0
- package/docs/functions/timers.timeoutPromise.html +4 -0
- package/docs/functions/transition.CSSTransition.html +18 -0
- package/docs/functions/transition.TransitionGroup.html +5 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +88 -0
- package/docs/media/icon.png +0 -0
- package/docs/modules/accessories.html +1 -0
- package/docs/modules/components.html +1 -0
- package/docs/modules/hooks.html +1 -0
- package/docs/modules/jsx.html +1 -0
- package/docs/modules/misc.html +1 -0
- package/docs/modules/redux.html +1 -0
- package/docs/modules/router.html +1 -0
- package/docs/modules/run.html +1 -0
- package/docs/modules/timers.html +1 -0
- package/docs/modules/transition.html +1 -0
- package/docs/modules.html +1 -0
- package/docs/static/demos/actionstate.jsx +41 -0
- package/docs/static/demos/boundary.jsx +52 -0
- package/docs/static/demos/context.jsx +68 -0
- package/docs/static/demos/css-transition.jsx +65 -0
- package/docs/static/demos/modal.jsx +41 -0
- package/docs/static/demos/proptypes.jsx +37 -0
- package/docs/static/demos/reducer.jsx +71 -0
- package/docs/static/demos/redux.jsx +58 -0
- package/docs/static/demos/router.jsx +153 -0
- package/docs/static/demos/stopwatch.jsx +42 -0
- package/docs/static/demos/suspense.jsx +48 -0
- package/docs/static/demos/transition.jsx +40 -0
- package/docs/static/demos/use-differed.jsx +30 -0
- package/docs/static/demos/usetransition.jsx +37 -0
- package/docs/static/index.html +212 -0
- package/docs/static/lilact.development.js +9344 -0
- package/docs/static/lilact.production.min.js +63 -0
- package/docs/static/prismjs/LICENSE.md +21 -0
- package/docs/static/prismjs/prism-jsx.min.js +1 -0
- package/docs/static/prismjs/prism.min.css +1 -0
- package/docs/static/prismjs/prism.min.js +16 -0
- package/docs/variables/jsx.transpilerConfig.html +1 -0
- package/docs/variables/misc.Children.html +10 -0
- package/icon.png +0 -0
- package/package.json +39 -0
- package/root/demos/actionstate.jsx +41 -0
- package/root/demos/boundary.jsx +52 -0
- package/root/demos/context.jsx +68 -0
- package/root/demos/css-transition.jsx +65 -0
- package/root/demos/modal.jsx +41 -0
- package/root/demos/proptypes.jsx +37 -0
- package/root/demos/reducer.jsx +71 -0
- package/root/demos/redux.jsx +58 -0
- package/root/demos/router.jsx +153 -0
- package/root/demos/stopwatch.jsx +42 -0
- package/root/demos/suspense.jsx +48 -0
- package/root/demos/transition.jsx +40 -0
- package/root/demos/use-differed.jsx +30 -0
- package/root/demos/usetransition.jsx +37 -0
- package/root/index.html +212 -0
- package/root/lilact.development.js +9344 -0
- package/root/lilact.production.min.js +63 -0
- package/root/prismjs/LICENSE.md +21 -0
- package/root/prismjs/prism-jsx.min.js +1 -0
- package/root/prismjs/prism.min.css +1 -0
- package/root/prismjs/prism.min.js +16 -0
- package/src/accessories.jsx +287 -0
- package/src/components.jsx +1063 -0
- package/src/events.jsx +175 -0
- package/src/hooks.jsx +461 -0
- package/src/jsx.addons.js +70 -0
- package/src/jsx.js +1168 -0
- package/src/lilact.jsx +115 -0
- package/src/loader.cjs +59 -0
- package/src/misc.jsx +419 -0
- package/src/redux.jsx +198 -0
- package/src/router.jsx +282 -0
- package/src/run.jsx +275 -0
- package/src/timers.jsx +313 -0
- package/src/transition.jsx +244 -0
- package/src/vlq.js +94 -0
- package/tsconfig.json +15 -0
- package/typedoc.json +23 -0
- package/webpack.config.js +196 -0
package/Icon/r
ADDED
|
File without changes
|
package/LICENSE.TXT
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
Lilact
|
|
3
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
BSD-2-Clause
|
|
7
|
+
|
|
8
|
+
Redistribution and use in source and binary forms, with or without
|
|
9
|
+
modification, are permitted provided that the following conditions are met:
|
|
10
|
+
|
|
11
|
+
* Redistributions of source code must retain the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
|
13
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
documentation and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
20
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
21
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
22
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
23
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
24
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<img src="./icon.png" alt="Description" width="200" style="margin-left: -.75rem"/>
|
|
2
|
+
|
|
3
|
+
# Lilact
|
|
4
|
+
|
|
5
|
+
### A Little JSX/React Runtime Implementation for Browser
|
|
6
|
+
|
|
7
|
+
`Lilact` is an extremely lightweight implementation of the React API that is
|
|
8
|
+
designed to work in the browser. It can be used as a single script
|
|
9
|
+
that is around `70kb` minified and around `25kb` gzipped and includes everything.
|
|
10
|
+
`Lilact` is very fast, it uses minimum resources and handles memory very efficiently.
|
|
11
|
+
|
|
12
|
+
`Lilact` uses its own robust JSX transpiler, and not babel. It is a recursive-descent
|
|
13
|
+
parser with lookahead, but it doesn't parse the JS syntax completely and relies on the
|
|
14
|
+
JS runtime to detect some errors. The transpiler weights
|
|
15
|
+
only a few kilobytes and can be even incorporated into other React engines. To
|
|
16
|
+
make it better, it even generates sourcemaps like a charm, without relying on
|
|
17
|
+
any 3rd party library. There is a `transpile.js` helper in the bin directory to
|
|
18
|
+
show how you can use it.
|
|
19
|
+
|
|
20
|
+
`Lilact` implements both the **legacy class based** and **modern hook based** APIs. And it
|
|
21
|
+
has almost everything necessary. In addition to the API, it also includes the official
|
|
22
|
+
`Redux` and `PropTypes` libraries to be used (see the `redux.jsx` and `proptypes.jsx` demos).
|
|
23
|
+
So yes it has redux support and has many of the functions and hooks, i.e. `connect` and
|
|
24
|
+
`useDispatch`.
|
|
25
|
+
|
|
26
|
+
It also includes the amazing `@emotion/css` library to ease working with styles.
|
|
27
|
+
It can be accessed through `Lilact.emotion`.
|
|
28
|
+
|
|
29
|
+
To ease working, it already includes a `HashRouter`, `CSSTransition`, `ErrorBoundary`,
|
|
30
|
+
`Suspense`, `Spinner`, and many other stuff. It also has a specific timeout implementation
|
|
31
|
+
that can be paused and resumed at will. `Lilact`'s `Suspense` even has a few more features
|
|
32
|
+
than the standard API.
|
|
33
|
+
|
|
34
|
+
You can see all the methods available in the documentation. And there is a list of
|
|
35
|
+
demos that can all be seen alongside their code at [Lilact Demo Examples](./static/index.html).
|
|
36
|
+
Just note that the modules are separated in the documentation to improve the doc
|
|
37
|
+
structure, and in practice all the methods and members are accessible via the `Lilact` object
|
|
38
|
+
itself directly.
|
|
39
|
+
|
|
40
|
+
`Lilact` runs in the browser, so it uses `eval` to run the transpiled scripts, and cannot
|
|
41
|
+
use import and exports the same as a module. So you should import the functions using the following
|
|
42
|
+
convention
|
|
43
|
+
|
|
44
|
+
const { useState, useRef, render } = Lilact;
|
|
45
|
+
|
|
46
|
+
And to export you can use `module.exports = ...`.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
To use in other node projects, install `Lilact` from npm public repository:
|
|
52
|
+
|
|
53
|
+
npm install lilact
|
|
54
|
+
|
|
55
|
+
It is also available via unpkg CDN and can be included in HTML files using
|
|
56
|
+
|
|
57
|
+
<script src="https://unpkg.com/lilact/dist/lilact.development.js"></script>
|
|
58
|
+
|
|
59
|
+
or
|
|
60
|
+
|
|
61
|
+
<script src="https://unpkg.com/lilact/dist/lilact.production.min.js"></script>
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
To use in a webpage, first download the source code and extract it. The minified
|
|
65
|
+
script itself is available in the `/dist` directory and the documentation
|
|
66
|
+
can be found in the `/docs` and also in the source files.
|
|
67
|
+
|
|
68
|
+
Note that the production version, like the official React API, doesn't do the proptypes
|
|
69
|
+
checks, but you can access PropTypes using Lilact.PropTypes.
|
|
70
|
+
|
|
71
|
+
After being loaded, Lilact automatically scans the document for any scirpt elements
|
|
72
|
+
with `type='text/jsx'` and it will run them. If the `src` attribute is set it will load
|
|
73
|
+
the resource, and if there is inner content it will be executed. Of course this is not the
|
|
74
|
+
only way.
|
|
75
|
+
|
|
76
|
+
Lilact wraps the browser events to mimic React events, this mimicry is not perfect, as
|
|
77
|
+
the footprint was very important, but it works fine.
|
|
78
|
+
|
|
79
|
+
As a simple example Lilact can be used like this:
|
|
80
|
+
|
|
81
|
+
<!DOCTYPE html>
|
|
82
|
+
<html>
|
|
83
|
+
<head>
|
|
84
|
+
<meta charset="utf-8"/>
|
|
85
|
+
<title>Lilact Demo</title>
|
|
86
|
+
<script src='./lilact.development.js' type="module"></script>
|
|
87
|
+
</head>
|
|
88
|
+
<body></body>
|
|
89
|
+
<script type='text/jsx'>
|
|
90
|
+
|
|
91
|
+
const { render, useState } = Lilact;
|
|
92
|
+
function App({children}) {
|
|
93
|
+
[...]
|
|
94
|
+
return <div>Hello World</div>!
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
render(<App/>, document.body);
|
|
98
|
+
</script>
|
|
99
|
+
</html>
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
To know more about using `Lilact`, see the included example and for the details
|
|
103
|
+
see the class documentation. And of course don't forget to check the
|
|
104
|
+
[Lilact Demo Examples](./static/index.html).
|
|
105
|
+
|
|
106
|
+
`Lilact` is currently in its beta state. It is under heavy tests and improvements are
|
|
107
|
+
being made. Please report any possible issues or bugs, they will be fixed
|
|
108
|
+
without any hesitation!
|
|
109
|
+
|
|
110
|
+
--------
|
|
111
|
+
|
|
112
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>. All rights reserved.
|
|
113
|
+
|
|
114
|
+
Lilact project is subject to the terms of BSD-2-Clause License. See the `LICENSE.TXT` file for more details.
|
|
115
|
+
|
|
116
|
+
<style>.tsd-page-title{display: none}</style>
|
package/bin/copy-demo.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function copyDirRecursive(src, dest) {
|
|
12
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
13
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
14
|
+
const s = path.join(src, entry.name);
|
|
15
|
+
const d = path.join(dest, entry.name);
|
|
16
|
+
if (entry.isDirectory()) copyDirRecursive(s, d);
|
|
17
|
+
else fs.copyFileSync(s, d);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const typedocOut = process.env.TYPEDOC_OUT || 'docs';
|
|
22
|
+
const from = path.resolve(__dirname, '..', 'root');
|
|
23
|
+
const to = path.resolve(__dirname, '..', typedocOut, 'static');
|
|
24
|
+
|
|
25
|
+
copyDirRecursive(from, to);
|
|
26
|
+
console.log(`Copied ${from} -> ${to}`);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
import { spawnSync } from "child_process";
|
|
9
|
+
|
|
10
|
+
function usage() {
|
|
11
|
+
console.error(
|
|
12
|
+
"Usage:\n" +
|
|
13
|
+
" transpile-dir <inDir> --outDir <outDir> [Options]\n\n" +
|
|
14
|
+
"Options:\n" +
|
|
15
|
+
" --inDir <dir> Input directory for transpiled files (required)\n\n" +
|
|
16
|
+
" --outDir <dir> Output directory for transpiled files (required)\n\n" +
|
|
17
|
+
" --isDebug Add debug labels \n" +
|
|
18
|
+
" --discardComments Discard comments \n" +
|
|
19
|
+
" --injectTraceLabels Inject trace labels needed by Lilact only \n" +
|
|
20
|
+
" --factory <func> The factory function (default: createComponent)\n" +
|
|
21
|
+
" -h, --help Show help\n"
|
|
22
|
+
);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let factory = "createComponent";
|
|
27
|
+
let discardComments = false;
|
|
28
|
+
let injectTraceLabels = false;
|
|
29
|
+
let isDebug = false;
|
|
30
|
+
|
|
31
|
+
let outDir, inDir;
|
|
32
|
+
const argv = process.argv.slice(2);
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < argv.length; i++) {
|
|
35
|
+
const a = argv[i];
|
|
36
|
+
if (a === "--outDir") {
|
|
37
|
+
outDir = argv[++i];
|
|
38
|
+
if (!outDir) usage();
|
|
39
|
+
outDir = path.resolve(outDir);
|
|
40
|
+
}
|
|
41
|
+
else if (a === "--inDir") {
|
|
42
|
+
inDir = argv[++i];
|
|
43
|
+
if (!inDir) usage();
|
|
44
|
+
inDir = path.resolve(inDir);
|
|
45
|
+
}
|
|
46
|
+
else if (a === "--isDebug") {
|
|
47
|
+
globalThis.DEBUG = true;
|
|
48
|
+
}
|
|
49
|
+
else if (a === "--discardComments") {
|
|
50
|
+
discardComments = true;
|
|
51
|
+
}
|
|
52
|
+
else if (a === "--injectTraceLabels") {
|
|
53
|
+
injectTraceLabels = true;
|
|
54
|
+
}
|
|
55
|
+
else if (a === "--factory") {
|
|
56
|
+
factory = argv[++i];
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
usage();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function walkJsxFiles(dir) {
|
|
64
|
+
const out = [];
|
|
65
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
66
|
+
for (const ent of entries) {
|
|
67
|
+
const full = path.join(dir, ent.name);
|
|
68
|
+
if (ent.isDirectory()) out.push(...walkJsxFiles(full));
|
|
69
|
+
else if (ent.isFile() && (ent.name.endsWith(".js") || ent.name.endsWith(".jsx") ) ) out.push(full);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const files = walkJsxFiles(inDir);
|
|
75
|
+
|
|
76
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
77
|
+
const __dirname = path.dirname(__filename);
|
|
78
|
+
|
|
79
|
+
const transpileBin = path.resolve(__dirname, "transpile.js");
|
|
80
|
+
|
|
81
|
+
if (!fs.existsSync(transpileBin)) {
|
|
82
|
+
throw new Error(`Missing ${transpileBin}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (const inputPath of files) {
|
|
86
|
+
|
|
87
|
+
const relPath = path.relative(inDir, inputPath);
|
|
88
|
+
|
|
89
|
+
let targetOutFile = path.join(outDir, relPath); // file-level destination
|
|
90
|
+
|
|
91
|
+
if(targetOutFile.endsWith('.jsx')) {
|
|
92
|
+
targetOutFile = targetOutFile.slice(0,targetOutFile.length-1);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (fs.existsSync(targetOutFile)) {
|
|
96
|
+
fs.unlinkSync(targetOutFile);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const args = [transpileBin, inputPath, "--out", targetOutFile, "--factory", factory];
|
|
100
|
+
|
|
101
|
+
if(isDebug) args.push("--isDebug");
|
|
102
|
+
if(discardComments) args.push("--discardComments");
|
|
103
|
+
if(injectTraceLabels) args.push("--injectTraceLabels");
|
|
104
|
+
|
|
105
|
+
const res = spawnSync(
|
|
106
|
+
process.execPath,
|
|
107
|
+
args,
|
|
108
|
+
{ stdio: "inherit" }
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (res.status !== 0) process.exit(res.status ?? 1);
|
|
112
|
+
}
|
package/bin/transpile.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Lilact
|
|
6
|
+
Copyright (C) 2024-2025 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
7
|
+
All rights reserved.
|
|
8
|
+
BSD-2-Clause
|
|
9
|
+
|
|
10
|
+
Redistribution and use in source and binary forms, with or without
|
|
11
|
+
modification, are permitted provided that the following conditions are met:
|
|
12
|
+
|
|
13
|
+
* Redistributions of source code must retain the above copyright
|
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
|
15
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
16
|
+
notice, this list of conditions and the following disclaimer in the
|
|
17
|
+
documentation and/or other materials provided with the distribution.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
22
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
23
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
24
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
25
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
26
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
28
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
+
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import fs from "fs";
|
|
33
|
+
import path from "path";
|
|
34
|
+
|
|
35
|
+
import {transpileJSX} from "../src/jsx.js";
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
function usage()
|
|
40
|
+
{
|
|
41
|
+
console.error(
|
|
42
|
+
"Usage:\n" +
|
|
43
|
+
" transpile <entries...> [Options] \n\n" +
|
|
44
|
+
"Options:\n" +
|
|
45
|
+
" --out <filepath> Output filepath for transpiled files. Multiple inputs will be concatenated. If not given, each file will have a separate output with an additinoal .transpiled.js in its name.\n" +
|
|
46
|
+
" --isDebug Add debug labels \n\n" +
|
|
47
|
+
" --discardComments Discard comments \n\n" +
|
|
48
|
+
" --injectTraceLabels Inject trace labels needed by Lilact only \n\n" +
|
|
49
|
+
" --factory <func> The factory function (default: createComponent)\n\n" +
|
|
50
|
+
" -h, --help Show help\n\n" +
|
|
51
|
+
"Example:\n" +
|
|
52
|
+
" transpile src/test.jsx dist/test.js"
|
|
53
|
+
);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const argv = process.argv.slice(2);
|
|
60
|
+
if (argv.length === 0) usage();
|
|
61
|
+
|
|
62
|
+
let out = null;
|
|
63
|
+
|
|
64
|
+
let factory = "createComponent";
|
|
65
|
+
let discardComments = false;
|
|
66
|
+
let injectTraceLabels = false;
|
|
67
|
+
|
|
68
|
+
const entries = [];
|
|
69
|
+
|
|
70
|
+
globalThis.DEBUG = false;
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < argv.length; i++) {
|
|
73
|
+
const a = argv[i];
|
|
74
|
+
if (a === "--out") {
|
|
75
|
+
out = argv[++i];
|
|
76
|
+
if (!out) usage();
|
|
77
|
+
out = path.resolve(out);
|
|
78
|
+
}
|
|
79
|
+
else if (a === "--isDebug") {
|
|
80
|
+
globalThis.DEBUG = true;
|
|
81
|
+
}
|
|
82
|
+
else if (a === "--discardComments") {
|
|
83
|
+
discardComments = true;
|
|
84
|
+
}
|
|
85
|
+
else if (a === "--injectTraceLabels") {
|
|
86
|
+
injectTraceLabels = true;
|
|
87
|
+
}
|
|
88
|
+
else if (a === "--factory") {
|
|
89
|
+
factory = argv[++i];
|
|
90
|
+
}
|
|
91
|
+
else if (a === "-h" || a === "--help") {
|
|
92
|
+
usage();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
entries.push(a);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
if (entries.length === 0) usage();
|
|
101
|
+
|
|
102
|
+
if (out) {
|
|
103
|
+
let p = path.dirname(out);
|
|
104
|
+
if(p!==".") {
|
|
105
|
+
fs.mkdirSync(p, { recursive: true });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
const inputPath = path.resolve(entry);
|
|
112
|
+
const code = fs.readFileSync(inputPath, "utf8");
|
|
113
|
+
|
|
114
|
+
const result = transpileJSX(code,
|
|
115
|
+
{
|
|
116
|
+
path: inputPath,
|
|
117
|
+
appendSourcemap: globalThis.DEBUG,
|
|
118
|
+
factory,
|
|
119
|
+
//mappings: [],
|
|
120
|
+
injectTraceLabels: injectTraceLabels,
|
|
121
|
+
discardComments: discardComments
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
let outFile;
|
|
126
|
+
|
|
127
|
+
if (out) {
|
|
128
|
+
outFile = out;
|
|
129
|
+
fs.appendFileSync(outFile, result, "utf8");
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
outFile = inputPath + ".transpiled.js";
|
|
133
|
+
fs.writeFileSync(outFile, result, "utf8");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
console.log(`Preprocessed: ${inputPath} -> ${outFile}`);
|
|
137
|
+
}
|