unplugin-atscript 0.0.1
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/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/index.cjs +71 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +44 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Atscript
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Atscript Unplugin
|
|
2
|
+
|
|
3
|
+
An Unplugin for processing `.as` files using [Atscript](https://github.com/moostjs/atscript). This plugin enables seamless integration of Atscript into modern build tools like Vite and Rollup. Thanks to Unplugin, it also supports Webpack and other bundlers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Supports `.as` file resolution and transformation
|
|
8
|
+
- Loads and processes `.as` files with Atscript
|
|
9
|
+
- Generates JavaScript output
|
|
10
|
+
- Compatible with Vite, Rollup, and other Unplugin-supported bundlers
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install -D unplugin-atscript @atscript/typescript
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
or
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
yarn add --dev unplugin-atscript @atscript/typescript
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pnpm add -D unplugin-atscript @atscript/typescript
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Vite
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// vite.config.ts
|
|
36
|
+
import { defineConfig } from 'vite'
|
|
37
|
+
import atscript from 'unplugin-atscript'
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
plugins: [atscript.vite()],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Rollup
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// rollup.config.js
|
|
48
|
+
import atscript from 'unplugin-atscript'
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
input: 'src/main.ts',
|
|
52
|
+
output: {
|
|
53
|
+
dir: 'dist',
|
|
54
|
+
format: 'esm',
|
|
55
|
+
},
|
|
56
|
+
plugins: [atscript.rollup()],
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## How It Works
|
|
61
|
+
|
|
62
|
+
1. Resolves `.as` files in the project.
|
|
63
|
+
2. Loads the Atscript configuration.
|
|
64
|
+
3. Uses `@atscript/core` to parse and transform `.as` files into JavaScript.
|
|
65
|
+
4. Outputs the generated JavaScript for further processing.
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
The plugin automatically loads the Atscript configuration from your project. You can define additional options in your Atscript configuration file (`atscript.config.js` or `atscript.config.ts`).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
|
+
//#region rolldown:runtime
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
const path = __toESM(require("path"));
|
|
27
|
+
const __atscript_core = __toESM(require("@atscript/core"));
|
|
28
|
+
const __atscript_typescript = __toESM(require("@atscript/typescript"));
|
|
29
|
+
const fs_promises = __toESM(require("fs/promises"));
|
|
30
|
+
const unplugin = __toESM(require("unplugin"));
|
|
31
|
+
|
|
32
|
+
//#region packages/unplugin/src/index.ts
|
|
33
|
+
const anscriptPluginFactory = () => {
|
|
34
|
+
const root = process.cwd();
|
|
35
|
+
let anscriptConfig = new Promise((resolve) => {
|
|
36
|
+
(0, __atscript_core.resolveConfigFile)(root).then((p) => {
|
|
37
|
+
(0, __atscript_core.loadConfig)(path.default.join(root, p)).then(resolve);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
let repo;
|
|
41
|
+
return {
|
|
42
|
+
name: "atscript",
|
|
43
|
+
resolveId(id, importer) {
|
|
44
|
+
if (importer && id.endsWith(".as")) return path.default.join(path.default.dirname(importer), id);
|
|
45
|
+
},
|
|
46
|
+
async load(id) {
|
|
47
|
+
if (id.endsWith(".as")) {
|
|
48
|
+
if (!repo) {
|
|
49
|
+
const config = await anscriptConfig;
|
|
50
|
+
if (!config.plugins) config.plugins = [(0, __atscript_typescript.default)()];
|
|
51
|
+
repo = new __atscript_core.AtscriptRepo(root, config);
|
|
52
|
+
}
|
|
53
|
+
const code = (await (0, fs_promises.readFile)(id, "utf8")).toString();
|
|
54
|
+
const doc = await repo.openDocument("file://" + id, code);
|
|
55
|
+
await repo.checkDoc(doc);
|
|
56
|
+
const out = await doc.render("js");
|
|
57
|
+
return {
|
|
58
|
+
code: out?.[0]?.content || "",
|
|
59
|
+
moduleType: "js"
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const asPlugin = /* #__PURE__ */ (0, unplugin.createUnplugin)(anscriptPluginFactory);
|
|
66
|
+
var src_default = asPlugin;
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
exports.anscriptPluginFactory = anscriptPluginFactory
|
|
70
|
+
exports.asPlugin = asPlugin
|
|
71
|
+
exports.default = src_default
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as unplugin from 'unplugin';
|
|
2
|
+
import { UnpluginFactory } from 'unplugin';
|
|
3
|
+
|
|
4
|
+
declare const anscriptPluginFactory: UnpluginFactory<undefined>;
|
|
5
|
+
declare const asPlugin: unplugin.UnpluginInstance<undefined, boolean>;
|
|
6
|
+
|
|
7
|
+
export { anscriptPluginFactory, asPlugin, asPlugin as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { AtscriptRepo, loadConfig, resolveConfigFile } from "@atscript/core";
|
|
3
|
+
import ts from "@atscript/typescript";
|
|
4
|
+
import { readFile } from "fs/promises";
|
|
5
|
+
import { createUnplugin } from "unplugin";
|
|
6
|
+
|
|
7
|
+
//#region packages/unplugin/src/index.ts
|
|
8
|
+
const anscriptPluginFactory = () => {
|
|
9
|
+
const root = process.cwd();
|
|
10
|
+
let anscriptConfig = new Promise((resolve) => {
|
|
11
|
+
resolveConfigFile(root).then((p) => {
|
|
12
|
+
loadConfig(path.join(root, p)).then(resolve);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
let repo;
|
|
16
|
+
return {
|
|
17
|
+
name: "atscript",
|
|
18
|
+
resolveId(id, importer) {
|
|
19
|
+
if (importer && id.endsWith(".as")) return path.join(path.dirname(importer), id);
|
|
20
|
+
},
|
|
21
|
+
async load(id) {
|
|
22
|
+
if (id.endsWith(".as")) {
|
|
23
|
+
if (!repo) {
|
|
24
|
+
const config = await anscriptConfig;
|
|
25
|
+
if (!config.plugins) config.plugins = [ts()];
|
|
26
|
+
repo = new AtscriptRepo(root, config);
|
|
27
|
+
}
|
|
28
|
+
const code = (await readFile(id, "utf8")).toString();
|
|
29
|
+
const doc = await repo.openDocument("file://" + id, code);
|
|
30
|
+
await repo.checkDoc(doc);
|
|
31
|
+
const out = await doc.render("js");
|
|
32
|
+
return {
|
|
33
|
+
code: out?.[0]?.content || "",
|
|
34
|
+
moduleType: "js"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const asPlugin = /* #__PURE__ */ createUnplugin(anscriptPluginFactory);
|
|
41
|
+
var src_default = asPlugin;
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { anscriptPluginFactory, asPlugin, src_default as default };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "unplugin-atscript",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Atscript: Configuration and build plugins.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"atscript",
|
|
21
|
+
"annotations",
|
|
22
|
+
"vite-plugin",
|
|
23
|
+
"rolldown-plugin",
|
|
24
|
+
"config",
|
|
25
|
+
"runtime"
|
|
26
|
+
],
|
|
27
|
+
"author": "Artem Maltsev",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/moostjs/atscript.git",
|
|
31
|
+
"directory": "packages/unplugin"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/moostjs/atscript/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/unplugin#readme",
|
|
37
|
+
"license": "ISC",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"unplugin": "^2.1.2",
|
|
40
|
+
"@atscript/core": "^0.0.1",
|
|
41
|
+
"@atscript/typescript": "^0.0.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"vitest": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"pub": "pnpm publish --access public",
|
|
48
|
+
"test": "vitest"
|
|
49
|
+
}
|
|
50
|
+
}
|