@cxl/build 0.0.2 → 0.2.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/amd-static.d.ts +0 -0
- package/amd-static.js +56 -0
- package/amd-static.tsbuildinfo +1 -0
- package/amd.js +120 -0
- package/builder.d.ts +14 -0
- package/builder.js +130 -0
- package/cxl.d.ts +5 -0
- package/cxl.js +192 -0
- package/file.d.ts +37 -0
- package/file.js +136 -0
- package/git.d.ts +3 -0
- package/git.js +25 -0
- package/index.d.ts +10 -0
- package/index.js +40 -285
- package/license-Apache-2.0.txt +202 -0
- package/license-GPL-3.0.txt +674 -0
- package/lint.d.ts +3 -0
- package/lint.js +41 -0
- package/npm.d.ts +38 -0
- package/npm.js +72 -0
- package/package.d.ts +70 -0
- package/package.js +337 -0
- package/package.json +27 -4
- package/test-report.html +1200 -0
- package/test-report.json +1 -0
- package/test.d.ts +2 -0
- package/test.js +17 -0
- package/tsc.d.ts +10 -0
- package/tsc.js +173 -0
- package/tsconfig.amd.json +1 -0
- package/tsconfig.test.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/yarn.lock +0 -26
package/lint.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eslint = eslint;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const rx_1 = require("@cxl/rx");
|
|
6
|
+
const builder_js_1 = require("./builder.js");
|
|
7
|
+
function handleEslintResult(results) {
|
|
8
|
+
const result = [];
|
|
9
|
+
let hasErrors = false;
|
|
10
|
+
results.forEach(result => {
|
|
11
|
+
const errorCount = result.errorCount;
|
|
12
|
+
const file = (0, path_1.relative)(process.cwd(), result.filePath);
|
|
13
|
+
(0, builder_js_1.appLog)(`eslint ${file}`);
|
|
14
|
+
if (errorCount) {
|
|
15
|
+
hasErrors = true;
|
|
16
|
+
result.messages.forEach(r => console.error(`${file}#${r.line}:${r.column}: ${r.message} (${r.ruleId})`));
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
if (hasErrors)
|
|
20
|
+
throw new Error('eslint errors found.');
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function eslint(options) {
|
|
24
|
+
return new rx_1.Observable(subs => {
|
|
25
|
+
const eslintPath = require.resolve('eslint', {
|
|
26
|
+
paths: [process.cwd(), __dirname],
|
|
27
|
+
});
|
|
28
|
+
const { ESLint } = require(eslintPath);
|
|
29
|
+
(0, builder_js_1.appLog)(`eslint ${ESLint.version} (${eslintPath})`);
|
|
30
|
+
const linter = new ESLint({
|
|
31
|
+
cache: true,
|
|
32
|
+
cwd: process.cwd(),
|
|
33
|
+
// fix: true,
|
|
34
|
+
...options,
|
|
35
|
+
});
|
|
36
|
+
linter
|
|
37
|
+
.lintFiles(['**/*.ts?(x)'])
|
|
38
|
+
.then(handleEslintResult)
|
|
39
|
+
.then(() => subs.complete(), e => subs.error(e));
|
|
40
|
+
});
|
|
41
|
+
}
|
package/npm.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type License = 'GPL-3.0' | 'GPL-3.0-only' | 'Apache-2.0' | 'UNLICENSED' | 'SEE LICENSE IN LICENSE.txt';
|
|
2
|
+
export type Dependencies = Record<string, string>;
|
|
3
|
+
export interface Package {
|
|
4
|
+
name: string;
|
|
5
|
+
version: string;
|
|
6
|
+
description: string;
|
|
7
|
+
license: License;
|
|
8
|
+
files: string[];
|
|
9
|
+
main: string;
|
|
10
|
+
bin?: string;
|
|
11
|
+
keywords?: string[];
|
|
12
|
+
browser?: string;
|
|
13
|
+
homepage: string;
|
|
14
|
+
private: boolean;
|
|
15
|
+
bugs: string;
|
|
16
|
+
repository: string | {
|
|
17
|
+
type: 'git';
|
|
18
|
+
url: string;
|
|
19
|
+
directory?: string;
|
|
20
|
+
};
|
|
21
|
+
dependencies?: Dependencies;
|
|
22
|
+
devDependencies?: Dependencies;
|
|
23
|
+
peerDependencies?: Dependencies;
|
|
24
|
+
bundledDependecies?: Dependencies;
|
|
25
|
+
type?: string;
|
|
26
|
+
scripts?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export interface PackageInfo extends Package {
|
|
29
|
+
'dist-tags': Record<string, string>;
|
|
30
|
+
versions: string[];
|
|
31
|
+
time: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
export declare function readPackage(path: string): Promise<Package>;
|
|
34
|
+
export declare function getLatestVersion(packageName: string, tag?: string): Promise<string | undefined>;
|
|
35
|
+
export declare function isPackageVersionPublished(packageName: string, version: string): Promise<boolean>;
|
|
36
|
+
export declare function testPackage(dir: string): Promise<void>;
|
|
37
|
+
export declare function publishNpm(dir: string): Promise<void>;
|
|
38
|
+
export declare function getPackageInfo(name: string): Promise<PackageInfo>;
|
package/npm.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readPackage = readPackage;
|
|
4
|
+
exports.getLatestVersion = getLatestVersion;
|
|
5
|
+
exports.isPackageVersionPublished = isPackageVersionPublished;
|
|
6
|
+
exports.testPackage = testPackage;
|
|
7
|
+
exports.publishNpm = publishNpm;
|
|
8
|
+
exports.getPackageInfo = getPackageInfo;
|
|
9
|
+
const program_1 = require("@cxl/program");
|
|
10
|
+
const promises_1 = require("fs/promises");
|
|
11
|
+
const git_js_1 = require("./git.js");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
async function readPackage(path) {
|
|
14
|
+
return JSON.parse(await (0, promises_1.readFile)(path, 'utf8'));
|
|
15
|
+
}
|
|
16
|
+
async function getLatestVersion(packageName, tag = 'latest') {
|
|
17
|
+
const info = await getPackageInfo(packageName);
|
|
18
|
+
return info?.['dist-tags'][tag] || undefined;
|
|
19
|
+
}
|
|
20
|
+
async function isPackageVersionPublished(packageName, version) {
|
|
21
|
+
const info = await getPackageInfo(packageName);
|
|
22
|
+
return info.versions.includes(version);
|
|
23
|
+
}
|
|
24
|
+
async function testPackage(dir) {
|
|
25
|
+
const cwd = (0, path_1.resolve)(`dist/${dir}`);
|
|
26
|
+
if (!cwd.startsWith(process.cwd()))
|
|
27
|
+
throw `"${cwd}" should be under current working directory`;
|
|
28
|
+
await (0, program_1.sh)(`npm install --production`, { cwd });
|
|
29
|
+
try {
|
|
30
|
+
await (0, program_1.sh)(`npm test`, { cwd: dir });
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
await (0, program_1.sh)(`rm -rf ${cwd}/node_modules package-lock.json`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function publishNpm(dir) {
|
|
37
|
+
const branch = await (0, git_js_1.getBranch)(process.cwd());
|
|
38
|
+
if (branch !== 'master')
|
|
39
|
+
throw `Active branch "${branch}" is not master`;
|
|
40
|
+
const pkg = await readPackage(`${dir}/package.json`);
|
|
41
|
+
await (0, git_js_1.checkBranchClean)('master');
|
|
42
|
+
const info = await getPackageInfo(pkg.name);
|
|
43
|
+
if (info.versions.includes(pkg.version)) {
|
|
44
|
+
console.log(`Package "${pkg.name}" version "${pkg.version}" already published. Skipping.`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log(`Building ${pkg.name} ${pkg.version}`);
|
|
48
|
+
await (0, program_1.sh)(`npm run build package --prefix ${dir}`);
|
|
49
|
+
await testPackage(dir);
|
|
50
|
+
const distDir = `dist/${dir}`;
|
|
51
|
+
const tag = pkg.version.includes('beta') ? 'beta' : 'latest';
|
|
52
|
+
const removeVersion = tag === 'beta' ? info['dist-tags'].beta : undefined;
|
|
53
|
+
console.log(await (0, program_1.sh)(`npm publish --access=public --tag ${tag}`, {
|
|
54
|
+
cwd: distDir,
|
|
55
|
+
}));
|
|
56
|
+
if (tag === 'beta') {
|
|
57
|
+
const baseTag = `${pkg.version.split('.')[0]}-beta`;
|
|
58
|
+
console.log(await (0, program_1.sh)(`npm dist-tag add ${pkg.name}@${pkg.version} ${baseTag}`));
|
|
59
|
+
}
|
|
60
|
+
if (removeVersion)
|
|
61
|
+
console.log(await (0, program_1.sh)(`npm unpublish ${pkg.name}@${removeVersion}`));
|
|
62
|
+
}
|
|
63
|
+
// Create Release Tag if it doesn't exist already
|
|
64
|
+
const gitTag = `${dir}/${pkg.version}`;
|
|
65
|
+
if (!(await (0, program_1.sh)(`git tag -l ${gitTag}`)).trim()) {
|
|
66
|
+
console.log(`Creating tag "${gitTag}"`);
|
|
67
|
+
await (0, program_1.sh)(`git tag ${gitTag} && git push origin ${gitTag}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function getPackageInfo(name) {
|
|
71
|
+
return JSON.parse((await (0, program_1.sh)(`npm show ${name} --json`)).trim());
|
|
72
|
+
}
|
package/package.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Observable } from '@cxl/rx';
|
|
2
|
+
import { Output } from '@cxl/source';
|
|
3
|
+
import { Package } from './npm.js';
|
|
4
|
+
import * as ts from 'typescript';
|
|
5
|
+
export declare const BASEDIR: string;
|
|
6
|
+
export declare function readPackage(base?: string): Package;
|
|
7
|
+
export declare function docs(dirName: string, devMode?: boolean): Observable<any, "none">;
|
|
8
|
+
export interface DocgenOptions {
|
|
9
|
+
file: string | string[];
|
|
10
|
+
name: string;
|
|
11
|
+
npm?: string;
|
|
12
|
+
setup?: string;
|
|
13
|
+
repo?: string;
|
|
14
|
+
repodir?: string;
|
|
15
|
+
typeRoots?: string;
|
|
16
|
+
sitemapBase?: string;
|
|
17
|
+
scripts?: string;
|
|
18
|
+
packageJson?: string;
|
|
19
|
+
docsJson?: string;
|
|
20
|
+
cwd?: string;
|
|
21
|
+
forceInstall?: boolean;
|
|
22
|
+
markdown?: boolean;
|
|
23
|
+
baseHref?: string;
|
|
24
|
+
tag: string;
|
|
25
|
+
outDir?: string;
|
|
26
|
+
tmpDir?: string;
|
|
27
|
+
rootDir?: string;
|
|
28
|
+
customJsDocTags?: string[];
|
|
29
|
+
exports?: string[];
|
|
30
|
+
summary?: boolean;
|
|
31
|
+
followReferences?: boolean;
|
|
32
|
+
cxlExtensions?: boolean;
|
|
33
|
+
headHtml?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function docgen(options: DocgenOptions): Promise<{
|
|
36
|
+
name: string;
|
|
37
|
+
version: string;
|
|
38
|
+
description: string;
|
|
39
|
+
sitemap: string;
|
|
40
|
+
}>;
|
|
41
|
+
export declare function docgenTask(packages: DocgenOptions[], commonOptions?: Partial<DocgenOptions>): Observable<{
|
|
42
|
+
path: string;
|
|
43
|
+
source: Buffer<ArrayBuffer>;
|
|
44
|
+
}, "none">;
|
|
45
|
+
/**
|
|
46
|
+
* Generate README file
|
|
47
|
+
*/
|
|
48
|
+
export declare function readme(): Observable<{
|
|
49
|
+
path: string;
|
|
50
|
+
source: Buffer<ArrayBuffer>;
|
|
51
|
+
}, "none">;
|
|
52
|
+
export declare function pkg(): Observable<Output, "none">;
|
|
53
|
+
export declare function AMD(): Observable<Output, "none">;
|
|
54
|
+
export declare function bundle(files: Record<string, string>, outFile: string, config?: ts.CompilerOptions): Observable<Output, "none">;
|
|
55
|
+
export declare function bundleAmd(files: Record<string, string>, outFile: string): Observable<Output, "none">;
|
|
56
|
+
export declare const REQUIRE_REPLACE = "\n\trequire.replace = function (path) {\n\t\treturn path.replace(\n\t\t\t/^@cxl\\/workspace\\.(.+)/,\n\t\t\t(str, p1) =>\n\t\t\t\t`/cxl.app/dist/${str.endsWith('.js') ? p1 : p1 + '/index.js'}`\n\t\t).replace(\n\t\t\t/^@cxl\\/(ui.*)/,\n\t\t\t(str, p1) =>\n\t\t\t\t`/ui/dist/${str.endsWith('.js') ? p1 : p1 + '/index.js'}`\n\t\t).replace(\n\t\t\t/^@cxl\\/(.+)/,\n\t\t\t(str, p1) =>\n\t\t\t\t`/cxl/dist/${str.endsWith('.js') ? p1 : p1 + '/index.js'}`\n\t\t);\n\t};\n";
|
|
57
|
+
interface TemplateConfig {
|
|
58
|
+
header: string;
|
|
59
|
+
debugHeader: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function template(filename: string, config?: Partial<TemplateConfig>): Observable<{
|
|
62
|
+
path: string;
|
|
63
|
+
source: string;
|
|
64
|
+
}, "none">;
|
|
65
|
+
export interface PublishConfiguration {
|
|
66
|
+
s3Path: string;
|
|
67
|
+
environment: 'dev' | 'prod';
|
|
68
|
+
}
|
|
69
|
+
export declare function deployS3({ environment, s3Path }: PublishConfiguration): Observable<never, "none">;
|
|
70
|
+
export {};
|
package/package.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUIRE_REPLACE = exports.BASEDIR = void 0;
|
|
4
|
+
exports.readPackage = readPackage;
|
|
5
|
+
exports.docs = docs;
|
|
6
|
+
exports.docgen = docgen;
|
|
7
|
+
exports.docgenTask = docgenTask;
|
|
8
|
+
exports.readme = readme;
|
|
9
|
+
exports.pkg = pkg;
|
|
10
|
+
exports.AMD = AMD;
|
|
11
|
+
exports.bundle = bundle;
|
|
12
|
+
exports.bundleAmd = bundleAmd;
|
|
13
|
+
exports.template = template;
|
|
14
|
+
exports.deployS3 = deployS3;
|
|
15
|
+
const rx_1 = require("@cxl/rx");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const file_js_1 = require("./file.js");
|
|
19
|
+
const child_process_1 = require("child_process");
|
|
20
|
+
const program_1 = require("@cxl/program");
|
|
21
|
+
const builder_js_1 = require("./builder.js");
|
|
22
|
+
const npm_js_1 = require("./npm.js");
|
|
23
|
+
const ts = require("typescript");
|
|
24
|
+
const SCRIPTDIR = process.cwd();
|
|
25
|
+
exports.BASEDIR = (0, child_process_1.execSync)(`npm prefix`, { cwd: SCRIPTDIR })
|
|
26
|
+
.toString()
|
|
27
|
+
.trim();
|
|
28
|
+
const LICENSE_MAP = {
|
|
29
|
+
'GPL-3.0': 'license-GPL-3.0.txt',
|
|
30
|
+
'GPL-3.0-only': 'license-GPL-3.0.txt',
|
|
31
|
+
'Apache-2.0': 'license-Apache-2.0.txt',
|
|
32
|
+
'SEE LICENSE IN LICENSE.txt': '',
|
|
33
|
+
UNLICENSED: '',
|
|
34
|
+
};
|
|
35
|
+
function verifyFields(fields, pkg) {
|
|
36
|
+
for (const f of fields)
|
|
37
|
+
if (!pkg[f])
|
|
38
|
+
throw new Error(`Field "${f}" missing in package.json`);
|
|
39
|
+
}
|
|
40
|
+
function readPackage(base = exports.BASEDIR) {
|
|
41
|
+
const pkg = base + '/package.json';
|
|
42
|
+
if (!(0, fs_1.existsSync)(pkg))
|
|
43
|
+
throw new Error('package.json not found');
|
|
44
|
+
const PACKAGE = JSON.parse((0, fs_1.readFileSync)(pkg, 'utf8'));
|
|
45
|
+
verifyFields(['name', 'version', 'description'], PACKAGE);
|
|
46
|
+
if (!PACKAGE.private)
|
|
47
|
+
verifyFields(['license'], PACKAGE);
|
|
48
|
+
return PACKAGE;
|
|
49
|
+
}
|
|
50
|
+
function docs(dirName, devMode = false) {
|
|
51
|
+
const docgen = (0, path_1.join)(__dirname, '../docgen');
|
|
52
|
+
return new rx_1.Observable(subs => {
|
|
53
|
+
const cmd = `node ${docgen} --clean ${devMode ? '--debug' : ''} -o ../docs/${dirName} --summary --markdown --cxlExtensions`;
|
|
54
|
+
console.log(cmd);
|
|
55
|
+
(0, program_1.sh)(cmd).then(out => (console.log(out), subs.complete()), e => subs.error(e));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async function docgen(options) {
|
|
59
|
+
const { name, tag, repo, file, setup, npm, tmpDir, typeRoots, scripts, sitemapBase, packageJson, docsJson, forceInstall, baseHref, rootDir, customJsDocTags, exports, summary, followReferences, cxlExtensions, headHtml, } = options;
|
|
60
|
+
const repodir = options.repodir ||
|
|
61
|
+
`${name.replace('/', '--')}-${tag.replace('/', '--')}`;
|
|
62
|
+
const dir = (0, path_1.join)(tmpDir || '', repodir, npm ? `/node_modules/${npm}` : ``);
|
|
63
|
+
const cwd = (0, path_1.join)(dir, options.cwd || '');
|
|
64
|
+
const outDir = (0, path_1.resolve)(options.outDir || 'docs');
|
|
65
|
+
const files = Array.isArray(file)
|
|
66
|
+
? file.map(f => `--file ${f}`).join(' ')
|
|
67
|
+
: `--tsconfig ${file}`;
|
|
68
|
+
const pkg = (0, path_1.join)(cwd, packageJson || 'package.json');
|
|
69
|
+
const install = repo
|
|
70
|
+
? `git clone ${repo} --branch=${tag} --depth=1 ${repodir};
|
|
71
|
+
cd ${repodir} ${setup ? `&& ${setup}` : ''}`
|
|
72
|
+
: `mkdir -p ${repodir} && npm install --prefix ./${repodir} ${npm}@${tag}`;
|
|
73
|
+
const DOCGEN = (0, path_1.join)(__dirname, '../docgen');
|
|
74
|
+
if (forceInstall)
|
|
75
|
+
await (0, program_1.sh)(`mkdir -p ${tmpDir} && cd ${tmpDir} && rm -rf ${repodir} && ${install}`);
|
|
76
|
+
else
|
|
77
|
+
await (0, program_1.sh)(`if [ ! -d "${dir}" ]; then
|
|
78
|
+
mkdir -p ${tmpDir} && cd ${tmpDir}
|
|
79
|
+
${install}
|
|
80
|
+
fi`);
|
|
81
|
+
const { description, version } = await (0, npm_js_1.readPackage)(pkg);
|
|
82
|
+
const sitemap = `${sitemapBase}/${name}/${version}/sitemap.xml`;
|
|
83
|
+
const outputDir = (0, path_1.join)(outDir, name);
|
|
84
|
+
console.log(cwd);
|
|
85
|
+
await (0, builder_js_1.run)(`node ${DOCGEN} ${files}`, {
|
|
86
|
+
packageJson,
|
|
87
|
+
docsJson,
|
|
88
|
+
scripts,
|
|
89
|
+
outputDir,
|
|
90
|
+
sitemap: sitemapBase ? `${sitemapBase}/${name}` : '',
|
|
91
|
+
summary: summary ?? true,
|
|
92
|
+
typeRoots,
|
|
93
|
+
packageName: name,
|
|
94
|
+
repository: repo?.startsWith('https')
|
|
95
|
+
? `${repo.replace(/.git$/, '')}/blob/${tag}${options.cwd ? `/${options.cwd}` : ''}`
|
|
96
|
+
: undefined,
|
|
97
|
+
markdown: true,
|
|
98
|
+
baseHref,
|
|
99
|
+
customJsDocTags,
|
|
100
|
+
rootDir,
|
|
101
|
+
exports,
|
|
102
|
+
followReferences,
|
|
103
|
+
cxlExtensions,
|
|
104
|
+
headHtml,
|
|
105
|
+
}, { cwd });
|
|
106
|
+
return { name, version, description, sitemap };
|
|
107
|
+
}
|
|
108
|
+
function docgenTask(packages, commonOptions) {
|
|
109
|
+
return (0, rx_1.fromAsync)(async () => {
|
|
110
|
+
const output = [];
|
|
111
|
+
for (const p of packages)
|
|
112
|
+
output.push(await docgen({
|
|
113
|
+
...commonOptions,
|
|
114
|
+
...p,
|
|
115
|
+
}));
|
|
116
|
+
return {
|
|
117
|
+
path: 'docgen.json',
|
|
118
|
+
source: Buffer.from(JSON.stringify(output)),
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function packageJson(p) {
|
|
123
|
+
return (0, rx_1.of)({
|
|
124
|
+
path: 'package.json',
|
|
125
|
+
source: Buffer.from(JSON.stringify({
|
|
126
|
+
name: p.name,
|
|
127
|
+
version: p.version,
|
|
128
|
+
description: p.description,
|
|
129
|
+
private: p.private,
|
|
130
|
+
license: p.license,
|
|
131
|
+
files: p.files || [
|
|
132
|
+
'*.js',
|
|
133
|
+
'*.d.ts',
|
|
134
|
+
'*.css',
|
|
135
|
+
'amd/*.js',
|
|
136
|
+
'amd/*.d.ts',
|
|
137
|
+
'mjs/*.js',
|
|
138
|
+
'mjs/*.d.ts',
|
|
139
|
+
'LICENSE',
|
|
140
|
+
'*.md',
|
|
141
|
+
],
|
|
142
|
+
main: p.main || 'index.js',
|
|
143
|
+
exports: p.exports,
|
|
144
|
+
browser: p.browser,
|
|
145
|
+
homepage: p.homepage,
|
|
146
|
+
bugs: p.bugs,
|
|
147
|
+
bin: p.bin,
|
|
148
|
+
repository: p.repository,
|
|
149
|
+
dependencies: p.dependencies,
|
|
150
|
+
peerDependencies: p.peerDependencies,
|
|
151
|
+
bundledDependencies: p.bundledDependencies,
|
|
152
|
+
type: p.type,
|
|
153
|
+
}, null, 2)),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function license(id) {
|
|
157
|
+
if (id === 'UNLICENSED' || id === 'SEE LICENSE IN LICENSE.txt')
|
|
158
|
+
return rx_1.EMPTY;
|
|
159
|
+
const licenseFile = LICENSE_MAP[id];
|
|
160
|
+
if (!licenseFile)
|
|
161
|
+
throw new Error(`Invalid license: "${id}"`);
|
|
162
|
+
return (0, file_js_1.file)((0, path_1.join)(__dirname, licenseFile), 'LICENSE');
|
|
163
|
+
}
|
|
164
|
+
function npmLink(pkgName, version) {
|
|
165
|
+
return `https://npmjs.com/package/${pkgName}/v/${version}`;
|
|
166
|
+
}
|
|
167
|
+
function readIfExists(file) {
|
|
168
|
+
try {
|
|
169
|
+
return (0, fs_1.readFileSync)(file, 'utf8');
|
|
170
|
+
}
|
|
171
|
+
catch (E) {
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Generate README file
|
|
177
|
+
*/
|
|
178
|
+
function readme() {
|
|
179
|
+
return (0, rx_1.defer)(() => {
|
|
180
|
+
const pkg = readPackage(exports.BASEDIR);
|
|
181
|
+
const extra = readIfExists('USAGE.md');
|
|
182
|
+
const encodedName = encodeURIComponent(pkg.name);
|
|
183
|
+
return (0, rx_1.of)({
|
|
184
|
+
path: 'README.md',
|
|
185
|
+
source: Buffer.from(`# ${pkg.name}
|
|
186
|
+
|
|
187
|
+
[](https://badge.fury.io/js/${encodedName})
|
|
188
|
+
|
|
189
|
+
${pkg.description}
|
|
190
|
+
|
|
191
|
+
## Project Details
|
|
192
|
+
|
|
193
|
+
- Branch Version: [${pkg.version}](${npmLink(pkg.name, pkg.version)})
|
|
194
|
+
- License: ${pkg.license}
|
|
195
|
+
- Documentation: [Link](${pkg.homepage})
|
|
196
|
+
- Report Issues: [Github](${pkg.bugs})
|
|
197
|
+
|
|
198
|
+
## Installation
|
|
199
|
+
|
|
200
|
+
npm install ${pkg.name}
|
|
201
|
+
|
|
202
|
+
${extra}`),
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function pkg() {
|
|
207
|
+
return (0, rx_1.defer)(() => {
|
|
208
|
+
const p = readPackage();
|
|
209
|
+
const licenseId = p.license;
|
|
210
|
+
const output = [packageJson(p)];
|
|
211
|
+
output.push((0, file_js_1.file)('README.md', 'README.md'));
|
|
212
|
+
if (licenseId)
|
|
213
|
+
output.push(license(licenseId));
|
|
214
|
+
return (0, rx_1.merge)(...output);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function createBundle(files, resolvedFiles, content, outFile, config) {
|
|
218
|
+
const options = {
|
|
219
|
+
lib: ['lib.es2017.d.ts'],
|
|
220
|
+
target: ts.ScriptTarget.ES2019,
|
|
221
|
+
module: ts.ModuleKind.AMD,
|
|
222
|
+
allowJs: true,
|
|
223
|
+
declaration: false,
|
|
224
|
+
baseUrl: process.cwd(),
|
|
225
|
+
outDir: process.cwd(),
|
|
226
|
+
outFile: outFile,
|
|
227
|
+
removeComments: true,
|
|
228
|
+
isolatedModules: true,
|
|
229
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
230
|
+
sourceMap: false,
|
|
231
|
+
...config,
|
|
232
|
+
};
|
|
233
|
+
const host = ts.createCompilerHost(options);
|
|
234
|
+
const oldGetSourceFile = host.getSourceFile;
|
|
235
|
+
const sourceFiles = [];
|
|
236
|
+
host.getSourceFile = function (fn, target) {
|
|
237
|
+
const i = resolvedFiles.indexOf(fn);
|
|
238
|
+
if (i !== -1) {
|
|
239
|
+
const sf = ts.createSourceFile(resolvedFiles[i], content[i], target);
|
|
240
|
+
sf.moduleName = files[i];
|
|
241
|
+
sourceFiles.push(sf);
|
|
242
|
+
return sf;
|
|
243
|
+
}
|
|
244
|
+
return oldGetSourceFile.apply(this, arguments);
|
|
245
|
+
};
|
|
246
|
+
const program = ts.createProgram(resolvedFiles, options, host);
|
|
247
|
+
let source = '';
|
|
248
|
+
program.emit(undefined, (_a, b) => (source += b));
|
|
249
|
+
return {
|
|
250
|
+
path: outFile,
|
|
251
|
+
source: Buffer.from(source),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function AMD() {
|
|
255
|
+
return (0, rx_1.defer)(() => (0, rx_1.of)({
|
|
256
|
+
path: 'amd.js',
|
|
257
|
+
source: (0, fs_1.readFileSync)(__dirname + '/amd.js'),
|
|
258
|
+
}));
|
|
259
|
+
}
|
|
260
|
+
function bundle(files, outFile, config) {
|
|
261
|
+
return new rx_1.Observable(subs => {
|
|
262
|
+
const moduleNames = Object.keys(files);
|
|
263
|
+
const resolvedFiles = Object.values(files);
|
|
264
|
+
Promise.all(resolvedFiles.map(f => fs_1.promises.readFile(f, 'utf8')))
|
|
265
|
+
.then(content => {
|
|
266
|
+
subs.next(createBundle(moduleNames, resolvedFiles, content, outFile, config));
|
|
267
|
+
subs.complete();
|
|
268
|
+
})
|
|
269
|
+
.catch(e => subs.error(e));
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
function bundleAmd(files, outFile) {
|
|
273
|
+
return new rx_1.Observable(subs => {
|
|
274
|
+
const result = [];
|
|
275
|
+
const moduleNames = Object.keys(files);
|
|
276
|
+
const resolvedFiles = Object.values(files);
|
|
277
|
+
Promise.all(resolvedFiles.map(f => fs_1.promises.readFile(f, 'utf8'))).then(content => {
|
|
278
|
+
moduleNames.forEach((mod, i) => {
|
|
279
|
+
result.push(`define("${mod}", ["require", "exports"], function (require, exports) {\n${content[i]}\n})`);
|
|
280
|
+
});
|
|
281
|
+
subs.next({
|
|
282
|
+
path: outFile,
|
|
283
|
+
source: Buffer.from(result.join('\n')),
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
exports.REQUIRE_REPLACE = `
|
|
289
|
+
require.replace = function (path) {
|
|
290
|
+
return path.replace(
|
|
291
|
+
/^@cxl\\/workspace\\.(.+)/,
|
|
292
|
+
(str, p1) =>
|
|
293
|
+
\`/cxl.app/dist/\${str.endsWith('.js') ? p1 : p1 + '/index.js'}\`
|
|
294
|
+
).replace(
|
|
295
|
+
/^@cxl\\/(ui.*)/,
|
|
296
|
+
(str, p1) =>
|
|
297
|
+
\`/ui/dist/\${str.endsWith('.js') ? p1 : p1 + '/index.js'}\`
|
|
298
|
+
).replace(
|
|
299
|
+
/^@cxl\\/(.+)/,
|
|
300
|
+
(str, p1) =>
|
|
301
|
+
\`/cxl/dist/\${str.endsWith('.js') ? p1 : p1 + '/index.js'}\`
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
`;
|
|
305
|
+
const INDEX_HEAD = `<!DOCTYPE html><meta charset="utf-8"><script src="index.bundle.min.js"></script>`;
|
|
306
|
+
const DEBUG_HEAD = `<!DOCTYPE html><meta charset="utf-8">
|
|
307
|
+
<script src="/cxl/dist/tester/require-browser.js"></script>
|
|
308
|
+
<script>
|
|
309
|
+
window.CXL_DEBUG = true;
|
|
310
|
+
${exports.REQUIRE_REPLACE}
|
|
311
|
+
require('@cxl/ui');
|
|
312
|
+
require('@cxl/ui-router');
|
|
313
|
+
require('@cxl/router/debug.js');
|
|
314
|
+
</script>
|
|
315
|
+
`;
|
|
316
|
+
const DefaultTemplateConfig = {
|
|
317
|
+
header: INDEX_HEAD,
|
|
318
|
+
debugHeader: DEBUG_HEAD,
|
|
319
|
+
};
|
|
320
|
+
const HTML_COMMENT_REGEX = /<!--[^]+?-->/gm;
|
|
321
|
+
function template(filename, config = {}) {
|
|
322
|
+
return (0, file_js_1.file)(filename).switchMap(({ source }) => {
|
|
323
|
+
const prodSource = source
|
|
324
|
+
.toString('utf8')
|
|
325
|
+
.replace(HTML_COMMENT_REGEX, '');
|
|
326
|
+
const cfg = { ...DefaultTemplateConfig, ...config };
|
|
327
|
+
return (0, rx_1.from)([
|
|
328
|
+
{ path: 'index.html', source: `${cfg.header}\n${prodSource}` },
|
|
329
|
+
{ path: 'debug.html', source: `${cfg.debugHeader}\n${source}` },
|
|
330
|
+
]);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function deployS3({ environment, s3Path }) {
|
|
334
|
+
if (environment !== 'dev' && environment !== 'prod')
|
|
335
|
+
throw new Error(`Invalid environment ${environment}`);
|
|
336
|
+
return (0, builder_js_1.exec)(`aws s3 sync --dryrun --cache-control max-age=60 --content-encoding=utf8 --delete ../dist/debuggerjs.com s3://${s3Path}`);
|
|
337
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cxl/build",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"bin": {
|
|
5
|
+
"cxl-build": "index.js"
|
|
6
|
+
},
|
|
7
|
+
"description": "Build Tool",
|
|
8
|
+
"license": "GPL-3.0",
|
|
9
|
+
"main": "index.js",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build-index": "tsc -b && tsc -b tsconfig.amd.json",
|
|
12
|
+
"build-test": "tsc -b tsconfig.test.json",
|
|
13
|
+
"build": "node build.mjs",
|
|
14
|
+
"test": "npm run build && cd ../dist/build && node ../tester --node"
|
|
15
|
+
},
|
|
5
16
|
"dependencies": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
17
|
+
"eslint": "^8.56.0",
|
|
18
|
+
"terser": "^5.16.1",
|
|
19
|
+
"typescript": "^5.5.3",
|
|
20
|
+
"@cxl/rx": "~0.8.0",
|
|
21
|
+
"@cxl/source": "~0.0.2",
|
|
22
|
+
"@cxl/amd": "~0.0.1",
|
|
23
|
+
"@cxl/program": "~0.0.3"
|
|
24
|
+
},
|
|
25
|
+
"bugs": "https://github.com/cxlio/cxl/issues",
|
|
26
|
+
"homepage": "https://cxlio.github.io/cxl/build",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/cxlio/cxl.git",
|
|
30
|
+
"directory": "build"
|
|
8
31
|
}
|
|
9
32
|
}
|