@blastlauncher/cli 1.0.5 → 3.0.0-alpha.0

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/index.cjs DELETED
@@ -1,368 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJS = (cb, mod) => function __require() {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
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
-
29
- // ../../node_modules/.pnpm/temp-dir@2.0.0/node_modules/temp-dir/index.js
30
- var require_temp_dir = __commonJS({
31
- "../../node_modules/.pnpm/temp-dir@2.0.0/node_modules/temp-dir/index.js"(exports, module2) {
32
- "use strict";
33
- var fs3 = require("fs");
34
- var os = require("os");
35
- var tempDirectorySymbol = Symbol.for("__RESOLVED_TEMP_DIRECTORY__");
36
- if (!global[tempDirectorySymbol]) {
37
- Object.defineProperty(global, tempDirectorySymbol, {
38
- value: fs3.realpathSync(os.tmpdir())
39
- });
40
- }
41
- module2.exports = global[tempDirectorySymbol];
42
- }
43
- });
44
-
45
- // index.js
46
- var import_child_process = require("child_process");
47
- var import_https = __toESM(require("https"));
48
- var import_path = __toESM(require("path"));
49
- var import_commander = require("commander");
50
- var import_esbuild = __toESM(require("esbuild"));
51
- var import_fs_extra = __toESM(require("fs-extra"));
52
- var import_semver = __toESM(require("semver"));
53
-
54
- // ../../node_modules/.pnpm/tempy@3.0.0/node_modules/tempy/index.js
55
- var import_node_fs = __toESM(require("node:fs"), 1);
56
- var import_node_path = __toESM(require("node:path"), 1);
57
- var import_node_stream = __toESM(require("node:stream"), 1);
58
- var import_node_util = require("node:util");
59
-
60
- // ../../node_modules/.pnpm/crypto-random-string@4.0.0/node_modules/crypto-random-string/index.js
61
- var import_util = require("util");
62
- var import_crypto = __toESM(require("crypto"), 1);
63
- var randomBytesAsync = (0, import_util.promisify)(import_crypto.default.randomBytes);
64
- var urlSafeCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~".split("");
65
- var numericCharacters = "0123456789".split("");
66
- var distinguishableCharacters = "CDEHKMPRTUWXY012458".split("");
67
- var asciiPrintableCharacters = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~".split("");
68
- var alphanumericCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split("");
69
- var generateForCustomCharacters = (length, characters) => {
70
- const characterCount = characters.length;
71
- const maxValidSelector = Math.floor(65536 / characterCount) * characterCount - 1;
72
- const entropyLength = 2 * Math.ceil(1.1 * length);
73
- let string = "";
74
- let stringLength = 0;
75
- while (stringLength < length) {
76
- const entropy = import_crypto.default.randomBytes(entropyLength);
77
- let entropyPosition = 0;
78
- while (entropyPosition < entropyLength && stringLength < length) {
79
- const entropyValue = entropy.readUInt16LE(entropyPosition);
80
- entropyPosition += 2;
81
- if (entropyValue > maxValidSelector) {
82
- continue;
83
- }
84
- string += characters[entropyValue % characterCount];
85
- stringLength++;
86
- }
87
- }
88
- return string;
89
- };
90
- var generateForCustomCharactersAsync = async (length, characters) => {
91
- const characterCount = characters.length;
92
- const maxValidSelector = Math.floor(65536 / characterCount) * characterCount - 1;
93
- const entropyLength = 2 * Math.ceil(1.1 * length);
94
- let string = "";
95
- let stringLength = 0;
96
- while (stringLength < length) {
97
- const entropy = await randomBytesAsync(entropyLength);
98
- let entropyPosition = 0;
99
- while (entropyPosition < entropyLength && stringLength < length) {
100
- const entropyValue = entropy.readUInt16LE(entropyPosition);
101
- entropyPosition += 2;
102
- if (entropyValue > maxValidSelector) {
103
- continue;
104
- }
105
- string += characters[entropyValue % characterCount];
106
- stringLength++;
107
- }
108
- }
109
- return string;
110
- };
111
- var generateRandomBytes = (byteLength, type, length) => import_crypto.default.randomBytes(byteLength).toString(type).slice(0, length);
112
- var generateRandomBytesAsync = async (byteLength, type, length) => {
113
- const buffer = await randomBytesAsync(byteLength);
114
- return buffer.toString(type).slice(0, length);
115
- };
116
- var allowedTypes = /* @__PURE__ */ new Set([
117
- void 0,
118
- "hex",
119
- "base64",
120
- "url-safe",
121
- "numeric",
122
- "distinguishable",
123
- "ascii-printable",
124
- "alphanumeric"
125
- ]);
126
- var createGenerator = (generateForCustomCharacters2, generateRandomBytes2) => ({ length, type, characters }) => {
127
- if (!(length >= 0 && Number.isFinite(length))) {
128
- throw new TypeError("Expected a `length` to be a non-negative finite number");
129
- }
130
- if (type !== void 0 && characters !== void 0) {
131
- throw new TypeError("Expected either `type` or `characters`");
132
- }
133
- if (characters !== void 0 && typeof characters !== "string") {
134
- throw new TypeError("Expected `characters` to be string");
135
- }
136
- if (!allowedTypes.has(type)) {
137
- throw new TypeError(`Unknown type: ${type}`);
138
- }
139
- if (type === void 0 && characters === void 0) {
140
- type = "hex";
141
- }
142
- if (type === "hex" || type === void 0 && characters === void 0) {
143
- return generateRandomBytes2(Math.ceil(length * 0.5), "hex", length);
144
- }
145
- if (type === "base64") {
146
- return generateRandomBytes2(Math.ceil(length * 0.75), "base64", length);
147
- }
148
- if (type === "url-safe") {
149
- return generateForCustomCharacters2(length, urlSafeCharacters);
150
- }
151
- if (type === "numeric") {
152
- return generateForCustomCharacters2(length, numericCharacters);
153
- }
154
- if (type === "distinguishable") {
155
- return generateForCustomCharacters2(length, distinguishableCharacters);
156
- }
157
- if (type === "ascii-printable") {
158
- return generateForCustomCharacters2(length, asciiPrintableCharacters);
159
- }
160
- if (type === "alphanumeric") {
161
- return generateForCustomCharacters2(length, alphanumericCharacters);
162
- }
163
- if (characters.length === 0) {
164
- throw new TypeError("Expected `characters` string length to be greater than or equal to 1");
165
- }
166
- if (characters.length > 65536) {
167
- throw new TypeError("Expected `characters` string length to be less or equal to 65536");
168
- }
169
- return generateForCustomCharacters2(length, characters.split(""));
170
- };
171
- var cryptoRandomString = createGenerator(generateForCustomCharacters, generateRandomBytes);
172
- cryptoRandomString.async = createGenerator(generateForCustomCharactersAsync, generateRandomBytesAsync);
173
- var crypto_random_string_default = cryptoRandomString;
174
-
175
- // ../../node_modules/.pnpm/unique-string@3.0.0/node_modules/unique-string/index.js
176
- function uniqueString() {
177
- return crypto_random_string_default({ length: 32 });
178
- }
179
-
180
- // ../../node_modules/.pnpm/tempy@3.0.0/node_modules/tempy/index.js
181
- var import_temp_dir = __toESM(require_temp_dir(), 1);
182
- var import_temp_dir2 = __toESM(require_temp_dir(), 1);
183
- var pipeline = (0, import_node_util.promisify)(import_node_stream.default.pipeline);
184
- var getPath = (prefix = "") => import_node_path.default.join(import_temp_dir.default, prefix + uniqueString());
185
- function temporaryFile({ name, extension } = {}) {
186
- if (name) {
187
- if (extension !== void 0 && extension !== null) {
188
- throw new Error("The `name` and `extension` options are mutually exclusive");
189
- }
190
- return import_node_path.default.join(temporaryDirectory(), name);
191
- }
192
- return getPath() + (extension === void 0 || extension === null ? "" : "." + extension.replace(/^\./, ""));
193
- }
194
- function temporaryDirectory({ prefix = "" } = {}) {
195
- const directory = getPath(prefix);
196
- import_node_fs.default.mkdirSync(directory);
197
- return directory;
198
- }
199
-
200
- // index.js
201
- function getJSON(url) {
202
- return new Promise((resolve, reject) => {
203
- import_https.default.get(url, (res) => {
204
- let body = "";
205
- res.on("data", (chunk) => {
206
- body += chunk;
207
- });
208
- res.on("end", () => {
209
- try {
210
- resolve(JSON.parse(body));
211
- } catch (e) {
212
- reject(e);
213
- }
214
- });
215
- }).on("error", (e) => {
216
- reject(e);
217
- });
218
- });
219
- }
220
- var PackageVersionHelper = class {
221
- constructor(npmOrg, registryUrl = "https://registry.npmjs.org") {
222
- this.npmOrg = npmOrg;
223
- this.registryUrl = registryUrl;
224
- }
225
- async fetchPackageVersions(packageName) {
226
- let res;
227
- try {
228
- console.log(`fetching ${this.registryUrl}/@${this.npmOrg}/${packageName}`);
229
- res = await getJSON(`${this.registryUrl}/@${this.npmOrg}/${packageName}`);
230
- if (res.error) {
231
- return null;
232
- }
233
- return Object.keys(res.versions);
234
- } catch (e) {
235
- return null;
236
- }
237
- }
238
- async getLatestVersion(versions) {
239
- const sortedVersions = versions.sort((a, b) => import_semver.default.compare(a, b));
240
- return sortedVersions[sortedVersions.length - 1];
241
- }
242
- async getPackageVersion(packageName) {
243
- const versions = await this.fetchPackageVersions(packageName);
244
- if (!versions) {
245
- return null;
246
- }
247
- return this.getLatestVersion(versions);
248
- }
249
- getPackageName(extensionFolder) {
250
- const packageJson = JSON.parse(import_fs_extra.default.readFileSync(import_path.default.resolve(extensionFolder, "package.json"), "utf8"));
251
- let packageName = packageJson.name;
252
- if (packageName.startsWith("@")) {
253
- packageName = packageName.split("/")[1];
254
- }
255
- packageName = packageName.toLowerCase();
256
- console.debug(`package name is ${packageName}`);
257
- return packageName;
258
- }
259
- };
260
- async function publishExtensions(extensionFolder, npmOrganization, npmRegistry, distDir) {
261
- const versionHelper = new PackageVersionHelper(npmOrganization, npmRegistry);
262
- console.log(`
263
- Entering ${extensionFolder}
264
- `);
265
- (0, import_child_process.execSync)(`cd "${extensionFolder}"`);
266
- if (!distDir) {
267
- distDir = import_path.default.resolve(extensionFolder, "dist");
268
- }
269
- if (!import_fs_extra.default.existsSync(distDir)) {
270
- import_fs_extra.default.mkdirSync(distDir);
271
- }
272
- await buildExtension(extensionFolder, distDir);
273
- const packageName = versionHelper.getPackageName(extensionFolder);
274
- let version = await versionHelper.getPackageVersion(packageName);
275
- if (version) {
276
- console.info(`current version is ${version}`);
277
- version = import_semver.default.inc(version, "major");
278
- } else {
279
- console.info(`no version found, using 1.0.0`);
280
- version = "1.0.0";
281
- }
282
- updatePackageInfo(distDir, version, npmOrganization);
283
- console.info(`publishing version ${version}`);
284
- (0, import_child_process.execSync)(`npm publish --access public`, {
285
- cwd: distDir
286
- });
287
- }
288
- function getTSConfigPath(extensionDir) {
289
- const originalTSconfigPath = import_path.default.resolve(extensionDir, "tsconfig.json");
290
- const tsconfigJson = JSON.parse(import_fs_extra.default.readFileSync(originalTSconfigPath, "utf8"));
291
- tsconfigJson.compilerOptions.jsx = "react";
292
- tsconfigJson.compilerOptions.strict = false;
293
- const tempTSconfigPath = temporaryFile({ extension: "json" });
294
- import_fs_extra.default.writeFileSync(tempTSconfigPath, JSON.stringify(tsconfigJson, null, 2));
295
- return tempTSconfigPath;
296
- }
297
- async function buildExtension(extensionDir, outputFolder) {
298
- const packageJson = JSON.parse(import_fs_extra.default.readFileSync(import_path.default.resolve(extensionDir, "package.json"), "utf8"));
299
- if (!outputFolder) {
300
- outputFolder = import_path.default.resolve(extensionDir, "dist");
301
- }
302
- const commandNames = packageJson.commands.map((command) => command.name);
303
- const supportedExts = [".js", ".ts", ".tsx", ".jsx"];
304
- const tsconfigPath = getTSConfigPath(extensionDir);
305
- const esbuildConfigs = commandNames.map((commandName) => {
306
- const files = import_fs_extra.default.readdirSync(import_path.default.join(extensionDir, "src"));
307
- const entry = files.find((file) => {
308
- return supportedExts.some((ext) => file === `${commandName}${ext}`);
309
- });
310
- if (!entry) {
311
- throw new Error(`No entry point found for ${commandName}`);
312
- }
313
- const entryPath = import_path.default.join(extensionDir, "src", entry);
314
- const outputPath = import_path.default.join(outputFolder, `${commandName}.js`);
315
- console.debug(`entry point for ${commandName} is ${entryPath}`);
316
- return {
317
- input: entryPath,
318
- output: outputPath
319
- };
320
- });
321
- console.info(`entry points [${esbuildConfigs.map((config) => config.input).join(" ")}]`);
322
- for (const config of esbuildConfigs) {
323
- await import_esbuild.default.build({
324
- entryPoints: [config.input],
325
- bundle: true,
326
- platform: "node",
327
- outfile: config.output,
328
- external: ["@raycast/api", "react"],
329
- jsx: "transform",
330
- jsxFactory: "_jsx",
331
- jsxFragment: "_jsxFragment",
332
- tsconfig: tsconfigPath,
333
- minify: true
334
- });
335
- }
336
- import_fs_extra.default.copyFileSync(import_path.default.join(extensionDir, "package.json"), import_path.default.join(outputFolder, "package.json"));
337
- const assetsDir = import_path.default.join(extensionDir, "assets");
338
- if (import_fs_extra.default.existsSync(assetsDir)) {
339
- import_fs_extra.default.copySync(assetsDir, import_path.default.join(outputFolder, "assets"));
340
- }
341
- }
342
- function updatePackageInfo(targetDir, version, npmOrganization) {
343
- const packagePath = import_path.default.join(targetDir, "package.json");
344
- const packageJson = JSON.parse(import_fs_extra.default.readFileSync(packagePath, "utf8"));
345
- if (!packageJson.name.startsWith(`@${npmOrganization}`)) {
346
- packageJson.name = `@${npmOrganization}/${packageJson.name}`;
347
- }
348
- packageJson.repository = "https://github.com/BlastLauncher/extensions.git";
349
- packageJson.version = version;
350
- packageJson.scripts = Object.keys(packageJson.scripts).filter((key) => key !== "publish").reduce((obj, key) => {
351
- obj[key] = packageJson.scripts[key];
352
- return obj;
353
- }, {});
354
- import_fs_extra.default.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2), "utf8");
355
- }
356
- var program = new import_commander.Command();
357
- program.name("blast").description(`CLI for Blast Launcher
358
-
359
- Example Usage:
360
- blast build ./extensions/todo-list -o ./extensions/todo-list/dist
361
- blast publish ./extensions/todo-list blast-extensions`);
362
- program.command("publish").description("Publish extensions").argument("<path>", "Path to extensions folder").argument("<organization>", "NPM organization to publish to, e.g. blast-extensions").option("-r, --registry <registry>", "NPM registry to publish to", "https://registry.npmjs.org").option("-o, --output <output>", "Output directory, default to ./dist folder relative to extension path").action((dir, organization, options) => {
363
- return publishExtensions(dir, organization, options.registry, options.output);
364
- });
365
- program.command("build").description("Build extensions").argument("<path>", "Path to extension").option("-o, --output <output>", "Output directory, default to ./dist folder relative to extension path").action((path3, options) => {
366
- return buildExtension(path3, options.output);
367
- });
368
- program.parse();
package/index.js DELETED
@@ -1,265 +0,0 @@
1
- #!/usr/bin/env node
2
- import { execSync } from "child_process";
3
- import https from "https";
4
- import path from "path";
5
-
6
- import { Command } from "commander";
7
- import esbuild from "esbuild";
8
- import fs from "fs-extra";
9
- import semver from "semver";
10
- import { temporaryFile } from "tempy";
11
-
12
- function getJSON(url) {
13
- return new Promise((resolve, reject) => {
14
- https
15
- .get(url, (res) => {
16
- let body = "";
17
- res.on("data", (chunk) => {
18
- body += chunk;
19
- });
20
- res.on("end", () => {
21
- try {
22
- resolve(JSON.parse(body));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- });
27
- })
28
- .on("error", (e) => {
29
- reject(e);
30
- });
31
- });
32
- }
33
-
34
- class PackageVersionHelper {
35
- constructor(npmOrg, registryUrl = "https://registry.npmjs.org") {
36
- this.npmOrg = npmOrg;
37
- this.registryUrl = registryUrl;
38
- }
39
-
40
- async fetchPackageVersions(packageName) {
41
- let res;
42
- try {
43
- console.log(`fetching ${this.registryUrl}/@${this.npmOrg}/${packageName}`);
44
- res = await getJSON(`${this.registryUrl}/@${this.npmOrg}/${packageName}`);
45
-
46
- if (res.error) {
47
- return null;
48
- }
49
-
50
- return Object.keys(res.versions);
51
- } catch (e) {
52
- // pacakge not found
53
- return null;
54
- }
55
- }
56
-
57
- async getLatestVersion(versions) {
58
- const sortedVersions = versions.sort((a, b) => semver.compare(a, b));
59
- return sortedVersions[sortedVersions.length - 1];
60
- }
61
-
62
- async getPackageVersion(packageName) {
63
- const versions = await this.fetchPackageVersions(packageName);
64
- if (!versions) {
65
- return null;
66
- }
67
-
68
- return this.getLatestVersion(versions);
69
- }
70
-
71
- getPackageName(extensionFolder) {
72
- const packageJson = JSON.parse(fs.readFileSync(path.resolve(extensionFolder, "package.json"), "utf8"));
73
- let packageName = packageJson.name;
74
- if (packageName.startsWith("@")) {
75
- packageName = packageName.split("/")[1];
76
- }
77
- packageName = packageName.toLowerCase();
78
-
79
- console.debug(`package name is ${packageName}`);
80
-
81
- return packageName;
82
- }
83
- }
84
-
85
- /**
86
- * @param {string} extensionFolder
87
- * @param {string} npmOrganization
88
- * @param {string} npmRegistry
89
- * @param {string} distDir
90
- */
91
- async function publishExtensions(extensionFolder, npmOrganization, npmRegistry, distDir) {
92
- const versionHelper = new PackageVersionHelper(npmOrganization, npmRegistry);
93
-
94
- console.log(`\nEntering ${extensionFolder}\n`);
95
- execSync(`cd "${extensionFolder}"`);
96
-
97
- if (!distDir) {
98
- distDir = path.resolve(extensionFolder, "dist");
99
- }
100
-
101
- if (!fs.existsSync(distDir)) {
102
- fs.mkdirSync(distDir);
103
- }
104
-
105
- await buildExtension(extensionFolder, distDir);
106
-
107
- const packageName = versionHelper.getPackageName(extensionFolder);
108
- let version = await versionHelper.getPackageVersion(packageName);
109
- if (version) {
110
- console.info(`current version is ${version}`);
111
- version = semver.inc(version, "major");
112
- } else {
113
- console.info(`no version found, using 1.0.0`);
114
- version = "1.0.0";
115
- }
116
-
117
- updatePackageInfo(distDir, version, npmOrganization);
118
-
119
- console.info(`publishing version ${version}`);
120
-
121
- // publish to npm
122
- execSync(`npm publish --access public`, {
123
- cwd: distDir,
124
- });
125
- }
126
-
127
- function getTSConfigPath(extensionDir) {
128
- const originalTSconfigPath = path.resolve(extensionDir, "tsconfig.json");
129
- const tsconfigJson = JSON.parse(fs.readFileSync(originalTSconfigPath, "utf8"));
130
-
131
- tsconfigJson.compilerOptions.jsx = "react";
132
- tsconfigJson.compilerOptions.strict = false;
133
-
134
- const tempTSconfigPath = temporaryFile({ extension: "json" });
135
-
136
- fs.writeFileSync(tempTSconfigPath, JSON.stringify(tsconfigJson, null, 2));
137
-
138
- return tempTSconfigPath;
139
- }
140
-
141
- async function buildExtension(extensionDir, outputFolder) {
142
- // Gather entry points from target extension's packages.json
143
- const packageJson = JSON.parse(fs.readFileSync(path.resolve(extensionDir, "package.json"), "utf8"));
144
- if (!outputFolder) {
145
- outputFolder = path.resolve(extensionDir, "dist");
146
- }
147
-
148
- const commandNames = packageJson.commands.map((command) => command.name);
149
-
150
- const supportedExts = [".js", ".ts", ".tsx", ".jsx"];
151
-
152
- const tsconfigPath = getTSConfigPath(extensionDir);
153
-
154
- const esbuildConfigs = commandNames.map((commandName) => {
155
- const files = fs.readdirSync(path.join(extensionDir, "src"));
156
- const entry = files.find((file) => {
157
- return supportedExts.some((ext) => file === `${commandName}${ext}`);
158
- });
159
-
160
- if (!entry) {
161
- throw new Error(`No entry point found for ${commandName}`);
162
- }
163
-
164
- const entryPath = path.join(extensionDir, "src", entry);
165
- const outputPath = path.join(outputFolder, `${commandName}.js`);
166
-
167
- console.debug(`entry point for ${commandName} is ${entryPath}`);
168
-
169
- return {
170
- input: entryPath,
171
- output: outputPath,
172
- };
173
- });
174
-
175
- console.info(`entry points [${esbuildConfigs.map((config) => config.input).join(" ")}]`);
176
-
177
- // Build each entry point
178
- for (const config of esbuildConfigs) {
179
- await esbuild.build({
180
- entryPoints: [config.input],
181
- bundle: true,
182
- platform: "node",
183
- outfile: config.output,
184
- external: ["@raycast/api", "react"],
185
- jsx: "transform",
186
- jsxFactory: "_jsx",
187
- jsxFragment: "_jsxFragment",
188
- tsconfig: tsconfigPath,
189
- minify: true,
190
- });
191
- }
192
-
193
- // copy the package.json to the output folder
194
- fs.copyFileSync(path.join(extensionDir, "package.json"), path.join(outputFolder, "package.json"));
195
-
196
- // copy assets directory to the output folder
197
- const assetsDir = path.join(extensionDir, "assets");
198
- if (fs.existsSync(assetsDir)) {
199
- fs.copySync(assetsDir, path.join(outputFolder, "assets"));
200
- }
201
- }
202
-
203
- /**
204
- * @param {string} targetDir
205
- * @param {string} version
206
- * @param {string} npmOrganization
207
- * @returns {void}
208
- * add extra information to package.json
209
- **/
210
- function updatePackageInfo(targetDir, version, npmOrganization) {
211
- const packagePath = path.join(targetDir, "package.json");
212
- const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
213
-
214
- // prepend @BlastLauncher to name if it's not already there
215
- if (!packageJson.name.startsWith(`@${npmOrganization}`)) {
216
- packageJson.name = `@${npmOrganization}/${packageJson.name}`;
217
- }
218
-
219
- // add repository field
220
- packageJson.repository = "https://github.com/BlastLauncher/extensions.git";
221
-
222
- // add version
223
- packageJson.version = version;
224
-
225
- // exclude original publish script
226
- packageJson.scripts = Object.keys(packageJson.scripts)
227
- .filter((key) => key !== "publish")
228
- .reduce((obj, key) => {
229
- obj[key] = packageJson.scripts[key];
230
- return obj;
231
- }, {});
232
-
233
- // write package.json
234
- fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2), "utf8");
235
- }
236
-
237
- const program = new Command();
238
-
239
- program.name("blast").description(`CLI for Blast Launcher
240
-
241
- Example Usage:
242
- blast build ./extensions/todo-list -o ./extensions/todo-list/dist
243
- blast publish ./extensions/todo-list blast-extensions`);
244
-
245
- program
246
- .command("publish")
247
- .description("Publish extensions")
248
- .argument("<path>", "Path to extensions folder")
249
- .argument("<organization>", "NPM organization to publish to, e.g. blast-extensions")
250
- .option("-r, --registry <registry>", "NPM registry to publish to", "https://registry.npmjs.org")
251
- .option("-o, --output <output>", "Output directory, default to ./dist folder relative to extension path")
252
- .action((dir, organization, options) => {
253
- return publishExtensions(dir, organization, options.registry, options.output);
254
- });
255
-
256
- program
257
- .command("build")
258
- .description("Build extensions")
259
- .argument("<path>", "Path to extension")
260
- .option("-o, --output <output>", "Output directory, default to ./dist folder relative to extension path")
261
- .action((path, options) => {
262
- return buildExtension(path, options.output);
263
- });
264
-
265
- program.parse();