@eighty4/dank 0.0.4-0 → 0.0.4-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/lib_js/flags.js CHANGED
@@ -1,123 +1,124 @@
1
- import { join, resolve } from 'node:path';
2
- import { cwd } from 'node:process';
3
- export function resolveBuildFlags() {
4
- const flags = {
5
- dirs: defaultProjectDirs(cwd()),
6
- minify: willMinify(),
7
- production: isProductionBuild(),
8
- };
9
- return {
10
- get dirs() {
11
- return flags.dirs;
12
- },
13
- get minify() {
14
- return flags.minify;
15
- },
16
- get production() {
17
- return flags.production;
18
- },
19
- };
1
+ import { join, resolve } from "node:path";
2
+ import { cwd } from "node:process";
3
+ function resolveBuildFlags() {
4
+ const flags = {
5
+ dirs: defaultProjectDirs(cwd()),
6
+ minify: willMinify(),
7
+ production: isProductionBuild()
8
+ };
9
+ return {
10
+ get dirs() {
11
+ return flags.dirs;
12
+ },
13
+ get minify() {
14
+ return flags.minify;
15
+ },
16
+ get production() {
17
+ return flags.production;
18
+ }
19
+ };
20
20
  }
21
- export function resolveServeFlags(c) {
22
- const preview = isPreviewBuild();
23
- const flags = {
24
- dirs: defaultProjectDirs(cwd()),
25
- dankPort: dankPort(c, preview),
26
- esbuildPort: esbuildPort(c),
27
- logHttp: willLogHttp(),
28
- minify: willMinify(),
29
- preview,
30
- production: isProductionBuild(),
31
- };
32
- return {
33
- get dirs() {
34
- return flags.dirs;
35
- },
36
- get dankPort() {
37
- return flags.dankPort;
38
- },
39
- get esbuildPort() {
40
- return flags.esbuildPort;
41
- },
42
- get logHttp() {
43
- return flags.logHttp;
44
- },
45
- get minify() {
46
- return flags.minify;
47
- },
48
- get preview() {
49
- return flags.preview;
50
- },
51
- get production() {
52
- return flags.production;
53
- },
54
- };
21
+ function resolveServeFlags(c) {
22
+ const preview = isPreviewBuild();
23
+ const flags = {
24
+ dirs: defaultProjectDirs(cwd()),
25
+ dankPort: dankPort(c, preview),
26
+ esbuildPort: esbuildPort(c),
27
+ logHttp: willLogHttp(),
28
+ minify: willMinify(),
29
+ preview,
30
+ production: isProductionBuild()
31
+ };
32
+ return {
33
+ get dirs() {
34
+ return flags.dirs;
35
+ },
36
+ get dankPort() {
37
+ return flags.dankPort;
38
+ },
39
+ get esbuildPort() {
40
+ return flags.esbuildPort;
41
+ },
42
+ get logHttp() {
43
+ return flags.logHttp;
44
+ },
45
+ get minify() {
46
+ return flags.minify;
47
+ },
48
+ get preview() {
49
+ return flags.preview;
50
+ },
51
+ get production() {
52
+ return flags.production;
53
+ }
54
+ };
55
55
  }
56
- // `dank serve` will pre-bundle and use service worker
57
- const isPreviewBuild = () => process.env.PREVIEW === 'true' || process.argv.includes('--preview');
58
- // `dank build` will minify sources and append git release tag to build tag
59
- // `dank serve` will pre-bundle with service worker and minify
60
- const isProductionBuild = () => process.env.PRODUCTION === 'true' || process.argv.includes('--production');
61
- // `dank serve` dank port for frontend webserver
62
- // alternate --preview port for service worker builds
56
+ const isPreviewBuild = () => process.env.PREVIEW === "true" || process.argv.includes("--preview");
57
+ const isProductionBuild = () => process.env.PRODUCTION === "true" || process.argv.includes("--production");
63
58
  function dankPort(c, preview) {
64
- if (process.env.DANK_PORT?.length) {
65
- return parsePortEnvVar('DANK_PORT');
66
- }
67
- return preview ? c.previewPort || c.port || 4000 : c.port || 3000;
59
+ if (process.env.DANK_PORT?.length) {
60
+ return parsePortEnvVar("DANK_PORT");
61
+ }
62
+ return preview ? c.previewPort || c.port || 4e3 : c.port || 3e3;
68
63
  }
69
- // `dank serve` esbuild port for bundler integration
70
64
  function esbuildPort(c) {
71
- if (process.env.ESBUILD_PORT?.length) {
72
- return parsePortEnvVar('ESBUILD_PORT');
73
- }
74
- return c.esbuild?.port || 3995;
65
+ if (process.env.ESBUILD_PORT?.length) {
66
+ return parsePortEnvVar("ESBUILD_PORT");
67
+ }
68
+ return c.esbuild?.port || 3995;
75
69
  }
76
70
  function parsePortEnvVar(name) {
77
- const port = parseInt(process.env[name], 10);
78
- if (isNaN(port)) {
79
- throw Error(`env var ${name}=${port} must be a valid port number`);
80
- }
81
- else {
82
- return port;
83
- }
71
+ const port = parseInt(process.env[name], 10);
72
+ if (isNaN(port)) {
73
+ throw Error(`env var ${name}=${port} must be a valid port number`);
74
+ } else {
75
+ return port;
76
+ }
84
77
  }
85
- export function defaultProjectDirs(projectRootAbs) {
86
- const dirs = {
87
- buildRoot: 'build',
88
- buildDist: join('build', 'dist'),
89
- buildWatch: join('build', 'watch'),
90
- pages: 'pages',
91
- pagesResolved: resolve(join(projectRootAbs, 'pages')),
92
- projectRootAbs,
93
- public: 'public',
94
- };
95
- return {
96
- get buildRoot() {
97
- return dirs.buildRoot;
98
- },
99
- get buildDist() {
100
- return dirs.buildDist;
101
- },
102
- get buildWatch() {
103
- return dirs.buildWatch;
104
- },
105
- get pages() {
106
- return dirs.pages;
107
- },
108
- get pagesResolved() {
109
- return dirs.pagesResolved;
110
- },
111
- get projectRootAbs() {
112
- return dirs.projectRootAbs;
113
- },
114
- get public() {
115
- return dirs.public;
116
- },
117
- };
78
+ function defaultProjectDirs(projectRootAbs) {
79
+ const pages = "pages";
80
+ const dirs = {
81
+ buildRoot: "build",
82
+ buildDist: join("build", "dist"),
83
+ buildWatch: join("build", "watch"),
84
+ pages,
85
+ pagesResolved: resolve(join(projectRootAbs, pages)),
86
+ projectResolved: resolve(projectRootAbs),
87
+ projectRootAbs,
88
+ public: "public"
89
+ };
90
+ return {
91
+ get buildRoot() {
92
+ return dirs.buildRoot;
93
+ },
94
+ get buildDist() {
95
+ return dirs.buildDist;
96
+ },
97
+ get buildWatch() {
98
+ return dirs.buildWatch;
99
+ },
100
+ get pages() {
101
+ return dirs.pages;
102
+ },
103
+ get pagesResolved() {
104
+ return dirs.pagesResolved;
105
+ },
106
+ get projectResolved() {
107
+ return dirs.projectResolved;
108
+ },
109
+ get projectRootAbs() {
110
+ return dirs.projectRootAbs;
111
+ },
112
+ get public() {
113
+ return dirs.public;
114
+ }
115
+ };
118
116
  }
119
- const willMinify = () => isProductionBuild() ||
120
- process.env.MINIFY === 'true' ||
121
- process.argv.includes('--minify');
122
- // `dank serve` will print http access logs to console
123
- const willLogHttp = () => process.env.LOG_HTTP === 'true' || process.argv.includes('--log-http');
117
+ const willMinify = () => isProductionBuild() || process.env.MINIFY === "true" || process.argv.includes("--minify");
118
+ const willLogHttp = () => process.env.LOG_HTTP === "true" || process.argv.includes("--log-http");
119
+ export {
120
+ defaultProjectDirs,
121
+ isProductionBuild,
122
+ resolveBuildFlags,
123
+ resolveServeFlags
124
+ };