paralayer 1.0.3 → 1.0.5
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/dist/bin.js +5 -7
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -1
- package/dist/paralayer.d.ts +3 -8
- package/dist/paralayer.js +9 -32
- package/package.json +3 -9
- package/dist/vite.d.ts +0 -2
- package/dist/vite.js +0 -4
package/dist/bin.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import minimist from 'minimist';
|
|
2
|
-
import {
|
|
2
|
+
import { paralayer } from './index.js';
|
|
3
3
|
const argv = minimist(process.argv.slice(2), {
|
|
4
4
|
string: ['default'],
|
|
5
5
|
boolean: ['watch', 'globalize'],
|
|
6
|
-
default: {
|
|
6
|
+
default: { watch: false, default: null, globalize: false },
|
|
7
7
|
});
|
|
8
8
|
const paths = argv._;
|
|
9
9
|
const input = paths.slice(0, -1);
|
|
@@ -16,12 +16,10 @@ if (!output) {
|
|
|
16
16
|
console.error('[paralayer] Output directory is not provided');
|
|
17
17
|
process.exit(1);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
await paralayer({
|
|
20
20
|
input: input,
|
|
21
21
|
output: output,
|
|
22
|
-
globalize: argv.globalize,
|
|
23
|
-
default: argv.default,
|
|
24
|
-
});
|
|
25
|
-
await paralayer.start({
|
|
26
22
|
watch: argv.watch,
|
|
23
|
+
default: argv.default,
|
|
24
|
+
globalize: argv.globalize,
|
|
27
25
|
});
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/paralayer.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as $utils from '@eposlabs/utils';
|
|
2
|
-
import type { Plugin } from 'vite';
|
|
3
2
|
export type DirPath = string;
|
|
4
3
|
export type File = {
|
|
5
4
|
content: string;
|
|
@@ -8,6 +7,7 @@ export type File = {
|
|
|
8
7
|
export type Options = {
|
|
9
8
|
input: DirPath | DirPath[];
|
|
10
9
|
output: DirPath;
|
|
10
|
+
watch?: boolean;
|
|
11
11
|
/** Default layer name. If a file name does not have layer tags, default name will be used. */
|
|
12
12
|
default?: string | null;
|
|
13
13
|
/** Whether the layer variables should be exposed globally. */
|
|
@@ -23,14 +23,9 @@ export declare class Paralayer extends $utils.Unit {
|
|
|
23
23
|
private extensions;
|
|
24
24
|
private previousLayers;
|
|
25
25
|
private watcher;
|
|
26
|
-
private viteConfig;
|
|
27
26
|
constructor(options: Options);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
watch?: boolean | undefined;
|
|
31
|
-
}) => Promise<void>;
|
|
32
|
-
private onConfigResolved;
|
|
33
|
-
private onBuildStart;
|
|
27
|
+
start: () => Promise<void>;
|
|
28
|
+
readSetupJs(): Promise<string>;
|
|
34
29
|
private onAll;
|
|
35
30
|
private onReady;
|
|
36
31
|
private build;
|
package/dist/paralayer.js
CHANGED
|
@@ -12,20 +12,11 @@ export class Paralayer extends $utils.Unit {
|
|
|
12
12
|
extensions = new Set(['.ts', '.tsx', '.js', '.jsx']);
|
|
13
13
|
previousLayers = [];
|
|
14
14
|
watcher = null;
|
|
15
|
-
viteConfig = null;
|
|
16
15
|
constructor(options) {
|
|
17
16
|
super();
|
|
18
17
|
this.options = options;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
name: 'paralayer',
|
|
23
|
-
enforce: 'pre',
|
|
24
|
-
configResolved: this.onConfigResolved,
|
|
25
|
-
buildStart: this.onBuildStart,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
start = async ({ watch = false } = {}) => {
|
|
19
|
+
start = async () => {
|
|
29
20
|
if (this.started)
|
|
30
21
|
return;
|
|
31
22
|
this.started = true;
|
|
@@ -35,20 +26,13 @@ export class Paralayer extends $utils.Unit {
|
|
|
35
26
|
this.watcher.on('ready', this.onReady);
|
|
36
27
|
await this.ready$.promise;
|
|
37
28
|
await this.queue.run(() => this.build());
|
|
38
|
-
if (!watch)
|
|
29
|
+
if (!this.options.watch)
|
|
39
30
|
await this.watcher.close();
|
|
40
31
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.viteConfig = config;
|
|
46
|
-
};
|
|
47
|
-
onBuildStart = async () => {
|
|
48
|
-
if (!this.viteConfig)
|
|
49
|
-
throw this.never;
|
|
50
|
-
await this.start({ watch: !!this.viteConfig.build.watch });
|
|
51
|
-
};
|
|
32
|
+
async readSetupJs() {
|
|
33
|
+
const setupJsPath = $path.join(this.options.output, 'setup.js');
|
|
34
|
+
return await $fs.readFile(setupJsPath, 'utf-8');
|
|
35
|
+
}
|
|
52
36
|
// ---------------------------------------------------------------------------
|
|
53
37
|
// HANDLERS
|
|
54
38
|
// ---------------------------------------------------------------------------
|
|
@@ -190,7 +174,6 @@ export class Paralayer extends $utils.Unit {
|
|
|
190
174
|
return [...imports].join('\n');
|
|
191
175
|
}
|
|
192
176
|
generateSetupContent(allLayers) {
|
|
193
|
-
const nocheck = '// @ts-nocheck';
|
|
194
177
|
const layers = allLayers.toSorted((layer1, layer2) => {
|
|
195
178
|
if (layer1.length !== layer2.length)
|
|
196
179
|
return layer1.length - layer2.length;
|
|
@@ -198,17 +181,11 @@ export class Paralayer extends $utils.Unit {
|
|
|
198
181
|
});
|
|
199
182
|
const vars = layers.map(layer => {
|
|
200
183
|
const $layerName = this.getLayerName(layer, '$camel');
|
|
184
|
+
if (this.options.globalize)
|
|
185
|
+
return `globalThis.${$layerName} = {}`;
|
|
201
186
|
return `const ${$layerName} = {}`;
|
|
202
187
|
});
|
|
203
|
-
|
|
204
|
-
if (this.options.globalize) {
|
|
205
|
-
globals = layers.map(layer => {
|
|
206
|
-
const $layerName = this.getLayerName(layer, '$camel');
|
|
207
|
-
return `globalThis.${$layerName} = ${$layerName}`;
|
|
208
|
-
});
|
|
209
|
-
globals.unshift('');
|
|
210
|
-
}
|
|
211
|
-
return [nocheck, '', ...vars, ...globals, ''].join('\n');
|
|
188
|
+
return [...vars].join('\n');
|
|
212
189
|
}
|
|
213
190
|
getLayer(path) {
|
|
214
191
|
const name = $path.basename(path);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paralayer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "imkost",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
"dev": "rm -rf dist && tsc --watch",
|
|
14
14
|
"build": "rm -rf dist && tsc",
|
|
15
15
|
"lint": "tsc --noEmit",
|
|
16
|
-
"release": "npm version patch && npm run
|
|
17
|
-
"release:raw": "npm run build && npm publish",
|
|
18
|
-
"release:minor": "npm version minor && npm run release:raw"
|
|
16
|
+
"release": "sh -c 'npm version ${1:-patch} && npm run build && npm publish' --"
|
|
19
17
|
},
|
|
20
18
|
"bin": {
|
|
21
19
|
"paralayer": "bin.js"
|
|
@@ -24,10 +22,6 @@
|
|
|
24
22
|
".": {
|
|
25
23
|
"default": "./dist/index.js",
|
|
26
24
|
"types": "./dist/index.d.ts"
|
|
27
|
-
},
|
|
28
|
-
"./vite": {
|
|
29
|
-
"default": "./dist/vite.js",
|
|
30
|
-
"types": "./dist/vite.d.ts"
|
|
31
25
|
}
|
|
32
26
|
},
|
|
33
27
|
"files": [
|
|
@@ -35,7 +29,7 @@
|
|
|
35
29
|
"bin.js"
|
|
36
30
|
],
|
|
37
31
|
"dependencies": {
|
|
38
|
-
"
|
|
32
|
+
"@eposlabs/utils": "^1.0.0",
|
|
39
33
|
"chokidar": "^4.0.3",
|
|
40
34
|
"minimist": "^1.2.8"
|
|
41
35
|
},
|
package/dist/vite.d.ts
DELETED
package/dist/vite.js
DELETED