@granite-js/cli 0.0.0-dev-20250725013859
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/LICENSE +202 -0
- package/README.md +31 -0
- package/dist/index.cjs +415 -0
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +389 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2025 Viva Republica, Inc
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @granite-js/cli
|
|
2
|
+
|
|
3
|
+
The Granite CLI
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn build
|
|
9
|
+
yarn run bin
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## License
|
|
13
|
+
|
|
14
|
+
This software is licensed under the [Apache 2 license](LICENSE), quoted below.
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
Copyright 2025 Viva Republica, Inc
|
|
18
|
+
|
|
19
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
you may not use this file except in compliance with the License.
|
|
21
|
+
You may obtain a copy of the License at:
|
|
22
|
+
|
|
23
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
24
|
+
|
|
25
|
+
Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
See the License for the specific language governing permissions and
|
|
29
|
+
limitations under the License.
|
|
30
|
+
|
|
31
|
+
```
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
defineConfig: () => defineConfig,
|
|
34
|
+
initialize: () => initialize,
|
|
35
|
+
loadConfig: () => loadConfig
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(index_exports);
|
|
38
|
+
var import_clipanion4 = require("clipanion");
|
|
39
|
+
var import_cosmiconfig2 = require("cosmiconfig");
|
|
40
|
+
|
|
41
|
+
// src/commands/BuildCommand/BuildCommand.ts
|
|
42
|
+
var import_clipanion = require("clipanion");
|
|
43
|
+
|
|
44
|
+
// src/commands/BuildCommand/build.ts
|
|
45
|
+
var import_path = __toESM(require("path"), 1);
|
|
46
|
+
var import_mpack = require("@granite-js/mpack");
|
|
47
|
+
var import_plugins = require("@granite-js/mpack/plugins");
|
|
48
|
+
var import_plugin_core = require("@granite-js/plugin-core");
|
|
49
|
+
async function build(config, options) {
|
|
50
|
+
const pluginContext = (0, import_plugin_core.createContext)();
|
|
51
|
+
for (const preHandler of config.pluginHooks.build.preHandlers) {
|
|
52
|
+
await preHandler.call(pluginContext, {
|
|
53
|
+
cwd: config.cwd,
|
|
54
|
+
entryFile: config.entryFile,
|
|
55
|
+
appName: config.appName,
|
|
56
|
+
outdir: config.outdir
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const buildResults = await Promise.all(
|
|
60
|
+
["ios", "android"].map(
|
|
61
|
+
(platform) => (0, import_mpack.runBundle)({
|
|
62
|
+
rootDir: config.cwd,
|
|
63
|
+
dev: false,
|
|
64
|
+
metafile: true,
|
|
65
|
+
cache: options.cache,
|
|
66
|
+
plugins: [import_plugins.statusPlugin],
|
|
67
|
+
buildConfig: { platform, outfile: import_path.default.join(config.outdir, `bundle.${platform}.js`), ...config.build }
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
);
|
|
71
|
+
for (const postHandler of config.pluginHooks.build.postHandlers) {
|
|
72
|
+
await postHandler.call(pluginContext, {
|
|
73
|
+
cwd: config.cwd,
|
|
74
|
+
entryFile: config.entryFile,
|
|
75
|
+
appName: config.appName,
|
|
76
|
+
outdir: config.outdir,
|
|
77
|
+
buildResults
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/config/loadConfig.ts
|
|
83
|
+
var import_utils = require("@granite-js/utils");
|
|
84
|
+
var import_cosmiconfig = require("cosmiconfig");
|
|
85
|
+
var import_cosmiconfig_typescript_loader = require("cosmiconfig-typescript-loader");
|
|
86
|
+
var MODULE_NAME = "granite";
|
|
87
|
+
var loadConfig = async () => {
|
|
88
|
+
const explorer = (0, import_cosmiconfig.cosmiconfig)(MODULE_NAME, {
|
|
89
|
+
searchPlaces: [
|
|
90
|
+
`${MODULE_NAME}.config.ts`,
|
|
91
|
+
`${MODULE_NAME}.config.mts`,
|
|
92
|
+
`${MODULE_NAME}.config.js`,
|
|
93
|
+
`${MODULE_NAME}.config.cjs`
|
|
94
|
+
],
|
|
95
|
+
loaders: {
|
|
96
|
+
".ts": (0, import_cosmiconfig_typescript_loader.TypeScriptLoader)(),
|
|
97
|
+
".mts": (0, import_cosmiconfig_typescript_loader.TypeScriptLoader)()
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
const result = await explorer.search((0, import_utils.getPackageRoot)());
|
|
101
|
+
const config = await result?.config;
|
|
102
|
+
return config;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/commands/BuildCommand/BuildCommand.ts
|
|
106
|
+
var BuildCommand = class extends import_clipanion.Command {
|
|
107
|
+
static paths = [[`build`]];
|
|
108
|
+
static usage = import_clipanion.Command.Usage({
|
|
109
|
+
category: "Build",
|
|
110
|
+
description: "Build Granite App",
|
|
111
|
+
examples: [["Build Granite App", "granite build"]]
|
|
112
|
+
});
|
|
113
|
+
disableCache = import_clipanion.Option.Boolean("--disable-cache", {
|
|
114
|
+
description: "Disable cache"
|
|
115
|
+
});
|
|
116
|
+
async execute() {
|
|
117
|
+
try {
|
|
118
|
+
const { disableCache = false } = this;
|
|
119
|
+
const config = await loadConfig();
|
|
120
|
+
await build(config, {
|
|
121
|
+
cache: !disableCache
|
|
122
|
+
});
|
|
123
|
+
return 0;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error(error);
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// src/commands/HermesCommand/HermesCommand.ts
|
|
132
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
133
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
134
|
+
var import_clipanion2 = require("clipanion");
|
|
135
|
+
|
|
136
|
+
// src/utils/compileHbc.ts
|
|
137
|
+
var import_assert = __toESM(require("assert"), 1);
|
|
138
|
+
var import_os = __toESM(require("os"), 1);
|
|
139
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
140
|
+
var import_es_toolkit = require("es-toolkit");
|
|
141
|
+
var import_execa = __toESM(require("execa"), 1);
|
|
142
|
+
var binary = {
|
|
143
|
+
Darwin: "react-native/sdks/hermesc/osx-bin/hermesc",
|
|
144
|
+
Linux: "react-native/sdks/hermesc/linux64-bin/hermesc",
|
|
145
|
+
Windows_NT: "react-native/sdks/hermesc/win64-bin/hermesc.exe"
|
|
146
|
+
};
|
|
147
|
+
async function compileHbc({ rootDir, filePath, sourcemap }) {
|
|
148
|
+
const binary2 = getHermesc(rootDir);
|
|
149
|
+
const outfile = import_path2.default.resolve(rootDir, filePath.replace(new RegExp(`${import_path2.default.extname(filePath)}$`), ".hbc"));
|
|
150
|
+
await (0, import_execa.default)(
|
|
151
|
+
binary2,
|
|
152
|
+
[
|
|
153
|
+
// Disable warnings
|
|
154
|
+
"-w",
|
|
155
|
+
// Expensive optimizations
|
|
156
|
+
"-O",
|
|
157
|
+
// Emit binary
|
|
158
|
+
"-emit-binary",
|
|
159
|
+
// Emit source map
|
|
160
|
+
sourcemap ? "-output-source-map" : null,
|
|
161
|
+
// Output path
|
|
162
|
+
"-out",
|
|
163
|
+
outfile,
|
|
164
|
+
filePath
|
|
165
|
+
].filter(import_es_toolkit.isNotNil)
|
|
166
|
+
);
|
|
167
|
+
return { outfile, sourcemapOutfile: sourcemap ? `${outfile}.map` : null };
|
|
168
|
+
}
|
|
169
|
+
function getHermesc(rootDir) {
|
|
170
|
+
const os2 = getOs();
|
|
171
|
+
const binarySource = binary[os2];
|
|
172
|
+
(0, import_assert.default)(binarySource, `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 OS \uC785\uB2C8\uB2E4: ${os2}`);
|
|
173
|
+
return resolveFromRoot(rootDir, binarySource);
|
|
174
|
+
}
|
|
175
|
+
function getOs() {
|
|
176
|
+
return import_os.default.type();
|
|
177
|
+
}
|
|
178
|
+
function resolveFromRoot(rootDir, request) {
|
|
179
|
+
return require.resolve(request, { paths: [rootDir] });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// src/commands/HermesCommand/HermesCommand.ts
|
|
183
|
+
var HermesCommand = class extends import_clipanion2.Command {
|
|
184
|
+
static paths = [[`hermes`]];
|
|
185
|
+
static usage = import_clipanion2.Command.Usage({
|
|
186
|
+
category: "Hermes",
|
|
187
|
+
description: "\uC9C0\uC815\uD55C \uBC88\uB4E4\uC744 Hermes \uBC14\uC774\uD2B8 \uCF54\uB4DC\uB85C \uCEF4\uD30C\uC77C \uD569\uB2C8\uB2E4",
|
|
188
|
+
examples: [["\uCEF4\uD30C\uC77C\uD558\uAE30", "granite hermes --jsbundle dist/bundle.js"]]
|
|
189
|
+
});
|
|
190
|
+
jsBundleFile = import_clipanion2.Option.String("--jsbundle", {
|
|
191
|
+
required: true,
|
|
192
|
+
description: "Hermes \uBC14\uC774\uD2B8 \uCF54\uB4DC\uB85C \uCEF4\uD30C\uC77C \uD560 Javascript \uD30C\uC77C \uACBD\uB85C \uC785\uB2C8\uB2E4"
|
|
193
|
+
});
|
|
194
|
+
sourcemap = import_clipanion2.Option.Boolean("--sourcemap", true, {
|
|
195
|
+
description: "\uC18C\uC2A4\uB9F5 \uD30C\uC77C\uC744 \uC0DD\uC131\uD569\uB2C8\uB2E4"
|
|
196
|
+
});
|
|
197
|
+
async execute() {
|
|
198
|
+
try {
|
|
199
|
+
const rootDir = process.cwd();
|
|
200
|
+
const filePath = import_path3.default.resolve(rootDir, this.jsBundleFile);
|
|
201
|
+
const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
|
|
202
|
+
console.log(`\u2705 \uCEF4\uD30C\uC77C \uC644\uB8CC: ${import_chalk.default.gray(outfile)}`);
|
|
203
|
+
if (sourcemapOutfile) {
|
|
204
|
+
console.log(`\u2705 \uC18C\uC2A4\uB9F5 \uC0DD\uC131 \uC644\uB8CC: ${import_chalk.default.gray(sourcemapOutfile)}`);
|
|
205
|
+
}
|
|
206
|
+
return 0;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error(error.stack);
|
|
209
|
+
return 1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/commands/DevCommand/DevCommand.ts
|
|
215
|
+
var mpack = __toESM(require("@granite-js/mpack"), 1);
|
|
216
|
+
var import_clipanion3 = require("clipanion");
|
|
217
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
218
|
+
|
|
219
|
+
// src/commands/DevCommand/startDevServer.ts
|
|
220
|
+
var import_mpack2 = require("@granite-js/mpack");
|
|
221
|
+
var import_plugin_core2 = require("@granite-js/plugin-core");
|
|
222
|
+
async function startDevServer(serverOptions, config) {
|
|
223
|
+
const pluginContext = (0, import_plugin_core2.createContext)();
|
|
224
|
+
const commonHandlerArgs = {
|
|
225
|
+
host: serverOptions.host,
|
|
226
|
+
port: serverOptions.port,
|
|
227
|
+
appName: config.appName,
|
|
228
|
+
outdir: config.outdir,
|
|
229
|
+
cwd: config.cwd,
|
|
230
|
+
entryFile: config.build.entry
|
|
231
|
+
};
|
|
232
|
+
for (const preHandler of config.pluginHooks.devServer.preHandlers) {
|
|
233
|
+
await preHandler.call(pluginContext, commonHandlerArgs);
|
|
234
|
+
}
|
|
235
|
+
await (0, import_mpack2.runServer)({
|
|
236
|
+
cwd: config.cwd,
|
|
237
|
+
host: serverOptions.host,
|
|
238
|
+
port: serverOptions.port,
|
|
239
|
+
middlewares: config.metro?.middlewares,
|
|
240
|
+
enableEmbeddedReactDevTools: !serverOptions.disableEmbeddedReactDevTools,
|
|
241
|
+
additionalConfig: config.metro,
|
|
242
|
+
onServerReady: async () => {
|
|
243
|
+
for (const postHandler of config.pluginHooks.devServer.postHandlers) {
|
|
244
|
+
await postHandler.call(pluginContext, commonHandlerArgs);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/commands/DevCommand/DevCommand.ts
|
|
251
|
+
var debug = (0, import_debug.default)("cli");
|
|
252
|
+
var DEFAULT_HOST = "0.0.0.0";
|
|
253
|
+
var DEFAULT_LOCALHOST_PORT = 8081;
|
|
254
|
+
var DevCommand = class extends import_clipanion3.Command {
|
|
255
|
+
static paths = [[`dev`]];
|
|
256
|
+
static usage = import_clipanion3.Command.Usage({
|
|
257
|
+
category: "Development",
|
|
258
|
+
description: "Run Granite development server",
|
|
259
|
+
examples: [["Run Granite development server", "granite dev"]]
|
|
260
|
+
});
|
|
261
|
+
host = import_clipanion3.Option.String("--host");
|
|
262
|
+
port = import_clipanion3.Option.String("--port");
|
|
263
|
+
disableEmbeddedReactDevTools = import_clipanion3.Option.Boolean("--disable-embedded-react-devtools", false);
|
|
264
|
+
// mpack dev-server
|
|
265
|
+
experimentalMode = import_clipanion3.Option.Boolean("--experimental-mode");
|
|
266
|
+
async execute() {
|
|
267
|
+
try {
|
|
268
|
+
process.env.MPACK_DEV_SERVER = "true";
|
|
269
|
+
const config = await loadConfig();
|
|
270
|
+
const serverOptions = {
|
|
271
|
+
host: this.host,
|
|
272
|
+
port: this.port ? parseInt(this.port, 10) : void 0
|
|
273
|
+
};
|
|
274
|
+
debug("StartCommand", {
|
|
275
|
+
...serverOptions,
|
|
276
|
+
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
277
|
+
experimentalMode: this.experimentalMode
|
|
278
|
+
});
|
|
279
|
+
if (this.experimentalMode) {
|
|
280
|
+
await mpack.EXPERIMENTAL__runServer({
|
|
281
|
+
buildConfig: config.build,
|
|
282
|
+
host: serverOptions.host,
|
|
283
|
+
port: serverOptions.port
|
|
284
|
+
});
|
|
285
|
+
} else {
|
|
286
|
+
await startDevServer(
|
|
287
|
+
{
|
|
288
|
+
host: serverOptions.host || DEFAULT_HOST,
|
|
289
|
+
port: serverOptions.port || DEFAULT_LOCALHOST_PORT,
|
|
290
|
+
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools
|
|
291
|
+
},
|
|
292
|
+
config
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.log(`ERROR OCCURRED`);
|
|
297
|
+
console.log(error);
|
|
298
|
+
console.log(error.message);
|
|
299
|
+
console.error(error.stack);
|
|
300
|
+
process.exit(1);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/config/defineConfig.ts
|
|
306
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
307
|
+
var import_plugin_core3 = require("@granite-js/plugin-core");
|
|
308
|
+
var import_utils3 = require("@granite-js/utils");
|
|
309
|
+
var import_es_toolkit2 = require("es-toolkit");
|
|
310
|
+
var import_zod = require("zod");
|
|
311
|
+
|
|
312
|
+
// src/config/graniteGlobals.ts
|
|
313
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
314
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
315
|
+
var import_utils2 = require("@granite-js/utils");
|
|
316
|
+
function prepareGraniteGlobalsScript(config) {
|
|
317
|
+
const filePath = writeGraniteGlobalsScript(config);
|
|
318
|
+
return {
|
|
319
|
+
esbuild: {
|
|
320
|
+
prelude: [filePath]
|
|
321
|
+
},
|
|
322
|
+
metro: {
|
|
323
|
+
prelude: [filePath]
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function writeGraniteGlobalsScript(config) {
|
|
328
|
+
const script = getGraniteGlobalScript(config);
|
|
329
|
+
const filePath = import_path4.default.join((0, import_utils2.getLocalTempDirectoryPath)(config.rootDir), "granite-globals.js");
|
|
330
|
+
(0, import_utils2.prepareLocalDirectory)(config.rootDir);
|
|
331
|
+
import_fs.default.writeFileSync(filePath, script, "utf-8");
|
|
332
|
+
return filePath;
|
|
333
|
+
}
|
|
334
|
+
function getGraniteGlobalScript({ appName, scheme }) {
|
|
335
|
+
return [
|
|
336
|
+
"global.__granite = global.__granite || {};",
|
|
337
|
+
`global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`
|
|
338
|
+
].join("\n");
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/config/defineConfig.ts
|
|
342
|
+
var graniteConfigSchema = import_zod.z.object({
|
|
343
|
+
cwd: import_zod.z.string().default(process.cwd()),
|
|
344
|
+
appName: import_zod.z.string(),
|
|
345
|
+
scheme: import_zod.z.string(),
|
|
346
|
+
outdir: import_zod.z.string().default("dist"),
|
|
347
|
+
entryFile: import_zod.z.string().default("./src/_app.tsx"),
|
|
348
|
+
build: import_zod.z.custom().optional(),
|
|
349
|
+
devServer: import_zod.z.custom().optional(),
|
|
350
|
+
metro: import_zod.z.custom().optional(),
|
|
351
|
+
plugins: import_zod.z.custom()
|
|
352
|
+
});
|
|
353
|
+
var defineConfig = async (config) => {
|
|
354
|
+
const parsed = graniteConfigSchema.parse(config);
|
|
355
|
+
const cwd = parsed.cwd ?? (0, import_utils3.getPackageRoot)();
|
|
356
|
+
const appName = parsed.appName;
|
|
357
|
+
const scheme = parsed.scheme;
|
|
358
|
+
const entryFile = import_path5.default.resolve(cwd, parsed.entryFile);
|
|
359
|
+
const outdir = import_path5.default.join(cwd, parsed.outdir);
|
|
360
|
+
const parsedBuildConfig = parsed.build;
|
|
361
|
+
const parsedDevServerConfig = parsed.devServer;
|
|
362
|
+
const parsedMetroConfig = parsed.metro;
|
|
363
|
+
const parsedConfig = {
|
|
364
|
+
...parsedBuildConfig,
|
|
365
|
+
devServer: parsedDevServerConfig,
|
|
366
|
+
metro: parsedMetroConfig
|
|
367
|
+
};
|
|
368
|
+
const { configs, pluginHooks } = await (0, import_plugin_core3.resolvePlugins)(parsed.plugins);
|
|
369
|
+
const globalsScriptConfig = prepareGraniteGlobalsScript({ rootDir: cwd, appName, scheme });
|
|
370
|
+
const mergedConfig = (0, import_plugin_core3.mergeConfig)(parsedConfig, ...[globalsScriptConfig, ...configs].filter(import_es_toolkit2.isNotNil));
|
|
371
|
+
const { metro, devServer, ...buildConfig } = mergedConfig ?? {};
|
|
372
|
+
return {
|
|
373
|
+
cwd,
|
|
374
|
+
entryFile,
|
|
375
|
+
appName,
|
|
376
|
+
scheme,
|
|
377
|
+
outdir,
|
|
378
|
+
devServer,
|
|
379
|
+
pluginHooks,
|
|
380
|
+
build: {
|
|
381
|
+
...buildConfig,
|
|
382
|
+
entry: entryFile
|
|
383
|
+
},
|
|
384
|
+
metro: {
|
|
385
|
+
...metro,
|
|
386
|
+
babelConfig: mergedConfig?.babel,
|
|
387
|
+
transformSync: mergedConfig?.transformer?.transformSync
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
// src/index.ts
|
|
393
|
+
var cli = new import_clipanion4.Cli({
|
|
394
|
+
binaryLabel: "granite",
|
|
395
|
+
binaryName: "granite",
|
|
396
|
+
enableCapture: true
|
|
397
|
+
});
|
|
398
|
+
async function initialize() {
|
|
399
|
+
const explorer = await (0, import_cosmiconfig2.cosmiconfig)("mpack");
|
|
400
|
+
const result = await explorer.search(process.cwd());
|
|
401
|
+
cli.register(BuildCommand);
|
|
402
|
+
cli.register(HermesCommand);
|
|
403
|
+
cli.register(DevCommand);
|
|
404
|
+
cli.register(import_clipanion4.Builtins.HelpCommand);
|
|
405
|
+
if (Array.isArray(result?.config?.commands)) {
|
|
406
|
+
(result?.config?.commands).forEach((command) => cli.register(command));
|
|
407
|
+
}
|
|
408
|
+
cli.runExit(process.argv.slice(2));
|
|
409
|
+
}
|
|
410
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
411
|
+
0 && (module.exports = {
|
|
412
|
+
defineConfig,
|
|
413
|
+
initialize,
|
|
414
|
+
loadConfig
|
|
415
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DevServerConfig, AdditionalMetroConfig, MetroDevServerConfig, BuildConfig as BuildConfig$1 } from '@granite-js/mpack';
|
|
2
|
+
import { BuildConfig, PluginInput, GranitePluginDevPreHandler, GranitePluginDevPostHandler, GranitePluginBuildPreHandler, GranitePluginBuildPostHandler } from '@granite-js/plugin-core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const graniteConfigSchema: z.ZodObject<{
|
|
6
|
+
cwd: z.ZodDefault<z.ZodString>;
|
|
7
|
+
appName: z.ZodString;
|
|
8
|
+
scheme: z.ZodString;
|
|
9
|
+
outdir: z.ZodDefault<z.ZodString>;
|
|
10
|
+
entryFile: z.ZodDefault<z.ZodString>;
|
|
11
|
+
build: z.ZodOptional<z.ZodType<BuildConfig, z.ZodTypeDef, BuildConfig>>;
|
|
12
|
+
devServer: z.ZodOptional<z.ZodType<DevServerConfig, z.ZodTypeDef, DevServerConfig>>;
|
|
13
|
+
metro: z.ZodOptional<z.ZodType<AdditionalMetroConfig & MetroDevServerConfig, z.ZodTypeDef, AdditionalMetroConfig & MetroDevServerConfig>>;
|
|
14
|
+
plugins: z.ZodType<PluginInput, z.ZodTypeDef, PluginInput>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
appName: string;
|
|
17
|
+
scheme: string;
|
|
18
|
+
cwd: string;
|
|
19
|
+
outdir: string;
|
|
20
|
+
entryFile: string;
|
|
21
|
+
plugins: PluginInput;
|
|
22
|
+
build?: BuildConfig | undefined;
|
|
23
|
+
metro?: (AdditionalMetroConfig & MetroDevServerConfig) | undefined;
|
|
24
|
+
devServer?: DevServerConfig | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
appName: string;
|
|
27
|
+
scheme: string;
|
|
28
|
+
plugins: PluginInput;
|
|
29
|
+
build?: BuildConfig | undefined;
|
|
30
|
+
metro?: (AdditionalMetroConfig & MetroDevServerConfig) | undefined;
|
|
31
|
+
cwd?: string | undefined;
|
|
32
|
+
outdir?: string | undefined;
|
|
33
|
+
entryFile?: string | undefined;
|
|
34
|
+
devServer?: DevServerConfig | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type GraniteConfig = z.input<typeof graniteConfigSchema>;
|
|
37
|
+
type CompleteGraniteConfig = Omit<z.output<typeof graniteConfigSchema>, 'build' | 'plugins'> & {
|
|
38
|
+
build: Omit<BuildConfig$1, 'platform' | 'outfile'>;
|
|
39
|
+
pluginHooks: GranitePluginHooks;
|
|
40
|
+
};
|
|
41
|
+
interface GranitePluginHooks {
|
|
42
|
+
devServer: {
|
|
43
|
+
preHandlers: GranitePluginDevPreHandler[];
|
|
44
|
+
postHandlers: GranitePluginDevPostHandler[];
|
|
45
|
+
};
|
|
46
|
+
build: {
|
|
47
|
+
preHandlers: GranitePluginBuildPreHandler[];
|
|
48
|
+
postHandlers: GranitePluginBuildPostHandler[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
* @category Configuration
|
|
54
|
+
* @name defineConfig
|
|
55
|
+
* @description
|
|
56
|
+
* Configures your Granite application by defining key settings in `granite.config.ts`.
|
|
57
|
+
*
|
|
58
|
+
* The configuration lets you specify:
|
|
59
|
+
* - How users will access your app through a URL scheme (e.g. `granite://`)
|
|
60
|
+
* - Your app's unique name that appears in the URL (e.g. `granite://my-service`)
|
|
61
|
+
* - Build settings for bundlers like ESBuild and Metro
|
|
62
|
+
* - Code transformation settings through Babel
|
|
63
|
+
* - Additional functionality through Granite plugins
|
|
64
|
+
*
|
|
65
|
+
* @param config - Configuration options
|
|
66
|
+
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
67
|
+
* @param config.appName - Your app's unique identifier
|
|
68
|
+
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
69
|
+
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
70
|
+
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
71
|
+
* @param config.build - Customize build settings
|
|
72
|
+
* @param config.metro - Configure Metro bundler settings
|
|
73
|
+
* @param config.devServer - Configure Mpack dev server settings
|
|
74
|
+
* @param config.plugins - Granite plugins to enhance functionality
|
|
75
|
+
* @returns The processed configuration
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* Here's a basic configuration that:
|
|
79
|
+
* - Makes your app accessible via the `granite://` scheme
|
|
80
|
+
* - Names your service "my-app" so it's reachable at `granite://my-app`
|
|
81
|
+
* - Uses the Hermes plugin to optimize JavaScript bundles into bytecode
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { defineConfig } from '@granite-js/react-native/config';
|
|
85
|
+
* import { hermes } from '@granite-js/plugin-hermes';
|
|
86
|
+
*
|
|
87
|
+
* export default defineConfig({
|
|
88
|
+
* // The name of your microservice
|
|
89
|
+
* appName: 'my-app',
|
|
90
|
+
* // The URL scheme for deep linking
|
|
91
|
+
* scheme: 'granite',
|
|
92
|
+
* // Entry file path
|
|
93
|
+
* entryFile: 'index.ts',
|
|
94
|
+
* // Array of plugins to use
|
|
95
|
+
* plugins: [hermes()],
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
100
|
+
|
|
101
|
+
declare const loadConfig: () => Promise<CompleteGraniteConfig>;
|
|
102
|
+
|
|
103
|
+
declare function initialize(): Promise<void>;
|
|
104
|
+
|
|
105
|
+
export { type CompleteGraniteConfig, type GraniteConfig, type GranitePluginHooks, defineConfig, initialize, loadConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DevServerConfig, AdditionalMetroConfig, MetroDevServerConfig, BuildConfig as BuildConfig$1 } from '@granite-js/mpack';
|
|
2
|
+
import { BuildConfig, PluginInput, GranitePluginDevPreHandler, GranitePluginDevPostHandler, GranitePluginBuildPreHandler, GranitePluginBuildPostHandler } from '@granite-js/plugin-core';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const graniteConfigSchema: z.ZodObject<{
|
|
6
|
+
cwd: z.ZodDefault<z.ZodString>;
|
|
7
|
+
appName: z.ZodString;
|
|
8
|
+
scheme: z.ZodString;
|
|
9
|
+
outdir: z.ZodDefault<z.ZodString>;
|
|
10
|
+
entryFile: z.ZodDefault<z.ZodString>;
|
|
11
|
+
build: z.ZodOptional<z.ZodType<BuildConfig, z.ZodTypeDef, BuildConfig>>;
|
|
12
|
+
devServer: z.ZodOptional<z.ZodType<DevServerConfig, z.ZodTypeDef, DevServerConfig>>;
|
|
13
|
+
metro: z.ZodOptional<z.ZodType<AdditionalMetroConfig & MetroDevServerConfig, z.ZodTypeDef, AdditionalMetroConfig & MetroDevServerConfig>>;
|
|
14
|
+
plugins: z.ZodType<PluginInput, z.ZodTypeDef, PluginInput>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
appName: string;
|
|
17
|
+
scheme: string;
|
|
18
|
+
cwd: string;
|
|
19
|
+
outdir: string;
|
|
20
|
+
entryFile: string;
|
|
21
|
+
plugins: PluginInput;
|
|
22
|
+
build?: BuildConfig | undefined;
|
|
23
|
+
metro?: (AdditionalMetroConfig & MetroDevServerConfig) | undefined;
|
|
24
|
+
devServer?: DevServerConfig | undefined;
|
|
25
|
+
}, {
|
|
26
|
+
appName: string;
|
|
27
|
+
scheme: string;
|
|
28
|
+
plugins: PluginInput;
|
|
29
|
+
build?: BuildConfig | undefined;
|
|
30
|
+
metro?: (AdditionalMetroConfig & MetroDevServerConfig) | undefined;
|
|
31
|
+
cwd?: string | undefined;
|
|
32
|
+
outdir?: string | undefined;
|
|
33
|
+
entryFile?: string | undefined;
|
|
34
|
+
devServer?: DevServerConfig | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
type GraniteConfig = z.input<typeof graniteConfigSchema>;
|
|
37
|
+
type CompleteGraniteConfig = Omit<z.output<typeof graniteConfigSchema>, 'build' | 'plugins'> & {
|
|
38
|
+
build: Omit<BuildConfig$1, 'platform' | 'outfile'>;
|
|
39
|
+
pluginHooks: GranitePluginHooks;
|
|
40
|
+
};
|
|
41
|
+
interface GranitePluginHooks {
|
|
42
|
+
devServer: {
|
|
43
|
+
preHandlers: GranitePluginDevPreHandler[];
|
|
44
|
+
postHandlers: GranitePluginDevPostHandler[];
|
|
45
|
+
};
|
|
46
|
+
build: {
|
|
47
|
+
preHandlers: GranitePluginBuildPreHandler[];
|
|
48
|
+
postHandlers: GranitePluginBuildPostHandler[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
* @category Configuration
|
|
54
|
+
* @name defineConfig
|
|
55
|
+
* @description
|
|
56
|
+
* Configures your Granite application by defining key settings in `granite.config.ts`.
|
|
57
|
+
*
|
|
58
|
+
* The configuration lets you specify:
|
|
59
|
+
* - How users will access your app through a URL scheme (e.g. `granite://`)
|
|
60
|
+
* - Your app's unique name that appears in the URL (e.g. `granite://my-service`)
|
|
61
|
+
* - Build settings for bundlers like ESBuild and Metro
|
|
62
|
+
* - Code transformation settings through Babel
|
|
63
|
+
* - Additional functionality through Granite plugins
|
|
64
|
+
*
|
|
65
|
+
* @param config - Configuration options
|
|
66
|
+
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
67
|
+
* @param config.appName - Your app's unique identifier
|
|
68
|
+
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
69
|
+
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
70
|
+
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
71
|
+
* @param config.build - Customize build settings
|
|
72
|
+
* @param config.metro - Configure Metro bundler settings
|
|
73
|
+
* @param config.devServer - Configure Mpack dev server settings
|
|
74
|
+
* @param config.plugins - Granite plugins to enhance functionality
|
|
75
|
+
* @returns The processed configuration
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* Here's a basic configuration that:
|
|
79
|
+
* - Makes your app accessible via the `granite://` scheme
|
|
80
|
+
* - Names your service "my-app" so it's reachable at `granite://my-app`
|
|
81
|
+
* - Uses the Hermes plugin to optimize JavaScript bundles into bytecode
|
|
82
|
+
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* import { defineConfig } from '@granite-js/react-native/config';
|
|
85
|
+
* import { hermes } from '@granite-js/plugin-hermes';
|
|
86
|
+
*
|
|
87
|
+
* export default defineConfig({
|
|
88
|
+
* // The name of your microservice
|
|
89
|
+
* appName: 'my-app',
|
|
90
|
+
* // The URL scheme for deep linking
|
|
91
|
+
* scheme: 'granite',
|
|
92
|
+
* // Entry file path
|
|
93
|
+
* entryFile: 'index.ts',
|
|
94
|
+
* // Array of plugins to use
|
|
95
|
+
* plugins: [hermes()],
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
100
|
+
|
|
101
|
+
declare const loadConfig: () => Promise<CompleteGraniteConfig>;
|
|
102
|
+
|
|
103
|
+
declare function initialize(): Promise<void>;
|
|
104
|
+
|
|
105
|
+
export { type CompleteGraniteConfig, type GraniteConfig, type GranitePluginHooks, defineConfig, initialize, loadConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import { Builtins, Cli } from "clipanion";
|
|
11
|
+
import { cosmiconfig as cosmiconfig2 } from "cosmiconfig";
|
|
12
|
+
|
|
13
|
+
// src/commands/BuildCommand/BuildCommand.ts
|
|
14
|
+
import { Command, Option } from "clipanion";
|
|
15
|
+
|
|
16
|
+
// src/commands/BuildCommand/build.ts
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { runBundle } from "@granite-js/mpack";
|
|
19
|
+
import { statusPlugin } from "@granite-js/mpack/plugins";
|
|
20
|
+
import { createContext } from "@granite-js/plugin-core";
|
|
21
|
+
async function build(config, options) {
|
|
22
|
+
const pluginContext = createContext();
|
|
23
|
+
for (const preHandler of config.pluginHooks.build.preHandlers) {
|
|
24
|
+
await preHandler.call(pluginContext, {
|
|
25
|
+
cwd: config.cwd,
|
|
26
|
+
entryFile: config.entryFile,
|
|
27
|
+
appName: config.appName,
|
|
28
|
+
outdir: config.outdir
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const buildResults = await Promise.all(
|
|
32
|
+
["ios", "android"].map(
|
|
33
|
+
(platform) => runBundle({
|
|
34
|
+
rootDir: config.cwd,
|
|
35
|
+
dev: false,
|
|
36
|
+
metafile: true,
|
|
37
|
+
cache: options.cache,
|
|
38
|
+
plugins: [statusPlugin],
|
|
39
|
+
buildConfig: { platform, outfile: path.join(config.outdir, `bundle.${platform}.js`), ...config.build }
|
|
40
|
+
})
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
for (const postHandler of config.pluginHooks.build.postHandlers) {
|
|
44
|
+
await postHandler.call(pluginContext, {
|
|
45
|
+
cwd: config.cwd,
|
|
46
|
+
entryFile: config.entryFile,
|
|
47
|
+
appName: config.appName,
|
|
48
|
+
outdir: config.outdir,
|
|
49
|
+
buildResults
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/config/loadConfig.ts
|
|
55
|
+
import { getPackageRoot } from "@granite-js/utils";
|
|
56
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
57
|
+
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
58
|
+
var MODULE_NAME = "granite";
|
|
59
|
+
var loadConfig = async () => {
|
|
60
|
+
const explorer = cosmiconfig(MODULE_NAME, {
|
|
61
|
+
searchPlaces: [
|
|
62
|
+
`${MODULE_NAME}.config.ts`,
|
|
63
|
+
`${MODULE_NAME}.config.mts`,
|
|
64
|
+
`${MODULE_NAME}.config.js`,
|
|
65
|
+
`${MODULE_NAME}.config.cjs`
|
|
66
|
+
],
|
|
67
|
+
loaders: {
|
|
68
|
+
".ts": TypeScriptLoader(),
|
|
69
|
+
".mts": TypeScriptLoader()
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const result = await explorer.search(getPackageRoot());
|
|
73
|
+
const config = await result?.config;
|
|
74
|
+
return config;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/commands/BuildCommand/BuildCommand.ts
|
|
78
|
+
var BuildCommand = class extends Command {
|
|
79
|
+
static paths = [[`build`]];
|
|
80
|
+
static usage = Command.Usage({
|
|
81
|
+
category: "Build",
|
|
82
|
+
description: "Build Granite App",
|
|
83
|
+
examples: [["Build Granite App", "granite build"]]
|
|
84
|
+
});
|
|
85
|
+
disableCache = Option.Boolean("--disable-cache", {
|
|
86
|
+
description: "Disable cache"
|
|
87
|
+
});
|
|
88
|
+
async execute() {
|
|
89
|
+
try {
|
|
90
|
+
const { disableCache = false } = this;
|
|
91
|
+
const config = await loadConfig();
|
|
92
|
+
await build(config, {
|
|
93
|
+
cache: !disableCache
|
|
94
|
+
});
|
|
95
|
+
return 0;
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(error);
|
|
98
|
+
return 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/commands/HermesCommand/HermesCommand.ts
|
|
104
|
+
import path3 from "path";
|
|
105
|
+
import chalk from "chalk";
|
|
106
|
+
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
107
|
+
|
|
108
|
+
// src/utils/compileHbc.ts
|
|
109
|
+
import assert from "assert";
|
|
110
|
+
import os from "os";
|
|
111
|
+
import path2 from "path";
|
|
112
|
+
import { isNotNil } from "es-toolkit";
|
|
113
|
+
import execa from "execa";
|
|
114
|
+
var binary = {
|
|
115
|
+
Darwin: "react-native/sdks/hermesc/osx-bin/hermesc",
|
|
116
|
+
Linux: "react-native/sdks/hermesc/linux64-bin/hermesc",
|
|
117
|
+
Windows_NT: "react-native/sdks/hermesc/win64-bin/hermesc.exe"
|
|
118
|
+
};
|
|
119
|
+
async function compileHbc({ rootDir, filePath, sourcemap }) {
|
|
120
|
+
const binary2 = getHermesc(rootDir);
|
|
121
|
+
const outfile = path2.resolve(rootDir, filePath.replace(new RegExp(`${path2.extname(filePath)}$`), ".hbc"));
|
|
122
|
+
await execa(
|
|
123
|
+
binary2,
|
|
124
|
+
[
|
|
125
|
+
// Disable warnings
|
|
126
|
+
"-w",
|
|
127
|
+
// Expensive optimizations
|
|
128
|
+
"-O",
|
|
129
|
+
// Emit binary
|
|
130
|
+
"-emit-binary",
|
|
131
|
+
// Emit source map
|
|
132
|
+
sourcemap ? "-output-source-map" : null,
|
|
133
|
+
// Output path
|
|
134
|
+
"-out",
|
|
135
|
+
outfile,
|
|
136
|
+
filePath
|
|
137
|
+
].filter(isNotNil)
|
|
138
|
+
);
|
|
139
|
+
return { outfile, sourcemapOutfile: sourcemap ? `${outfile}.map` : null };
|
|
140
|
+
}
|
|
141
|
+
function getHermesc(rootDir) {
|
|
142
|
+
const os2 = getOs();
|
|
143
|
+
const binarySource = binary[os2];
|
|
144
|
+
assert(binarySource, `\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 OS \uC785\uB2C8\uB2E4: ${os2}`);
|
|
145
|
+
return resolveFromRoot(rootDir, binarySource);
|
|
146
|
+
}
|
|
147
|
+
function getOs() {
|
|
148
|
+
return os.type();
|
|
149
|
+
}
|
|
150
|
+
function resolveFromRoot(rootDir, request) {
|
|
151
|
+
return __require.resolve(request, { paths: [rootDir] });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/commands/HermesCommand/HermesCommand.ts
|
|
155
|
+
var HermesCommand = class extends Command2 {
|
|
156
|
+
static paths = [[`hermes`]];
|
|
157
|
+
static usage = Command2.Usage({
|
|
158
|
+
category: "Hermes",
|
|
159
|
+
description: "\uC9C0\uC815\uD55C \uBC88\uB4E4\uC744 Hermes \uBC14\uC774\uD2B8 \uCF54\uB4DC\uB85C \uCEF4\uD30C\uC77C \uD569\uB2C8\uB2E4",
|
|
160
|
+
examples: [["\uCEF4\uD30C\uC77C\uD558\uAE30", "granite hermes --jsbundle dist/bundle.js"]]
|
|
161
|
+
});
|
|
162
|
+
jsBundleFile = Option2.String("--jsbundle", {
|
|
163
|
+
required: true,
|
|
164
|
+
description: "Hermes \uBC14\uC774\uD2B8 \uCF54\uB4DC\uB85C \uCEF4\uD30C\uC77C \uD560 Javascript \uD30C\uC77C \uACBD\uB85C \uC785\uB2C8\uB2E4"
|
|
165
|
+
});
|
|
166
|
+
sourcemap = Option2.Boolean("--sourcemap", true, {
|
|
167
|
+
description: "\uC18C\uC2A4\uB9F5 \uD30C\uC77C\uC744 \uC0DD\uC131\uD569\uB2C8\uB2E4"
|
|
168
|
+
});
|
|
169
|
+
async execute() {
|
|
170
|
+
try {
|
|
171
|
+
const rootDir = process.cwd();
|
|
172
|
+
const filePath = path3.resolve(rootDir, this.jsBundleFile);
|
|
173
|
+
const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
|
|
174
|
+
console.log(`\u2705 \uCEF4\uD30C\uC77C \uC644\uB8CC: ${chalk.gray(outfile)}`);
|
|
175
|
+
if (sourcemapOutfile) {
|
|
176
|
+
console.log(`\u2705 \uC18C\uC2A4\uB9F5 \uC0DD\uC131 \uC644\uB8CC: ${chalk.gray(sourcemapOutfile)}`);
|
|
177
|
+
}
|
|
178
|
+
return 0;
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(error.stack);
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// src/commands/DevCommand/DevCommand.ts
|
|
187
|
+
import * as mpack from "@granite-js/mpack";
|
|
188
|
+
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
189
|
+
import Debug from "debug";
|
|
190
|
+
|
|
191
|
+
// src/commands/DevCommand/startDevServer.ts
|
|
192
|
+
import { runServer } from "@granite-js/mpack";
|
|
193
|
+
import { createContext as createContext2 } from "@granite-js/plugin-core";
|
|
194
|
+
async function startDevServer(serverOptions, config) {
|
|
195
|
+
const pluginContext = createContext2();
|
|
196
|
+
const commonHandlerArgs = {
|
|
197
|
+
host: serverOptions.host,
|
|
198
|
+
port: serverOptions.port,
|
|
199
|
+
appName: config.appName,
|
|
200
|
+
outdir: config.outdir,
|
|
201
|
+
cwd: config.cwd,
|
|
202
|
+
entryFile: config.build.entry
|
|
203
|
+
};
|
|
204
|
+
for (const preHandler of config.pluginHooks.devServer.preHandlers) {
|
|
205
|
+
await preHandler.call(pluginContext, commonHandlerArgs);
|
|
206
|
+
}
|
|
207
|
+
await runServer({
|
|
208
|
+
cwd: config.cwd,
|
|
209
|
+
host: serverOptions.host,
|
|
210
|
+
port: serverOptions.port,
|
|
211
|
+
middlewares: config.metro?.middlewares,
|
|
212
|
+
enableEmbeddedReactDevTools: !serverOptions.disableEmbeddedReactDevTools,
|
|
213
|
+
additionalConfig: config.metro,
|
|
214
|
+
onServerReady: async () => {
|
|
215
|
+
for (const postHandler of config.pluginHooks.devServer.postHandlers) {
|
|
216
|
+
await postHandler.call(pluginContext, commonHandlerArgs);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/commands/DevCommand/DevCommand.ts
|
|
223
|
+
var debug = Debug("cli");
|
|
224
|
+
var DEFAULT_HOST = "0.0.0.0";
|
|
225
|
+
var DEFAULT_LOCALHOST_PORT = 8081;
|
|
226
|
+
var DevCommand = class extends Command3 {
|
|
227
|
+
static paths = [[`dev`]];
|
|
228
|
+
static usage = Command3.Usage({
|
|
229
|
+
category: "Development",
|
|
230
|
+
description: "Run Granite development server",
|
|
231
|
+
examples: [["Run Granite development server", "granite dev"]]
|
|
232
|
+
});
|
|
233
|
+
host = Option3.String("--host");
|
|
234
|
+
port = Option3.String("--port");
|
|
235
|
+
disableEmbeddedReactDevTools = Option3.Boolean("--disable-embedded-react-devtools", false);
|
|
236
|
+
// mpack dev-server
|
|
237
|
+
experimentalMode = Option3.Boolean("--experimental-mode");
|
|
238
|
+
async execute() {
|
|
239
|
+
try {
|
|
240
|
+
process.env.MPACK_DEV_SERVER = "true";
|
|
241
|
+
const config = await loadConfig();
|
|
242
|
+
const serverOptions = {
|
|
243
|
+
host: this.host,
|
|
244
|
+
port: this.port ? parseInt(this.port, 10) : void 0
|
|
245
|
+
};
|
|
246
|
+
debug("StartCommand", {
|
|
247
|
+
...serverOptions,
|
|
248
|
+
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
249
|
+
experimentalMode: this.experimentalMode
|
|
250
|
+
});
|
|
251
|
+
if (this.experimentalMode) {
|
|
252
|
+
await mpack.EXPERIMENTAL__runServer({
|
|
253
|
+
buildConfig: config.build,
|
|
254
|
+
host: serverOptions.host,
|
|
255
|
+
port: serverOptions.port
|
|
256
|
+
});
|
|
257
|
+
} else {
|
|
258
|
+
await startDevServer(
|
|
259
|
+
{
|
|
260
|
+
host: serverOptions.host || DEFAULT_HOST,
|
|
261
|
+
port: serverOptions.port || DEFAULT_LOCALHOST_PORT,
|
|
262
|
+
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools
|
|
263
|
+
},
|
|
264
|
+
config
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.log(`ERROR OCCURRED`);
|
|
269
|
+
console.log(error);
|
|
270
|
+
console.log(error.message);
|
|
271
|
+
console.error(error.stack);
|
|
272
|
+
process.exit(1);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// src/config/defineConfig.ts
|
|
278
|
+
import path5 from "path";
|
|
279
|
+
import {
|
|
280
|
+
resolvePlugins,
|
|
281
|
+
mergeConfig
|
|
282
|
+
} from "@granite-js/plugin-core";
|
|
283
|
+
import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
|
|
284
|
+
import { isNotNil as isNotNil2 } from "es-toolkit";
|
|
285
|
+
import { z } from "zod";
|
|
286
|
+
|
|
287
|
+
// src/config/graniteGlobals.ts
|
|
288
|
+
import fs from "fs";
|
|
289
|
+
import path4 from "path";
|
|
290
|
+
import { getLocalTempDirectoryPath, prepareLocalDirectory } from "@granite-js/utils";
|
|
291
|
+
function prepareGraniteGlobalsScript(config) {
|
|
292
|
+
const filePath = writeGraniteGlobalsScript(config);
|
|
293
|
+
return {
|
|
294
|
+
esbuild: {
|
|
295
|
+
prelude: [filePath]
|
|
296
|
+
},
|
|
297
|
+
metro: {
|
|
298
|
+
prelude: [filePath]
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function writeGraniteGlobalsScript(config) {
|
|
303
|
+
const script = getGraniteGlobalScript(config);
|
|
304
|
+
const filePath = path4.join(getLocalTempDirectoryPath(config.rootDir), "granite-globals.js");
|
|
305
|
+
prepareLocalDirectory(config.rootDir);
|
|
306
|
+
fs.writeFileSync(filePath, script, "utf-8");
|
|
307
|
+
return filePath;
|
|
308
|
+
}
|
|
309
|
+
function getGraniteGlobalScript({ appName, scheme }) {
|
|
310
|
+
return [
|
|
311
|
+
"global.__granite = global.__granite || {};",
|
|
312
|
+
`global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`
|
|
313
|
+
].join("\n");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/config/defineConfig.ts
|
|
317
|
+
var graniteConfigSchema = z.object({
|
|
318
|
+
cwd: z.string().default(process.cwd()),
|
|
319
|
+
appName: z.string(),
|
|
320
|
+
scheme: z.string(),
|
|
321
|
+
outdir: z.string().default("dist"),
|
|
322
|
+
entryFile: z.string().default("./src/_app.tsx"),
|
|
323
|
+
build: z.custom().optional(),
|
|
324
|
+
devServer: z.custom().optional(),
|
|
325
|
+
metro: z.custom().optional(),
|
|
326
|
+
plugins: z.custom()
|
|
327
|
+
});
|
|
328
|
+
var defineConfig = async (config) => {
|
|
329
|
+
const parsed = graniteConfigSchema.parse(config);
|
|
330
|
+
const cwd = parsed.cwd ?? getPackageRoot2();
|
|
331
|
+
const appName = parsed.appName;
|
|
332
|
+
const scheme = parsed.scheme;
|
|
333
|
+
const entryFile = path5.resolve(cwd, parsed.entryFile);
|
|
334
|
+
const outdir = path5.join(cwd, parsed.outdir);
|
|
335
|
+
const parsedBuildConfig = parsed.build;
|
|
336
|
+
const parsedDevServerConfig = parsed.devServer;
|
|
337
|
+
const parsedMetroConfig = parsed.metro;
|
|
338
|
+
const parsedConfig = {
|
|
339
|
+
...parsedBuildConfig,
|
|
340
|
+
devServer: parsedDevServerConfig,
|
|
341
|
+
metro: parsedMetroConfig
|
|
342
|
+
};
|
|
343
|
+
const { configs, pluginHooks } = await resolvePlugins(parsed.plugins);
|
|
344
|
+
const globalsScriptConfig = prepareGraniteGlobalsScript({ rootDir: cwd, appName, scheme });
|
|
345
|
+
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(isNotNil2));
|
|
346
|
+
const { metro, devServer, ...buildConfig } = mergedConfig ?? {};
|
|
347
|
+
return {
|
|
348
|
+
cwd,
|
|
349
|
+
entryFile,
|
|
350
|
+
appName,
|
|
351
|
+
scheme,
|
|
352
|
+
outdir,
|
|
353
|
+
devServer,
|
|
354
|
+
pluginHooks,
|
|
355
|
+
build: {
|
|
356
|
+
...buildConfig,
|
|
357
|
+
entry: entryFile
|
|
358
|
+
},
|
|
359
|
+
metro: {
|
|
360
|
+
...metro,
|
|
361
|
+
babelConfig: mergedConfig?.babel,
|
|
362
|
+
transformSync: mergedConfig?.transformer?.transformSync
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/index.ts
|
|
368
|
+
var cli = new Cli({
|
|
369
|
+
binaryLabel: "granite",
|
|
370
|
+
binaryName: "granite",
|
|
371
|
+
enableCapture: true
|
|
372
|
+
});
|
|
373
|
+
async function initialize() {
|
|
374
|
+
const explorer = await cosmiconfig2("mpack");
|
|
375
|
+
const result = await explorer.search(process.cwd());
|
|
376
|
+
cli.register(BuildCommand);
|
|
377
|
+
cli.register(HermesCommand);
|
|
378
|
+
cli.register(DevCommand);
|
|
379
|
+
cli.register(Builtins.HelpCommand);
|
|
380
|
+
if (Array.isArray(result?.config?.commands)) {
|
|
381
|
+
(result?.config?.commands).forEach((command) => cli.register(command));
|
|
382
|
+
}
|
|
383
|
+
cli.runExit(process.argv.slice(2));
|
|
384
|
+
}
|
|
385
|
+
export {
|
|
386
|
+
defineConfig,
|
|
387
|
+
initialize,
|
|
388
|
+
loadConfig
|
|
389
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@granite-js/cli",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0-dev-20250725013859",
|
|
5
|
+
"description": "The Granite CLI",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"bin": "node scripts/run.js",
|
|
19
|
+
"prepack": "yarn build",
|
|
20
|
+
"typecheck": "tsc --noEmit",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"find-deadcode": "ts-prune",
|
|
23
|
+
"build": "tsup"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"package.json"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@babel/core": "^7.24.9",
|
|
31
|
+
"@babel/preset-env": "^7.24.8",
|
|
32
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
33
|
+
"@types/babel__core": "^7",
|
|
34
|
+
"@types/babel__preset-env": "^7",
|
|
35
|
+
"@types/connect": "^3",
|
|
36
|
+
"@types/debug": "^4",
|
|
37
|
+
"@types/node": "^22.10.2",
|
|
38
|
+
"@types/serve-static": "^1",
|
|
39
|
+
"esbuild": "^0.25.4",
|
|
40
|
+
"eslint": "^9.7.0",
|
|
41
|
+
"ts-prune": "^0.10.3",
|
|
42
|
+
"tsup": "^8.5.0",
|
|
43
|
+
"typescript": "5.8.3",
|
|
44
|
+
"vitest": "^3.0.7"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@granite-js/mpack": "workspace:*",
|
|
48
|
+
"@granite-js/plugin-core": "workspace:*",
|
|
49
|
+
"@granite-js/utils": "workspace:*",
|
|
50
|
+
"@inquirer/prompts": "^7.2.3",
|
|
51
|
+
"@shopify/semaphore": "^3.1.0",
|
|
52
|
+
"chalk": "^4",
|
|
53
|
+
"clipanion": "^4.0.0-rc.4",
|
|
54
|
+
"connect": "^3.7.0",
|
|
55
|
+
"cosmiconfig": "^9.0.0",
|
|
56
|
+
"cosmiconfig-typescript-loader": "^5.1.0",
|
|
57
|
+
"debug": "^4.3.7",
|
|
58
|
+
"enquirer": "^2.4.1",
|
|
59
|
+
"es-toolkit": "^1.32.0",
|
|
60
|
+
"execa": "^5",
|
|
61
|
+
"ora": "^5",
|
|
62
|
+
"typanion": "^3.14.0",
|
|
63
|
+
"zod": "3.24.4"
|
|
64
|
+
}
|
|
65
|
+
}
|