@cxl/build 0.2.1 → 1.0.0-beta.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/README.md +17 -0
- package/builder.d.ts +9 -4
- package/chunk-ZYWVDQ3W.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-MSWYOSE7.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 +30 -31
- 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/amd.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
((window) => {
|
|
3
|
-
const __require = window.process ? require : undefined;
|
|
4
|
-
const define = (window.define || (window.define = _define));
|
|
5
|
-
const modules = (_require.modules = define.modules = define.modules || {});
|
|
6
|
-
const modulePromise = {};
|
|
7
|
-
const BASENAME_REGEX = /\/?([^/]+)$/;
|
|
8
|
-
const windowRequire = (window.require || _require);
|
|
9
|
-
function dirname(path) {
|
|
10
|
-
return path.replace(BASENAME_REGEX, '');
|
|
11
|
-
}
|
|
12
|
-
function normalize(path, basePath) {
|
|
13
|
-
return new URL(basePath + '/' + (path.endsWith('.js') ? path : `${path}.js`), 'https://localhost').pathname.slice(1);
|
|
14
|
-
}
|
|
15
|
-
function tryRequire(path) {
|
|
16
|
-
try {
|
|
17
|
-
return __require?.(path);
|
|
18
|
-
}
|
|
19
|
-
catch (e) {
|
|
20
|
-
// Ignore Error, try async
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async function _requireAsync(path) {
|
|
24
|
-
await Promise.resolve();
|
|
25
|
-
const mod = modules[path] || modulePromise[path] || tryRequire(path);
|
|
26
|
-
if (mod)
|
|
27
|
-
return mod;
|
|
28
|
-
const modulePath = windowRequire.replace
|
|
29
|
-
? windowRequire.replace(path)
|
|
30
|
-
: path;
|
|
31
|
-
return (modulePromise[path] = _import(modulePath, path));
|
|
32
|
-
}
|
|
33
|
-
function _require(path, resolve, reject, basePath) {
|
|
34
|
-
let actualPath = Array.isArray(path) ? path[0] : path;
|
|
35
|
-
let mod = modules[actualPath] || tryRequire(actualPath);
|
|
36
|
-
if (!mod) {
|
|
37
|
-
if (basePath)
|
|
38
|
-
actualPath = normalize(actualPath, basePath);
|
|
39
|
-
mod = _requireAsync(actualPath);
|
|
40
|
-
}
|
|
41
|
-
if (resolve) {
|
|
42
|
-
if (mod instanceof Promise)
|
|
43
|
-
mod.then(resolve, reject);
|
|
44
|
-
else
|
|
45
|
-
resolve(mod);
|
|
46
|
-
}
|
|
47
|
-
return mod;
|
|
48
|
-
}
|
|
49
|
-
function defineAsync(name, injects, module) {
|
|
50
|
-
let isAsync = false;
|
|
51
|
-
const moduleExports = {};
|
|
52
|
-
const args = [];
|
|
53
|
-
function resolve(newargs) {
|
|
54
|
-
const hasModule = !!window.module;
|
|
55
|
-
const mod = (window.module = {
|
|
56
|
-
exports: moduleExports,
|
|
57
|
-
});
|
|
58
|
-
const result = module(...newargs);
|
|
59
|
-
const resultMod = (modules[name] =
|
|
60
|
-
result || mod.exports || moduleExports);
|
|
61
|
-
delete modulePromise[name];
|
|
62
|
-
if (hasModule)
|
|
63
|
-
delete window.module;
|
|
64
|
-
return resultMod;
|
|
65
|
-
}
|
|
66
|
-
function findModule(modname) {
|
|
67
|
-
if (modname === 'exports')
|
|
68
|
-
return moduleExports;
|
|
69
|
-
if (modname === 'require')
|
|
70
|
-
return _require;
|
|
71
|
-
if (modname.startsWith('.'))
|
|
72
|
-
return _require(modname, undefined, undefined, dirname(name));
|
|
73
|
-
return _require(modname);
|
|
74
|
-
}
|
|
75
|
-
for (const inject of injects) {
|
|
76
|
-
const mod = findModule(inject);
|
|
77
|
-
if (mod instanceof Promise)
|
|
78
|
-
isAsync = true;
|
|
79
|
-
args.push(mod);
|
|
80
|
-
}
|
|
81
|
-
return isAsync ? Promise.all(args).then(resolve) : resolve(args);
|
|
82
|
-
}
|
|
83
|
-
function defineNormalized(name, injects, module) {
|
|
84
|
-
if (!modules[name])
|
|
85
|
-
modulePromise[name] = defineAsync(name, injects, module);
|
|
86
|
-
else
|
|
87
|
-
throw new Error(`Module "${name}" already defined`);
|
|
88
|
-
}
|
|
89
|
-
function _define(name, injects, module) {
|
|
90
|
-
if (Array.isArray(name) && injects && !Array.isArray(injects)) {
|
|
91
|
-
defineNormalized(define.moduleName, name, injects);
|
|
92
|
-
}
|
|
93
|
-
else if (typeof name === 'function') {
|
|
94
|
-
defineNormalized(define.moduleName, [], name);
|
|
95
|
-
}
|
|
96
|
-
else if (typeof name === 'string' && Array.isArray(injects) && module)
|
|
97
|
-
defineNormalized(name, injects, module);
|
|
98
|
-
else
|
|
99
|
-
throw new Error('Invalid define');
|
|
100
|
-
}
|
|
101
|
-
function _import(url, moduleName) {
|
|
102
|
-
return fetch(url)
|
|
103
|
-
.then(res => (res.status === 200 ? res.text() : ''))
|
|
104
|
-
.then(__src => {
|
|
105
|
-
if (!__src)
|
|
106
|
-
return (modules[moduleName] = {});
|
|
107
|
-
define.moduleName = moduleName;
|
|
108
|
-
delete modulePromise[moduleName];
|
|
109
|
-
define.eval(`${__src}\n//# sourceURL=${moduleName}`);
|
|
110
|
-
return modules[moduleName] ?? modulePromise[moduleName] ?? {};
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (typeof window.require !== 'undefined')
|
|
114
|
-
_require.resolve = window.require.resolve;
|
|
115
|
-
window.require = window.require || _require;
|
|
116
|
-
_define.amd = true;
|
|
117
|
-
})(typeof self === 'undefined' ? global : self);
|
|
118
|
-
define.eval || (define.eval = function (__source) {
|
|
119
|
-
eval(__source);
|
|
120
|
-
});
|
package/builder.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appLog = void 0;
|
|
4
|
-
exports.build = build;
|
|
5
|
-
exports.exec = exec;
|
|
6
|
-
exports.shell = shell;
|
|
7
|
-
exports.run = run;
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const child_process_1 = require("child_process");
|
|
11
|
-
const program_1 = require("@cxl/program");
|
|
12
|
-
const rx_1 = require("@cxl/rx");
|
|
13
|
-
const tsc_js_1 = require("./tsc.js");
|
|
14
|
-
const package_js_1 = require("./package.js");
|
|
15
|
-
const AppName = program_1.colors.green('build');
|
|
16
|
-
exports.appLog = program_1.log.bind(null, AppName);
|
|
17
|
-
function kb(bytes) {
|
|
18
|
-
return (bytes / 1000).toFixed(2) + 'kb';
|
|
19
|
-
}
|
|
20
|
-
class Build {
|
|
21
|
-
constructor(log, config) {
|
|
22
|
-
this.log = log;
|
|
23
|
-
this.config = config;
|
|
24
|
-
this.outputDir = config.outputDir || '.';
|
|
25
|
-
}
|
|
26
|
-
async runTask(task) {
|
|
27
|
-
await task.tap(result => {
|
|
28
|
-
const outFile = (0, path_1.resolve)(this.outputDir, result.path);
|
|
29
|
-
const source = result.source;
|
|
30
|
-
const outputDir = (0, path_1.dirname)(outFile);
|
|
31
|
-
if (!(0, fs_1.existsSync)(outputDir))
|
|
32
|
-
(0, child_process_1.execSync)(`mkdir -p ${outputDir}`);
|
|
33
|
-
(0, fs_1.writeFileSync)(outFile, source);
|
|
34
|
-
if (result.mtime)
|
|
35
|
-
(0, fs_1.utimesSync)(outFile, result.mtime, result.mtime);
|
|
36
|
-
const printPath = (0, path_1.relative)(process.cwd(), outFile);
|
|
37
|
-
this.log(`${printPath} ${kb((result.source || '').length)}`);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
async build() {
|
|
41
|
-
try {
|
|
42
|
-
const target = this.config.target || '';
|
|
43
|
-
if (target)
|
|
44
|
-
this.log(`target ${target}`);
|
|
45
|
-
(0, child_process_1.execSync)(`mkdir -p ${this.outputDir}`);
|
|
46
|
-
await Promise.all(this.config.tasks.map(task => this.runTask(task)));
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.log('BUILD: ', e);
|
|
50
|
-
throw 'Build finished with errors';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async function build(...targets) {
|
|
55
|
-
if (!targets)
|
|
56
|
-
throw new Error('Invalid configuration');
|
|
57
|
-
if (package_js_1.BASEDIR !== process.cwd()) {
|
|
58
|
-
process.chdir(package_js_1.BASEDIR);
|
|
59
|
-
(0, exports.appLog)(`chdir "${package_js_1.BASEDIR}"`);
|
|
60
|
-
}
|
|
61
|
-
const pkg = (0, package_js_1.readPackage)();
|
|
62
|
-
(0, exports.appLog)(`${pkg.name} ${pkg.version}`);
|
|
63
|
-
(0, exports.appLog)(`typescript ${tsc_js_1.tscVersion}`);
|
|
64
|
-
const runTargets = [undefined, ...process.argv];
|
|
65
|
-
try {
|
|
66
|
-
for (const targetId of runTargets) {
|
|
67
|
-
for (const target of targets)
|
|
68
|
-
if (target.target === targetId)
|
|
69
|
-
await new Build(exports.appLog, target).build();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
console.error(e);
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function formatTime(time) {
|
|
78
|
-
const s = Number(time) / 1e9, str = s.toFixed(4) + 's';
|
|
79
|
-
// Color code based on time,
|
|
80
|
-
return s > 0.1 ? (s > 0.5 ? program_1.colors.red(str) : program_1.colors.yellow(str)) : str;
|
|
81
|
-
}
|
|
82
|
-
function exec(cmd) {
|
|
83
|
-
return new rx_1.Observable(subs => {
|
|
84
|
-
(0, exports.appLog)(`sh ${cmd}`);
|
|
85
|
-
(0, program_1.operation)((0, program_1.sh)(cmd, {})).then(result => {
|
|
86
|
-
(0, exports.appLog)(`sh ${cmd}`, formatTime(result.time));
|
|
87
|
-
if (result.result)
|
|
88
|
-
console.log(result.result);
|
|
89
|
-
subs.complete();
|
|
90
|
-
}, e => {
|
|
91
|
-
subs.error(e);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function shell(cmd, options = {}) {
|
|
96
|
-
return new rx_1.Observable(subs => {
|
|
97
|
-
const proc = (0, child_process_1.spawn)(cmd, [], { shell: true, ...options });
|
|
98
|
-
let output;
|
|
99
|
-
let error;
|
|
100
|
-
proc.stdout?.on('data', data => (output = output
|
|
101
|
-
? Buffer.concat([output, Buffer.from(data)])
|
|
102
|
-
: Buffer.from(data)));
|
|
103
|
-
proc.stderr?.on('data', data => (error = error
|
|
104
|
-
? Buffer.concat([error, Buffer.from(data)])
|
|
105
|
-
: Buffer.from(data)));
|
|
106
|
-
proc.on('close', code => {
|
|
107
|
-
if (code)
|
|
108
|
-
subs.error(error || output);
|
|
109
|
-
else {
|
|
110
|
-
subs.next(output);
|
|
111
|
-
subs.complete();
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function run(cmd, params, options) {
|
|
117
|
-
const args = [cmd];
|
|
118
|
-
for (const p in params) {
|
|
119
|
-
const val = params[p];
|
|
120
|
-
if (val === false || val === undefined)
|
|
121
|
-
continue;
|
|
122
|
-
if (Array.isArray(val)) {
|
|
123
|
-
val.forEach(v => args.push(`--${p} "${v}"`));
|
|
124
|
-
}
|
|
125
|
-
else
|
|
126
|
-
args.push(typeof val === 'boolean' ? `--${p}` : `--${p} "${val}"`);
|
|
127
|
-
}
|
|
128
|
-
console.log(args.join(' '));
|
|
129
|
-
return (0, program_1.sh)(args.join(' '), options);
|
|
130
|
-
}
|
package/cxl.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Output } from '@cxl/source';
|
|
2
|
-
import { BuildConfiguration } from './builder.js';
|
|
3
|
-
export declare function minifyIf(filename: string): (source: import("@cxl/rx").Observable<Output, "none">) => import("@cxl/rx").Observable<Output, "none">;
|
|
4
|
-
export declare function generateTestFile(dirName: string, pkgName: string, testFile: string): string;
|
|
5
|
-
export declare function buildCxl(...extra: BuildConfiguration[]): Promise<void>;
|
package/cxl.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.minifyIf = minifyIf;
|
|
4
|
-
exports.generateTestFile = generateTestFile;
|
|
5
|
-
exports.buildCxl = buildCxl;
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const child_process_1 = require("child_process");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const rx_1 = require("@cxl/rx");
|
|
10
|
-
const builder_js_1 = require("./builder.js");
|
|
11
|
-
const package_js_1 = require("./package.js");
|
|
12
|
-
const file_js_1 = require("./file.js");
|
|
13
|
-
const lint_js_1 = require("./lint.js");
|
|
14
|
-
const tsc_js_1 = require("./tsc.js");
|
|
15
|
-
function minifyIf(filename) {
|
|
16
|
-
return (0, rx_1.mergeMap)((out) => out.path === filename
|
|
17
|
-
? (0, rx_1.concat)((0, rx_1.of)(out), (0, file_js_1.file)(out.path).pipe((0, file_js_1.minify)()))
|
|
18
|
-
: (0, rx_1.of)(out));
|
|
19
|
-
}
|
|
20
|
-
function generateTestFile(dirName, pkgName, testFile) {
|
|
21
|
-
return `<!DOCTYPE html>
|
|
22
|
-
<title>${pkgName} Test Suite</title>
|
|
23
|
-
<script type="module" src="/cxl/dist/tester/require-browser.js"></script>
|
|
24
|
-
<script type="module">
|
|
25
|
-
require.replace = function (path) {
|
|
26
|
-
return path.replace(
|
|
27
|
-
/^@j5g3\\/(.+)/,
|
|
28
|
-
(str, p1) =>
|
|
29
|
-
\`/j5g3/dist/\${str.endsWith('.js') ? p1 : p1 + '/index.js'}\`
|
|
30
|
-
)
|
|
31
|
-
.replace(
|
|
32
|
-
/^@cxl\\/workspace\\.(.+)/,
|
|
33
|
-
(str, p1) =>
|
|
34
|
-
\`/cxl.app/dist/$\{
|
|
35
|
-
str.endsWith('.js') ? p1 : p1 + '/index.js'
|
|
36
|
-
}\`
|
|
37
|
-
)
|
|
38
|
-
.replace(
|
|
39
|
-
/^@cxl\\/gbc\.(.*)/,
|
|
40
|
-
(str, p1) =>
|
|
41
|
-
\`/gbc/dist/$\{
|
|
42
|
-
str.endsWith('.js') ? p1 : p1 + '/index.js'
|
|
43
|
-
}\`
|
|
44
|
-
)
|
|
45
|
-
.replace(
|
|
46
|
-
/^@cxl\\/(ui.*)/,
|
|
47
|
-
(str, p1) =>
|
|
48
|
-
\`/ui/dist/$\{
|
|
49
|
-
str.endsWith('.js') ? p1 : p1 + '/index.js'
|
|
50
|
-
}\`
|
|
51
|
-
)
|
|
52
|
-
.replace(
|
|
53
|
-
/^@cxl\\/(.+)/,
|
|
54
|
-
(str, p1) =>
|
|
55
|
-
\`/cxl/dist/$\{
|
|
56
|
-
str.endsWith('.js') ? p1 : p1 + '/index.js'
|
|
57
|
-
}\`
|
|
58
|
-
);
|
|
59
|
-
};
|
|
60
|
-
const browserRunner = require('/cxl/dist/tester/browser-runner.js').default;
|
|
61
|
-
|
|
62
|
-
const suite = require('${testFile}').default;
|
|
63
|
-
browserRunner.run([suite], '../../${dirName}/spec');
|
|
64
|
-
</script>`;
|
|
65
|
-
}
|
|
66
|
-
function buildCxl(...extra) {
|
|
67
|
-
const packageJson = (0, package_js_1.readPackage)();
|
|
68
|
-
const cwd = process.cwd();
|
|
69
|
-
const tsconfigFile = require(cwd + '/tsconfig.json');
|
|
70
|
-
const outputDir = tsconfigFile?.compilerOptions?.outDir;
|
|
71
|
-
if (!outputDir)
|
|
72
|
-
throw new Error('No outDir field set in tsconfig.json');
|
|
73
|
-
const dirName = (0, path_1.basename)(outputDir);
|
|
74
|
-
const tester = (0, path_1.join)(__dirname, '../tester');
|
|
75
|
-
const isBrowser = !!packageJson.browser;
|
|
76
|
-
return (0, builder_js_1.build)({
|
|
77
|
-
target: 'clean',
|
|
78
|
-
outputDir,
|
|
79
|
-
tasks: [
|
|
80
|
-
(0, rx_1.observable)(() => {
|
|
81
|
-
(0, child_process_1.execSync)(`rm -rf ${outputDir}`);
|
|
82
|
-
}),
|
|
83
|
-
],
|
|
84
|
-
}, {
|
|
85
|
-
outputDir,
|
|
86
|
-
tasks: [
|
|
87
|
-
(0, file_js_1.file)('index.html', 'index.html').catchError(() => rx_1.EMPTY),
|
|
88
|
-
(0, file_js_1.file)('debug.html', 'debug.html').catchError(() => rx_1.EMPTY),
|
|
89
|
-
(0, file_js_1.file)('stage.html', 'stage.html').catchError(() => rx_1.EMPTY),
|
|
90
|
-
(0, file_js_1.file)('icons.svg', 'icons.svg').catchError(() => rx_1.EMPTY),
|
|
91
|
-
(0, file_js_1.file)('favicon.ico', 'favicon.ico').catchError(() => rx_1.EMPTY),
|
|
92
|
-
(0, file_js_1.file)('test.html', 'test.html').catchError(() => (0, rx_1.of)({
|
|
93
|
-
path: 'test.html',
|
|
94
|
-
source: Buffer.from(generateTestFile(dirName, packageJson.name, './test.js')),
|
|
95
|
-
})),
|
|
96
|
-
(0, tsc_js_1.tsconfig)('tsconfig.test.json'),
|
|
97
|
-
],
|
|
98
|
-
}, {
|
|
99
|
-
target: 'test',
|
|
100
|
-
outputDir,
|
|
101
|
-
tasks: [
|
|
102
|
-
(0, builder_js_1.exec)(`cd ${outputDir} && node ${tester} --baselinePath=../../${dirName}/spec${isBrowser ? '' : ' --node'}`),
|
|
103
|
-
],
|
|
104
|
-
}, {
|
|
105
|
-
target: 'package',
|
|
106
|
-
outputDir: '.',
|
|
107
|
-
tasks: [(0, package_js_1.readme)()],
|
|
108
|
-
}, {
|
|
109
|
-
target: 'package',
|
|
110
|
-
outputDir,
|
|
111
|
-
tasks: [
|
|
112
|
-
(0, lint_js_1.eslint)(),
|
|
113
|
-
packageJson.browser
|
|
114
|
-
? (0, file_js_1.file)(`${outputDir}/index.js`).pipe((0, file_js_1.minify)())
|
|
115
|
-
: rx_1.EMPTY,
|
|
116
|
-
(0, package_js_1.pkg)(),
|
|
117
|
-
],
|
|
118
|
-
}, ...((0, fs_1.existsSync)('tsconfig.amd.json')
|
|
119
|
-
? [
|
|
120
|
-
{
|
|
121
|
-
target: 'package',
|
|
122
|
-
outputDir: outputDir + '/amd',
|
|
123
|
-
tasks: [
|
|
124
|
-
(0, rx_1.concat)((0, tsc_js_1.tsconfig)('tsconfig.amd.json'), (0, file_js_1.minifyDir)(outputDir + '/amd', {
|
|
125
|
-
sourceMap: false,
|
|
126
|
-
changePath: false,
|
|
127
|
-
})),
|
|
128
|
-
],
|
|
129
|
-
},
|
|
130
|
-
]
|
|
131
|
-
: []), ...((0, fs_1.existsSync)('tsconfig.mjs.json')
|
|
132
|
-
? [
|
|
133
|
-
{
|
|
134
|
-
target: 'package',
|
|
135
|
-
outputDir: outputDir + '/mjs',
|
|
136
|
-
tasks: [
|
|
137
|
-
(0, rx_1.concat)((0, tsc_js_1.tsconfig)('tsconfig.mjs.json'), (0, file_js_1.minifyDir)(outputDir + '/mjs', {
|
|
138
|
-
sourceMap: false,
|
|
139
|
-
changePath: false,
|
|
140
|
-
})),
|
|
141
|
-
],
|
|
142
|
-
},
|
|
143
|
-
]
|
|
144
|
-
: []), ...((0, fs_1.existsSync)('tsconfig.api.json')
|
|
145
|
-
? [
|
|
146
|
-
{
|
|
147
|
-
outputDir: outputDir,
|
|
148
|
-
tasks: [
|
|
149
|
-
(0, tsc_js_1.tsconfig)('tsconfig.api.json', {
|
|
150
|
-
sourceMap: false,
|
|
151
|
-
})
|
|
152
|
-
.filter(({ path }) => path.endsWith('.js'))
|
|
153
|
-
.pipe((0, file_js_1.concatFile)('server.js')),
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
]
|
|
157
|
-
: []), ...((0, fs_1.existsSync)('tsconfig.server.json')
|
|
158
|
-
? [
|
|
159
|
-
{
|
|
160
|
-
outputDir: outputDir,
|
|
161
|
-
tasks: [(0, tsc_js_1.tsconfig)('tsconfig.server.json')],
|
|
162
|
-
},
|
|
163
|
-
]
|
|
164
|
-
: []), ...((0, fs_1.existsSync)('tsconfig.worker.json')
|
|
165
|
-
? [
|
|
166
|
-
{
|
|
167
|
-
outputDir: outputDir,
|
|
168
|
-
tasks: [
|
|
169
|
-
(0, tsc_js_1.tsconfig)('tsconfig.worker.json', undefined, outputDir),
|
|
170
|
-
],
|
|
171
|
-
},
|
|
172
|
-
]
|
|
173
|
-
: []), ...((0, fs_1.existsSync)('tsconfig.bundle.json')
|
|
174
|
-
? [
|
|
175
|
-
{
|
|
176
|
-
target: 'package',
|
|
177
|
-
outputDir: outputDir,
|
|
178
|
-
tasks: [
|
|
179
|
-
(0, rx_1.concat)((0, tsc_js_1.tsconfig)('tsconfig.bundle.json'), (0, file_js_1.file)(`${outputDir}/index.bundle.js`).pipe((0, file_js_1.minify)({ changePath: false }))),
|
|
180
|
-
],
|
|
181
|
-
},
|
|
182
|
-
]
|
|
183
|
-
: []), {
|
|
184
|
-
target: 'docs-dev',
|
|
185
|
-
outputDir: '.',
|
|
186
|
-
tasks: [(0, package_js_1.docs)(dirName, true)],
|
|
187
|
-
}, ...extra, {
|
|
188
|
-
target: 'docs',
|
|
189
|
-
outputDir: '.',
|
|
190
|
-
tasks: [(0, package_js_1.docs)(dirName)],
|
|
191
|
-
});
|
|
192
|
-
}
|
package/file.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MinifyDefault = void 0;
|
|
4
|
-
exports.ls = ls;
|
|
5
|
-
exports.read = read;
|
|
6
|
-
exports.filterPath = filterPath;
|
|
7
|
-
exports.file = file;
|
|
8
|
-
exports.basename = basename;
|
|
9
|
-
exports.concatFile = concatFile;
|
|
10
|
-
exports.files = files;
|
|
11
|
-
exports.matchStat = matchStat;
|
|
12
|
-
exports.copyDir = copyDir;
|
|
13
|
-
exports.getSourceMap = getSourceMap;
|
|
14
|
-
exports.minify = minify;
|
|
15
|
-
exports.minifyDir = minifyDir;
|
|
16
|
-
exports.zip = zip;
|
|
17
|
-
const Terser = require("terser");
|
|
18
|
-
const rx_1 = require("@cxl/rx");
|
|
19
|
-
const fs_1 = require("fs");
|
|
20
|
-
const path_1 = require("path");
|
|
21
|
-
const builder_js_1 = require("./builder.js");
|
|
22
|
-
function ls(dir) {
|
|
23
|
-
return new rx_1.Observable(async (subs) => {
|
|
24
|
-
const files = await fs_1.promises.readdir(dir);
|
|
25
|
-
for (const path of files)
|
|
26
|
-
subs.next((0, path_1.resolve)(dir, path));
|
|
27
|
-
subs.complete();
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
async function read(source) {
|
|
31
|
-
const content = await fs_1.promises.readFile(source);
|
|
32
|
-
return {
|
|
33
|
-
path: source,
|
|
34
|
-
source: content,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function filterPath(matchPath) {
|
|
38
|
-
matchPath = (0, path_1.resolve)(matchPath);
|
|
39
|
-
return (0, rx_1.filter)((out) => (0, path_1.resolve)(out.path).startsWith(matchPath));
|
|
40
|
-
}
|
|
41
|
-
function file(source, out) {
|
|
42
|
-
return (0, rx_1.defer)(() => (0, rx_1.from)(read(source).then(res => ({
|
|
43
|
-
path: out || (0, path_1.resolve)(source),
|
|
44
|
-
source: res.source,
|
|
45
|
-
}))));
|
|
46
|
-
}
|
|
47
|
-
function basename(replace) {
|
|
48
|
-
return (0, rx_1.tap)(out => (out.path = (replace || '') + (0, path_1.basename)(out.path)));
|
|
49
|
-
}
|
|
50
|
-
/*export function prepend(src: string) {
|
|
51
|
-
return tap(out => out.source = Buffer.from(src + out.source.toString('utf8')));
|
|
52
|
-
}*/
|
|
53
|
-
function concatFile(outName, separator = '\n') {
|
|
54
|
-
return (0, rx_1.pipe)((0, rx_1.reduce)((out, src) => `${out}${separator}${src.source}`, ''), (0, rx_1.map)(source => ({ path: outName, source: Buffer.from(source) })));
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Reads multiple files asynchronously and emits them in order
|
|
58
|
-
*/
|
|
59
|
-
function files(sources) {
|
|
60
|
-
return new rx_1.Observable(subs => {
|
|
61
|
-
Promise.all(sources.map(read)).then(out => {
|
|
62
|
-
out.forEach(o => subs.next(o));
|
|
63
|
-
subs.complete();
|
|
64
|
-
}, e => subs.error(e));
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
function matchStat(fromPath, toPath) {
|
|
68
|
-
return Promise.all([fs_1.promises.stat(fromPath), fs_1.promises.stat(toPath)]).then(([fromStat, toStat]) => fromStat.mtime.getTime() === toStat.mtime.getTime(), () => true);
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Copy Directory
|
|
72
|
-
*/
|
|
73
|
-
function copyDir(fromPath, toPath, glob = '*') {
|
|
74
|
-
return (0, builder_js_1.exec)(`mkdir -p ${toPath} && rsync -au -i --delete ${fromPath}/${glob} ${toPath}`);
|
|
75
|
-
}
|
|
76
|
-
function getSourceMap(out) {
|
|
77
|
-
const source = out.source.toString();
|
|
78
|
-
const match = /\/\/# sourceMappingURL=(.+)/.exec(source);
|
|
79
|
-
const path = match ? (0, path_1.resolve)((0, path_1.dirname)(out.path), match?.[1]) : null;
|
|
80
|
-
if (path)
|
|
81
|
-
return { path: (0, path_1.basename)(path), source: (0, fs_1.readFileSync)(path) };
|
|
82
|
-
}
|
|
83
|
-
exports.MinifyDefault = {
|
|
84
|
-
ecma: 2020,
|
|
85
|
-
};
|
|
86
|
-
function minify(op) {
|
|
87
|
-
return (0, rx_1.mergeMap)(out => {
|
|
88
|
-
const config = { ...exports.MinifyDefault, ...op };
|
|
89
|
-
// Bypass if not a JS file
|
|
90
|
-
if (!out.path.endsWith('.js'))
|
|
91
|
-
return (0, rx_1.of)(out);
|
|
92
|
-
const destPath = op?.changePath === false
|
|
93
|
-
? out.path
|
|
94
|
-
: out.path.replace(/\.js$/, '.min.js');
|
|
95
|
-
if (config.sourceMap === undefined) {
|
|
96
|
-
const sourceMap = getSourceMap(out);
|
|
97
|
-
if (sourceMap)
|
|
98
|
-
config.sourceMap = {
|
|
99
|
-
content: sourceMap.source.toString(),
|
|
100
|
-
url: destPath + '.map',
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
const source = out.source.toString();
|
|
104
|
-
delete config.changePath;
|
|
105
|
-
return new rx_1.Observable(async (subscriber) => {
|
|
106
|
-
try {
|
|
107
|
-
const { code, map } = await Terser.minify({ [out.path]: source }, config);
|
|
108
|
-
if (!code)
|
|
109
|
-
throw new Error('No code generated');
|
|
110
|
-
subscriber.next({
|
|
111
|
-
path: destPath,
|
|
112
|
-
source: Buffer.from(code),
|
|
113
|
-
});
|
|
114
|
-
if (map && config.sourceMap)
|
|
115
|
-
subscriber.next({
|
|
116
|
-
path: config.sourceMap.url,
|
|
117
|
-
source: Buffer.from(map.toString()),
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
console.error(`Error minifying ${out.path}`);
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
subscriber.complete();
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function minifyDir(dir, op) {
|
|
129
|
-
return ls(dir)
|
|
130
|
-
.filter(path => path.endsWith('.js'))
|
|
131
|
-
.mergeMap(file)
|
|
132
|
-
.pipe(minify(op));
|
|
133
|
-
}
|
|
134
|
-
function zip(src, path) {
|
|
135
|
-
return (0, builder_js_1.shell)(`zip - ${src.join(' ')}`).map(source => ({ path, source }));
|
|
136
|
-
}
|
package/git.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getBranch = getBranch;
|
|
4
|
-
exports.checkBranchClean = checkBranchClean;
|
|
5
|
-
exports.checkBranchUpToDate = checkBranchUpToDate;
|
|
6
|
-
const program_1 = require("@cxl/program");
|
|
7
|
-
async function getBranch(cwd) {
|
|
8
|
-
return (await (0, program_1.sh)('git rev-parse --abbrev-ref HEAD', { cwd })).trim();
|
|
9
|
-
}
|
|
10
|
-
async function checkBranchClean(branch) {
|
|
11
|
-
try {
|
|
12
|
-
await (0, program_1.sh)(`git status > /dev/null; git diff-index --quiet ${branch}`);
|
|
13
|
-
}
|
|
14
|
-
catch (e) {
|
|
15
|
-
throw new Error('Not a clean repository');
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async function checkBranchUpToDate(branch = 'master') {
|
|
19
|
-
try {
|
|
20
|
-
await (0, program_1.sh)(`git diff origin/${branch} ${branch} --quiet`);
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
throw new Error('Branch has not been merged with origin');
|
|
24
|
-
}
|
|
25
|
-
}
|
package/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.shell = exports.exec = exports.build = exports.buildCxl = exports.docgenTask = exports.docgen = exports.template = exports.bundleAmd = exports.bundle = exports.readme = exports.pkg = exports.REQUIRE_REPLACE = exports.AMD = exports.readJson = exports.sh = exports.mkdirp = exports.concat = exports.zip = exports.minify = exports.copyDir = exports.concatFile = exports.files = exports.file = exports.basename = exports.tsBundle = exports.tsconfig = void 0;
|
|
5
|
-
const cxl_js_1 = require("./cxl.js");
|
|
6
|
-
var tsc_js_1 = require("./tsc.js");
|
|
7
|
-
Object.defineProperty(exports, "tsconfig", { enumerable: true, get: function () { return tsc_js_1.tsconfig; } });
|
|
8
|
-
Object.defineProperty(exports, "tsBundle", { enumerable: true, get: function () { return tsc_js_1.bundle; } });
|
|
9
|
-
var file_js_1 = require("./file.js");
|
|
10
|
-
Object.defineProperty(exports, "basename", { enumerable: true, get: function () { return file_js_1.basename; } });
|
|
11
|
-
Object.defineProperty(exports, "file", { enumerable: true, get: function () { return file_js_1.file; } });
|
|
12
|
-
Object.defineProperty(exports, "files", { enumerable: true, get: function () { return file_js_1.files; } });
|
|
13
|
-
Object.defineProperty(exports, "concatFile", { enumerable: true, get: function () { return file_js_1.concatFile; } });
|
|
14
|
-
Object.defineProperty(exports, "copyDir", { enumerable: true, get: function () { return file_js_1.copyDir; } });
|
|
15
|
-
Object.defineProperty(exports, "minify", { enumerable: true, get: function () { return file_js_1.minify; } });
|
|
16
|
-
Object.defineProperty(exports, "zip", { enumerable: true, get: function () { return file_js_1.zip; } });
|
|
17
|
-
var rx_1 = require("@cxl/rx");
|
|
18
|
-
Object.defineProperty(exports, "concat", { enumerable: true, get: function () { return rx_1.concat; } });
|
|
19
|
-
var program_1 = require("@cxl/program");
|
|
20
|
-
Object.defineProperty(exports, "mkdirp", { enumerable: true, get: function () { return program_1.mkdirp; } });
|
|
21
|
-
Object.defineProperty(exports, "sh", { enumerable: true, get: function () { return program_1.sh; } });
|
|
22
|
-
Object.defineProperty(exports, "readJson", { enumerable: true, get: function () { return program_1.readJson; } });
|
|
23
|
-
var package_js_1 = require("./package.js");
|
|
24
|
-
Object.defineProperty(exports, "AMD", { enumerable: true, get: function () { return package_js_1.AMD; } });
|
|
25
|
-
Object.defineProperty(exports, "REQUIRE_REPLACE", { enumerable: true, get: function () { return package_js_1.REQUIRE_REPLACE; } });
|
|
26
|
-
Object.defineProperty(exports, "pkg", { enumerable: true, get: function () { return package_js_1.pkg; } });
|
|
27
|
-
Object.defineProperty(exports, "readme", { enumerable: true, get: function () { return package_js_1.readme; } });
|
|
28
|
-
Object.defineProperty(exports, "bundle", { enumerable: true, get: function () { return package_js_1.bundle; } });
|
|
29
|
-
Object.defineProperty(exports, "bundleAmd", { enumerable: true, get: function () { return package_js_1.bundleAmd; } });
|
|
30
|
-
Object.defineProperty(exports, "template", { enumerable: true, get: function () { return package_js_1.template; } });
|
|
31
|
-
Object.defineProperty(exports, "docgen", { enumerable: true, get: function () { return package_js_1.docgen; } });
|
|
32
|
-
Object.defineProperty(exports, "docgenTask", { enumerable: true, get: function () { return package_js_1.docgenTask; } });
|
|
33
|
-
var cxl_js_2 = require("./cxl.js");
|
|
34
|
-
Object.defineProperty(exports, "buildCxl", { enumerable: true, get: function () { return cxl_js_2.buildCxl; } });
|
|
35
|
-
var builder_js_1 = require("./builder.js");
|
|
36
|
-
Object.defineProperty(exports, "build", { enumerable: true, get: function () { return builder_js_1.build; } });
|
|
37
|
-
Object.defineProperty(exports, "exec", { enumerable: true, get: function () { return builder_js_1.exec; } });
|
|
38
|
-
Object.defineProperty(exports, "shell", { enumerable: true, get: function () { return builder_js_1.shell; } });
|
|
39
|
-
if (require.main?.filename === __filename)
|
|
40
|
-
(0, cxl_js_1.buildCxl)();
|