@oicl-lit/gen-utils 0.3.4
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/README.md +3 -0
- package/lib/file-utils.d.ts +28 -0
- package/lib/file-utils.js +52 -0
- package/lib/file-utils.js.map +1 -0
- package/lib/package-utils.d.ts +38 -0
- package/lib/package-utils.js +101 -0
- package/lib/package-utils.js.map +1 -0
- package/lib/str-utils.d.ts +27 -0
- package/lib/str-utils.js +33 -0
- package/lib/str-utils.js.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Object with keys either specifying a filename (with value of string contents)
|
|
8
|
+
* or a folder name (with value of another FileTree object). As a convenience,
|
|
9
|
+
* filenames may contain slashes, in which case folders are automatically
|
|
10
|
+
* created.
|
|
11
|
+
*/
|
|
12
|
+
export interface FileTree {
|
|
13
|
+
[path: string]: string | FileTree;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Test whether a path is contained within a root path
|
|
17
|
+
*/
|
|
18
|
+
export declare const pathIsinRootPath: (subPath: string, rootPath: string) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Writes a tree of files to an output folder.
|
|
21
|
+
*
|
|
22
|
+
* @param outDir Root folder to write files into
|
|
23
|
+
* @param tree Object with keys either specifying a filename (with value
|
|
24
|
+
* of string contents) or a folder name (with value of another FileTree object).
|
|
25
|
+
* As a convenience, filenames may contain slashes, in which case folders
|
|
26
|
+
* are automatically created.
|
|
27
|
+
*/
|
|
28
|
+
export declare const writeFileTree: (outDir: string, tree: FileTree) => Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from 'fs/promises';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
/**
|
|
9
|
+
* Test whether a path is contained within a root path
|
|
10
|
+
*/
|
|
11
|
+
export const pathIsinRootPath = (subPath, rootPath) => {
|
|
12
|
+
if (!subPath.startsWith(rootPath)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const subpath = subPath.substring(rootPath.length);
|
|
16
|
+
if (!rootPath.endsWith(path.sep)) {
|
|
17
|
+
// Make sure we don't have path='/abc/def' and root='/ab'
|
|
18
|
+
if (!subpath.startsWith(path.sep)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Writes a tree of files to an output folder.
|
|
26
|
+
*
|
|
27
|
+
* @param outDir Root folder to write files into
|
|
28
|
+
* @param tree Object with keys either specifying a filename (with value
|
|
29
|
+
* of string contents) or a folder name (with value of another FileTree object).
|
|
30
|
+
* As a convenience, filenames may contain slashes, in which case folders
|
|
31
|
+
* are automatically created.
|
|
32
|
+
*/
|
|
33
|
+
export const writeFileTree = async (outDir, tree) => {
|
|
34
|
+
outDir = path.resolve(outDir);
|
|
35
|
+
for (const [name, fileOrFolder] of Object.entries(tree)) {
|
|
36
|
+
const fullPath = path.resolve(outDir, name);
|
|
37
|
+
if (!pathIsinRootPath(fullPath, outDir)) {
|
|
38
|
+
throw new Error(`Path '${fullPath}' is not contained in '${outDir}' when writing a ` +
|
|
39
|
+
`file tree containing an entry of '${name}'.`);
|
|
40
|
+
}
|
|
41
|
+
const folder = path.dirname(fullPath);
|
|
42
|
+
// TODO(kschaaf) Consider making this recursion async for parallel i/o
|
|
43
|
+
if (typeof fileOrFolder === 'string') {
|
|
44
|
+
await fs.mkdir(folder, { recursive: true });
|
|
45
|
+
await fs.writeFile(fullPath, fileOrFolder);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
await writeFileTree(fullPath, fileOrFolder);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=file-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../src/lib/file-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAY7B;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAAe,EAAE,QAAgB,EAAE,EAAE;IACpE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,yDAAyD;QACzD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAE,IAAc,EAAE,EAAE;IACpE,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,KAAK,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CACb,SAAS,QAAQ,0BAA0B,MAAM,mBAAmB;gBAClE,qCAAqC,IAAI,IAAI,CAChD,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtC,sEAAsE;QACtE,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;YAC1C,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,MAAM,aAAa,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Map npm package name to folder in monorepo to use instead
|
|
8
|
+
*/
|
|
9
|
+
export interface MonorepoPackages {
|
|
10
|
+
[index: string]: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Runs `npm i` in the package in the given packageRoot, optionally using
|
|
14
|
+
* monorepo packages in place of installing from the registry.
|
|
15
|
+
*
|
|
16
|
+
* Note that rather than using an `npm link` / symlink approach for substituting
|
|
17
|
+
* monorepo packages, we use `npm pack` and point package.json to the tarball
|
|
18
|
+
* for that package. This more closely matches how a given test package will be
|
|
19
|
+
* installed from the registry, and avoids issues when a monorepo has
|
|
20
|
+
* peerDependencies (since a monorepo package will have its own copy of its
|
|
21
|
+
* peerDependencies installed, which is not what will happen when installed as a
|
|
22
|
+
* dependency itself).
|
|
23
|
+
*
|
|
24
|
+
* @param packageRoot
|
|
25
|
+
* @param linkedPackages
|
|
26
|
+
*/
|
|
27
|
+
export declare const installPackage: (packageRoot: string, monorepoPackages?: MonorepoPackages) => Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Runs `npm run build` on the given package
|
|
30
|
+
* @param packageRoot
|
|
31
|
+
*/
|
|
32
|
+
export declare const buildPackage: (packageRoot: string) => Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Runs `npm pack` on the given package
|
|
35
|
+
* @param packageRoot
|
|
36
|
+
* @returns Absolute path to the packaged tarball
|
|
37
|
+
*/
|
|
38
|
+
export declare const packPackage: (packageRoot: string) => Promise<string>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import { promisify } from 'util';
|
|
7
|
+
import { exec as execCb } from 'child_process';
|
|
8
|
+
import * as fs from 'fs/promises';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
const exec = promisify(execCb);
|
|
11
|
+
/**
|
|
12
|
+
* Runs `npm i` in the package in the given packageRoot, optionally using
|
|
13
|
+
* monorepo packages in place of installing from the registry.
|
|
14
|
+
*
|
|
15
|
+
* Note that rather than using an `npm link` / symlink approach for substituting
|
|
16
|
+
* monorepo packages, we use `npm pack` and point package.json to the tarball
|
|
17
|
+
* for that package. This more closely matches how a given test package will be
|
|
18
|
+
* installed from the registry, and avoids issues when a monorepo has
|
|
19
|
+
* peerDependencies (since a monorepo package will have its own copy of its
|
|
20
|
+
* peerDependencies installed, which is not what will happen when installed as a
|
|
21
|
+
* dependency itself).
|
|
22
|
+
*
|
|
23
|
+
* @param packageRoot
|
|
24
|
+
* @param linkedPackages
|
|
25
|
+
*/
|
|
26
|
+
export const installPackage = async (packageRoot, monorepoPackages) => {
|
|
27
|
+
// Read package.json
|
|
28
|
+
const packageFile = path.join(packageRoot, 'package.json');
|
|
29
|
+
const packageText = await fs.readFile(packageFile, 'utf8');
|
|
30
|
+
const packageJson = JSON.parse(packageText);
|
|
31
|
+
if (monorepoPackages !== undefined) {
|
|
32
|
+
let deps;
|
|
33
|
+
for (const [pkg, folder] of Object.entries(monorepoPackages)) {
|
|
34
|
+
// Figure out what kind of dep the linked dep is
|
|
35
|
+
if (packageJson.dependencies?.[pkg] !== undefined) {
|
|
36
|
+
deps = packageJson.dependencies;
|
|
37
|
+
}
|
|
38
|
+
else if (packageJson.devDependencies?.[pkg] !== undefined) {
|
|
39
|
+
deps = packageJson.devDependencies;
|
|
40
|
+
}
|
|
41
|
+
else if (packageJson.peerDependencies?.[pkg] !== undefined) {
|
|
42
|
+
deps = packageJson.peerDependencies;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// TODO(kschaaf) Would be nice to also validate the monorepo package
|
|
46
|
+
// fulfills the generated version constraint
|
|
47
|
+
throw new Error(`Linked package '${pkg}' was not a dependency of '${packageFile}'.`);
|
|
48
|
+
}
|
|
49
|
+
// Make sure the folder for the package to link exists
|
|
50
|
+
try {
|
|
51
|
+
await fs.access(folder);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error(`Folder ${folder} for linked package '${pkg}' did not exist.`);
|
|
55
|
+
}
|
|
56
|
+
// npm pack the linked package into a tarball
|
|
57
|
+
const tarballFile = await packPackage(folder);
|
|
58
|
+
// Update the package.json dep with a file path to the tarball
|
|
59
|
+
deps[pkg] = `file:${tarballFile}`;
|
|
60
|
+
}
|
|
61
|
+
// Write out the updated package.json
|
|
62
|
+
await fs.writeFile(packageFile, JSON.stringify(packageJson, null, 2), 'utf8');
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Install
|
|
66
|
+
await exec('npm install', { cwd: packageRoot });
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
// Restore package.json
|
|
70
|
+
await fs.writeFile(packageFile, packageText, 'utf8');
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Runs `npm run build` on the given package
|
|
75
|
+
* @param packageRoot
|
|
76
|
+
*/
|
|
77
|
+
export const buildPackage = async (packageRoot) => {
|
|
78
|
+
try {
|
|
79
|
+
await exec('npm run build', { cwd: packageRoot });
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
const { stdout } = e;
|
|
83
|
+
throw new Error(`Failed to build package '${packageRoot}': ${stdout}`);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Runs `npm pack` on the given package
|
|
88
|
+
* @param packageRoot
|
|
89
|
+
* @returns Absolute path to the packaged tarball
|
|
90
|
+
*/
|
|
91
|
+
export const packPackage = async (packageRoot) => {
|
|
92
|
+
try {
|
|
93
|
+
const { stdout: tarballFile } = await exec('npm pack', { cwd: packageRoot });
|
|
94
|
+
return path.resolve(packageRoot, tarballFile.trim());
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
const { stdout } = e;
|
|
98
|
+
throw new Error(`Failed to pack package '${packageRoot}': ${stdout}`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=package-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-utils.js","sourceRoot":"","sources":["../src/lib/package-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAC,IAAI,IAAI,MAAM,EAAC,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAS/B;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,cAA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AAE,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,EAAC,MAAM,EAAC,GAAG,CAAqB,CAAC;QACvC,MAAM,IAAI,KAAK,CAAC,2BAA2B,WAAW,MAAM,MAAM,EAAE,CAAC,CAAC;IACxE,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Use https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript
|
|
8
|
+
* for JS syntax highlighting
|
|
9
|
+
*/
|
|
10
|
+
export declare const javascript: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Use https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html
|
|
13
|
+
* for HTML syntax highlighting
|
|
14
|
+
*/
|
|
15
|
+
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Converts string to initial cap.
|
|
18
|
+
*/
|
|
19
|
+
export declare const toInitialCap: (str: string) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Converts kabob-case string to PascalCase.
|
|
22
|
+
*/
|
|
23
|
+
export declare const kabobToPascalCase: (str: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Converts kabob-case event name to an "on" event: `onEventName`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const kabobToOnEvent: (str: string) => string;
|
package/lib/str-utils.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generic tagged-template literal string concatenator with array value
|
|
8
|
+
* flattening. Can be assigned to various tag names for syntax highlighting.
|
|
9
|
+
*/
|
|
10
|
+
const concat = (strings, ...values) => values.reduce((acc, v, i) => acc + (Array.isArray(v) ? v.flat(Infinity).join('') : v) + strings[i + 1], strings[0]);
|
|
11
|
+
/**
|
|
12
|
+
* Use https://marketplace.visualstudio.com/items?itemName=zjcompt.es6-string-javascript
|
|
13
|
+
* for JS syntax highlighting
|
|
14
|
+
*/
|
|
15
|
+
export const javascript = concat;
|
|
16
|
+
/**
|
|
17
|
+
* Use https://marketplace.visualstudio.com/items?itemName=Tobermory.es6-string-html
|
|
18
|
+
* for HTML syntax highlighting
|
|
19
|
+
*/
|
|
20
|
+
export const html = concat;
|
|
21
|
+
/**
|
|
22
|
+
* Converts string to initial cap.
|
|
23
|
+
*/
|
|
24
|
+
export const toInitialCap = (str) => str ? `${str[0].toUpperCase()}${str.slice(1)}` : str;
|
|
25
|
+
/**
|
|
26
|
+
* Converts kabob-case string to PascalCase.
|
|
27
|
+
*/
|
|
28
|
+
export const kabobToPascalCase = (str) => toInitialCap(str).replace(/-[a-z]/g, (m) => m[1].toUpperCase());
|
|
29
|
+
/**
|
|
30
|
+
* Converts kabob-case event name to an "on" event: `onEventName`.
|
|
31
|
+
*/
|
|
32
|
+
export const kabobToOnEvent = (str) => `on${kabobToPascalCase(str)}`;
|
|
33
|
+
//# sourceMappingURL=str-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"str-utils.js","sourceRoot":"","sources":["../src/lib/str-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,MAAM,GAAG,CAAC,OAA6B,EAAE,GAAG,MAAiB,EAAE,EAAE,CACrE,MAAM,CAAC,MAAM,CACX,CAAC,GAAW,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CACpB,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAC3E,OAAO,CAAC,CAAC,CAAC,CACX,CAAC;AAEJ;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAE3B;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAE,EAAE,CAC1C,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAE,EAAE,CAC/C,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAElE;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,KAAK,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oicl-lit/gen-utils",
|
|
3
|
+
"description": "Utilities for lit code generators",
|
|
4
|
+
"version": "0.3.4",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"author": "Google LLC",
|
|
9
|
+
"license": "BSD-3-Clause",
|
|
10
|
+
"bugs": "https://github.com/lit/lit/issues",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/lit/lit.git",
|
|
16
|
+
"directory": "packages/labs/gen"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "wireit",
|
|
20
|
+
"test": "wireit"
|
|
21
|
+
},
|
|
22
|
+
"wireit": {
|
|
23
|
+
"build": {
|
|
24
|
+
"command": "tsc --build --pretty",
|
|
25
|
+
"dependencies": [
|
|
26
|
+
"../analyzer:build",
|
|
27
|
+
"../../tests:build"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"src/**/*.ts",
|
|
31
|
+
"tsconfig.json"
|
|
32
|
+
],
|
|
33
|
+
"output": [
|
|
34
|
+
"lib",
|
|
35
|
+
"test",
|
|
36
|
+
"index.{js,js.map,d.ts,d.ts.map}"
|
|
37
|
+
],
|
|
38
|
+
"clean": "if-file-deleted"
|
|
39
|
+
},
|
|
40
|
+
"test": {
|
|
41
|
+
"#comment": "The quotes around the file regex must be double quotes on windows!",
|
|
42
|
+
"command": "uvu test \"_test\\.js$\"",
|
|
43
|
+
"dependencies": [
|
|
44
|
+
"build",
|
|
45
|
+
"../../lit:build",
|
|
46
|
+
"../../tests:build"
|
|
47
|
+
],
|
|
48
|
+
"files": [],
|
|
49
|
+
"output": []
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@oicl-lit/analyzer": "^0.14.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@lit-internal/tests": "^0.0.1",
|
|
57
|
+
"@types/node": "^22.17.0"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=14.8.0"
|
|
61
|
+
},
|
|
62
|
+
"files": [
|
|
63
|
+
"lib"
|
|
64
|
+
],
|
|
65
|
+
"homepage": "https://github.com/lit/lit",
|
|
66
|
+
"keywords": [
|
|
67
|
+
"lit",
|
|
68
|
+
"lit-html",
|
|
69
|
+
"lit-element",
|
|
70
|
+
"LitElement",
|
|
71
|
+
"generator",
|
|
72
|
+
"cli"
|
|
73
|
+
]
|
|
74
|
+
}
|