@knighted/duel 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/init.cjs DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.init = void 0;
7
- var _nodeProcess = require("node:process");
8
- var _nodeUtil = require("node:util");
9
- var _nodePath = require("node:path");
10
- var _promises = require("node:fs/promises");
11
- var _stripJsonComments = _interopRequireDefault(require("strip-json-comments"));
12
- var _readPkgUp = require("read-pkg-up");
13
- var _util = require("./util.cjs");
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- const init = async args => {
16
- let parsed = null;
17
- try {
18
- const {
19
- values
20
- } = (0, _nodeUtil.parseArgs)({
21
- args,
22
- options: {
23
- project: {
24
- type: 'string',
25
- short: 'p',
26
- default: 'tsconfig.json'
27
- },
28
- 'target-extension': {
29
- type: 'string',
30
- short: 'x',
31
- default: ''
32
- },
33
- 'pkg-dir': {
34
- type: 'string',
35
- short: 'k',
36
- default: (0, _nodeProcess.cwd)()
37
- },
38
- parallel: {
39
- type: 'boolean',
40
- short: 'l',
41
- default: false
42
- },
43
- dirs: {
44
- type: 'boolean',
45
- short: 'd',
46
- default: false
47
- },
48
- help: {
49
- type: 'boolean',
50
- short: 'h',
51
- default: false
52
- }
53
- }
54
- });
55
- parsed = values;
56
- } catch (err) {
57
- (0, _util.logError)(err.message);
58
- return false;
59
- }
60
- if (parsed.help) {
61
- (0, _util.log)('Usage: duel [options]\n');
62
- (0, _util.log)('Options:');
63
- (0, _util.log)("--project, -p [path] \t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
64
- (0, _util.log)('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to cwd.');
65
- (0, _util.log)('--dirs, -d \t\t Output both builds to directories inside of outDir. [esm, cjs].');
66
- (0, _util.log)('--parallel, -l \t\t Run the builds in parallel.');
67
- (0, _util.log)('--help, -h \t\t Print this message.');
68
- } else {
69
- const {
70
- project,
71
- 'target-extension': targetExt,
72
- 'pkg-dir': pkgDir,
73
- parallel,
74
- dirs
75
- } = parsed;
76
- let configPath = (0, _nodePath.resolve)(project);
77
- let stats = null;
78
- let pkg = null;
79
- if (targetExt) {
80
- (0, _util.logError)('--target-extension is deprecated. Define "type" in your package.json instead and the dual build will be inferred from that.');
81
- return false;
82
- }
83
- pkg = await (0, _readPkgUp.readPackageUp)({
84
- cwd: pkgDir
85
- });
86
- if (!pkg) {
87
- (0, _util.logError)('No package.json file found.');
88
- return false;
89
- }
90
- try {
91
- stats = await (0, _promises.stat)(configPath);
92
- } catch {
93
- (0, _util.logError)(`Provided --project '${project}' resolves to ${configPath} which is not a file or directory.`);
94
- return false;
95
- }
96
- if (stats.isDirectory()) {
97
- configPath = (0, _nodePath.join)(configPath, 'tsconfig.json');
98
- try {
99
- stats = await (0, _promises.stat)(configPath);
100
- } catch {
101
- (0, _util.logError)(`Provided --project '${project}' resolves to a directory ${(0, _nodePath.dirname)(configPath)} with no tsconfig.json.`);
102
- return false;
103
- }
104
- }
105
- if (stats.isFile()) {
106
- let tsconfig = null;
107
- try {
108
- tsconfig = JSON.parse((0, _stripJsonComments.default)((await (0, _promises.readFile)(configPath)).toString()));
109
- } catch (err) {
110
- (0, _util.logError)(`The config file found at ${configPath} is not parsable as JSON.`);
111
- return false;
112
- }
113
- if (!tsconfig.compilerOptions?.outDir) {
114
- (0, _util.log)('No outDir defined in tsconfig.json. Build output will be in "dist".');
115
- }
116
- const projectDir = (0, _nodePath.dirname)(configPath);
117
- return {
118
- pkg,
119
- dirs,
120
- parallel,
121
- tsconfig,
122
- projectDir,
123
- configPath
124
- };
125
- }
126
- }
127
- return false;
128
- };
129
- exports.init = init;
package/dist/init.js DELETED
@@ -1,122 +0,0 @@
1
- import { cwd } from 'node:process';
2
- import { parseArgs } from 'node:util';
3
- import { resolve, join, dirname } from 'node:path';
4
- import { stat, readFile } from 'node:fs/promises';
5
- import stripJsonComments from 'strip-json-comments';
6
- import { readPackageUp } from 'read-pkg-up';
7
- import { logError, log } from './util.js';
8
- const init = async args => {
9
- let parsed = null;
10
- try {
11
- const {
12
- values
13
- } = parseArgs({
14
- args,
15
- options: {
16
- project: {
17
- type: 'string',
18
- short: 'p',
19
- default: 'tsconfig.json'
20
- },
21
- 'target-extension': {
22
- type: 'string',
23
- short: 'x',
24
- default: ''
25
- },
26
- 'pkg-dir': {
27
- type: 'string',
28
- short: 'k',
29
- default: cwd()
30
- },
31
- parallel: {
32
- type: 'boolean',
33
- short: 'l',
34
- default: false
35
- },
36
- dirs: {
37
- type: 'boolean',
38
- short: 'd',
39
- default: false
40
- },
41
- help: {
42
- type: 'boolean',
43
- short: 'h',
44
- default: false
45
- }
46
- }
47
- });
48
- parsed = values;
49
- } catch (err) {
50
- logError(err.message);
51
- return false;
52
- }
53
- if (parsed.help) {
54
- log('Usage: duel [options]\n');
55
- log('Options:');
56
- log("--project, -p [path] \t Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.");
57
- log('--pkg-dir, -k [path] \t The directory to start looking for a package.json file. Defaults to cwd.');
58
- log('--dirs, -d \t\t Output both builds to directories inside of outDir. [esm, cjs].');
59
- log('--parallel, -l \t\t Run the builds in parallel.');
60
- log('--help, -h \t\t Print this message.');
61
- } else {
62
- const {
63
- project,
64
- 'target-extension': targetExt,
65
- 'pkg-dir': pkgDir,
66
- parallel,
67
- dirs
68
- } = parsed;
69
- let configPath = resolve(project);
70
- let stats = null;
71
- let pkg = null;
72
- if (targetExt) {
73
- logError('--target-extension is deprecated. Define "type" in your package.json instead and the dual build will be inferred from that.');
74
- return false;
75
- }
76
- pkg = await readPackageUp({
77
- cwd: pkgDir
78
- });
79
- if (!pkg) {
80
- logError('No package.json file found.');
81
- return false;
82
- }
83
- try {
84
- stats = await stat(configPath);
85
- } catch {
86
- logError(`Provided --project '${project}' resolves to ${configPath} which is not a file or directory.`);
87
- return false;
88
- }
89
- if (stats.isDirectory()) {
90
- configPath = join(configPath, 'tsconfig.json');
91
- try {
92
- stats = await stat(configPath);
93
- } catch {
94
- logError(`Provided --project '${project}' resolves to a directory ${dirname(configPath)} with no tsconfig.json.`);
95
- return false;
96
- }
97
- }
98
- if (stats.isFile()) {
99
- let tsconfig = null;
100
- try {
101
- tsconfig = JSON.parse(stripJsonComments((await readFile(configPath)).toString()));
102
- } catch (err) {
103
- logError(`The config file found at ${configPath} is not parsable as JSON.`);
104
- return false;
105
- }
106
- if (!tsconfig.compilerOptions?.outDir) {
107
- log('No outDir defined in tsconfig.json. Build output will be in "dist".');
108
- }
109
- const projectDir = dirname(configPath);
110
- return {
111
- pkg,
112
- dirs,
113
- parallel,
114
- tsconfig,
115
- projectDir,
116
- configPath
117
- };
118
- }
119
- }
120
- return false;
121
- };
122
- export { init };
package/dist/util.cjs DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.logError = exports.log = exports.getRealPathAsFileUrl = void 0;
7
- var _nodeUrl = require("node:url");
8
- var _promises = require("node:fs/promises");
9
- const log = (color = '\x1b[30m', msg = '') => {
10
- console.log(`${color}%s\x1b[0m`, msg);
11
- };
12
- exports.log = log;
13
- const logError = log.bind(null, '\x1b[31m');
14
- exports.logError = logError;
15
- const getRealPathAsFileUrl = async path => {
16
- const realPath = await (0, _promises.realpath)(path);
17
- const asFileUrl = (0, _nodeUrl.pathToFileURL)(realPath).href;
18
- return asFileUrl;
19
- };
20
- exports.getRealPathAsFileUrl = getRealPathAsFileUrl;
package/dist/util.js DELETED
@@ -1,12 +0,0 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { realpath } from 'node:fs/promises';
3
- const log = (color = '\x1b[30m', msg = '') => {
4
- console.log(`${color}%s\x1b[0m`, msg);
5
- };
6
- const logError = log.bind(null, '\x1b[31m');
7
- const getRealPathAsFileUrl = async path => {
8
- const realPath = await realpath(path);
9
- const asFileUrl = pathToFileURL(realPath).href;
10
- return asFileUrl;
11
- };
12
- export { log, logError, getRealPathAsFileUrl };