@cxl/build 0.2.1 → 1.0.0-beta.2
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 +17 -0
- package/builder.d.ts +9 -4
- package/chunk-BJVTLF6O.js +4 -0
- package/chunk-FSRPMVAS.js +1 -0
- package/chunk-ZNHDZJVN.js +24 -0
- package/eslint-config.d.ts +2 -0
- package/eslint-config.js +28 -0
- package/file.d.ts +9 -17
- package/git.d.ts +2 -1
- package/index.bundle.js +2 -0
- package/index.d.ts +3 -7
- package/library-FGC5CGCE.js +1 -0
- package/library.d.ts +2 -0
- package/lint.d.ts +4 -3
- package/npm.d.ts +6 -3
- package/package.d.ts +5 -60
- package/package.json +31 -31
- package/png-BPHNXF4V.js +1 -0
- package/render-html-WNP2FSL3-HEUQV5A2.js +26 -0
- package/render-summary-ULILIVXW-MBBMA5KL.js +1 -0
- package/test.d.ts +1 -1
- package/tsc.d.ts +7 -8
- package/amd-static.d.ts +0 -0
- package/amd-static.js +0 -56
- package/amd-static.tsbuildinfo +0 -1
- package/amd.js +0 -120
- package/builder.js +0 -130
- package/cxl.d.ts +0 -5
- package/cxl.js +0 -192
- package/file.js +0 -136
- package/git.js +0 -25
- package/index.js +0 -40
- package/license-Apache-2.0.txt +0 -202
- package/lint.js +0 -41
- package/npm.js +0 -72
- package/package.js +0 -337
- package/test-report.html +0 -1200
- package/test-report.json +0 -1
- package/test.js +0 -17
- package/tsc.js +0 -173
- package/tsconfig.amd.json +0 -1
- package/tsconfig.test.tsbuildinfo +0 -1
- package/tsconfig.tsbuildinfo +0 -1
- /package/{license-GPL-3.0.txt → LICENSE} +0 -0
package/package.js
DELETED
|
@@ -1,337 +0,0 @@
|
|
|
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
|
-
}
|