extension-create 2.0.0-rc.24 → 2.0.0-rc.25

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/module.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export interface CreateOptions {
1
+ interface CreateOptions {
2
2
  template: string;
3
3
  install?: boolean;
4
4
  cliVersion?: string;
5
5
  }
6
- export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
6
+ declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
7
+
8
+ export { type CreateOptions, extensionCreate };
package/dist/module.js CHANGED
@@ -1,551 +1,39 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
2
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
3
- import * as __WEBPACK_EXTERNAL_MODULE_chalk__ from "chalk";
4
- import * as __WEBPACK_EXTERNAL_MODULE_package_manager_detector_0998337c__ from "package-manager-detector";
5
- import * as __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__ from "fs/promises";
6
- import * as __WEBPACK_EXTERNAL_MODULE_url__ from "url";
7
- import * as __WEBPACK_EXTERNAL_MODULE_go_git_it_78aeb103__ from "go-git-it";
8
- import * as __WEBPACK_EXTERNAL_MODULE_cross_spawn_96b24ecb__ from "cross-spawn";
9
- function destinationNotWriteable(workingDir) {
10
- const workingDirFolder = __WEBPACK_EXTERNAL_MODULE_path__.basename(workingDir);
11
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write in the destination directory\n\nPath is not writable. Ensure you have write permissions for this folder.\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red('NOT WRITEABLE')}: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(workingDirFolder)}`;
12
- }
13
- async function directoryHasConflicts(projectPath, conflictingFiles) {
14
- const projectName = __WEBPACK_EXTERNAL_MODULE_path__.basename(projectPath);
15
- let message = `\nConflict! Path to ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)} includes conflicting files:\n\n`;
16
- for (const file of conflictingFiles){
17
- const stats = await __WEBPACK_EXTERNAL_MODULE_fs__.promises.lstat(__WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, file));
18
- message += stats.isDirectory() ? `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].gray('-')} ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow(file)}\n` : `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].gray('-')} ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow(file)}\n`;
19
- }
20
- message += `\nYou need to either rename/remove the files listed above, or choose a new directory name for your extension.\n\nPath to conflicting directory: ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(projectPath)}`;
21
- return message;
22
- }
23
- function noProjectName() {
24
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} You need to provide an extension name to create one. See ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('--help')} for command info.`;
25
- }
26
- function noUrlAllowed() {
27
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} URLs are not allowed as a project path. Either write a name or a path to a local folder.`;
28
- }
29
- async function successfullInstall(projectPath, projectName) {
30
- const relativePath = __WEBPACK_EXTERNAL_MODULE_path__.relative(process.cwd(), projectPath);
31
- const pm = await (0, __WEBPACK_EXTERNAL_MODULE_package_manager_detector_0998337c__.detect)();
32
- let command = 'npm run';
33
- switch(null == pm ? void 0 : pm.name){
34
- case 'yarn':
35
- command = 'yarn dev';
36
- break;
37
- case 'pnpm':
38
- command = 'pnpm dev';
39
- break;
40
- default:
41
- command = 'npm run dev';
42
- }
43
- if (process.env.npm_config_user_agent) {
44
- if (process.env.npm_config_user_agent.includes('pnpm')) command = 'pnpm dev';
45
- }
46
- return `\u{1F9E9} - ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green('Success!')} Extension ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)} created.\n\nNow ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(`cd ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].underline(relativePath)}`)} and ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(`${command}`)} to open a new browser instance\nwith your extension installed, loaded, and enabled for development.\n\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].green('You are ready')}. Time to hack on your extension!`;
47
- }
48
- function startingNewExtension(projectName) {
49
- return `\u{1F423} - Starting a new browser extension named ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}...`;
50
- }
51
- function checkingIfPathIsWriteable() {
52
- return `\u{1F91E} - Checking if destination path is writeable...`;
53
- }
54
- function scanningPossiblyConflictingFiles() {
55
- return "\uD83D\uDD0E - Scanning for potential conflicting files...";
56
- }
57
- function createDirectoryError(projectName, error) {
58
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't create directory ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
59
- }
60
- function writingTypeDefinitions(projectName) {
61
- return `\u{1F537} - Writing type definitions for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}...`;
62
- }
63
- function writingTypeDefinitionsError(error) {
64
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write the extension type definition.\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
65
- }
66
- function installingFromTemplate(projectName, templateName) {
67
- if ('init' === templateName) return `\u{1F9F0} - Installing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}...`;
68
- return `\u{1F9F0} - Installing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)} from template ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(templateName)}...`;
69
- }
70
- function installingFromTemplateError(projectName, template, error) {
71
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't find template ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].magenta(template)} for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
72
- }
73
- function initializingGitForRepository(projectName) {
74
- return `\u{1F332} - Initializing git repository for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}...`;
75
- }
76
- function initializingGitForRepositoryFailed(gitCommand, gitArgs, code) {
77
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow(gitCommand)} ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow(gitArgs.join(' '))} failed with exit code ${code}`;
78
- }
79
- function initializingGitForRepositoryProcessError(projectName, error) {
80
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't initialize ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('git')} for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error.message)}`;
81
- }
82
- function initializingGitForRepositoryError(projectName, error) {
83
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't initialize ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('git')} for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error.message || error.toString())}`;
84
- }
85
- function installingDependencies() {
86
- return "\uD83D\uDEE0 - Installing dependencies... (takes a moment)";
87
- }
88
- function installingDependenciesFailed(gitCommand, gitArgs, code) {
89
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${gitCommand} ${gitArgs.join(' ')} failed with exit code ${code}`;
90
- }
91
- function installingDependenciesProcessError(projectName, error) {
92
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't install dependencies for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
93
- }
94
- function cantInstallDependencies(projectName, error) {
95
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't install dependencies for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error.message || error.toString())}`;
96
- }
97
- function writingPackageJsonMetadata() {
98
- return `\u{1F4DD} - Writing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('package.json')} metadata...`;
99
- }
100
- function writingPackageJsonMetadataError(projectName, error) {
101
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('package.json')} for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
102
- }
103
- function writingManifestJsonMetadata() {
104
- return `\u{1F4DC} - Writing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('manifest.json')} metadata...`;
105
- }
106
- function writingManifestJsonMetadataError(projectName, error) {
107
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('manifest.json')} for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
108
- }
109
- function writingReadmeMetaData() {
110
- return `\u{1F4C4} - Writing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('README.md')} metadata...`;
111
- }
112
- function writingGitIgnore() {
113
- return `\u{1F648} - Writing ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('.gitignore')} lines...`;
114
- }
115
- function writingReadmeMetaDataEError(projectName, error) {
116
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write the ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].yellow('README.md')} file for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
117
- }
118
- function folderExists(projectName) {
119
- return `\u{1F91D} - Ensuring ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)} folder exists...`;
120
- }
121
- function writingDirectoryError(error) {
122
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Error while checking directory writability:\n` + __WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error);
123
- }
124
- function cantSetupBuiltInTests(projectName, error) {
125
- return `${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't setup built-in tests for ${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].cyan(projectName)}:\n${__WEBPACK_EXTERNAL_MODULE_chalk__["default"].red(error)}`;
126
- }
127
- const utils_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
128
- const utils_dirname = __WEBPACK_EXTERNAL_MODULE_path__.dirname(utils_filename);
129
- async function copyDirectoryWithSymlinks(source, destination) {
130
- const entries = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readdir(source, {
131
- withFileTypes: true
132
- });
133
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(destination, {
134
- recursive: true
135
- });
136
- for (const entry of entries){
137
- const sourcePath = __WEBPACK_EXTERNAL_MODULE_path__.join(source, entry.name);
138
- const destPath = __WEBPACK_EXTERNAL_MODULE_path__.join(destination, entry.name);
139
- if (entry.isDirectory()) await copyDirectoryWithSymlinks(sourcePath, destPath);
140
- else if (entry.isSymbolicLink()) {
141
- const target = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readlink(sourcePath);
142
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.symlink(target, destPath);
143
- } else await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.copyFile(sourcePath, destPath);
144
- }
145
- }
146
- async function moveDirectoryContents(source, destination) {
147
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(destination, {
148
- recursive: true
149
- });
150
- const entries = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readdir(source, {
151
- withFileTypes: true
152
- });
153
- for (const entry of entries){
154
- const sourcePath = __WEBPACK_EXTERNAL_MODULE_path__.join(source, entry.name);
155
- const destPath = __WEBPACK_EXTERNAL_MODULE_path__.join(destination, entry.name);
156
- if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
157
- else if (entry.isSymbolicLink()) {
158
- const target = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readlink(sourcePath);
159
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.symlink(target, destPath);
160
- } else await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.rename(sourcePath, destPath);
161
- }
162
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.rm(source, {
163
- recursive: true,
164
- force: true
165
- });
166
- }
167
- async function getInstallCommand() {
168
- const pm = await (0, __WEBPACK_EXTERNAL_MODULE_package_manager_detector_0998337c__.detect)();
169
- let command = 'npm';
170
- if (process.env.npm_config_user_agent) {
171
- if (process.env.npm_config_user_agent.includes('pnpm')) return 'pnpm';
172
- }
173
- switch(null == pm ? void 0 : pm.name){
174
- case 'yarn':
175
- command = 'yarn';
176
- break;
177
- case 'pnpm':
178
- command = 'pnpm';
179
- break;
180
- default:
181
- command = 'npm';
182
- }
183
- return command;
184
- }
185
- function getTemplatePath(workingDir) {
186
- const templatesDir = __WEBPACK_EXTERNAL_MODULE_path__.resolve(utils_dirname, '..', 'template');
187
- return __WEBPACK_EXTERNAL_MODULE_path__.resolve(workingDir, templatesDir);
188
- }
189
- async function isDirectoryWriteable(directory, projectName) {
190
- try {
191
- console.log(folderExists(projectName));
192
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(directory, {
193
- recursive: true
194
- });
195
- return true;
196
- } catch (err) {
197
- console.log(writingDirectoryError(err));
198
- return false;
199
- }
200
- }
201
- function isExternalTemplate(templateName) {
202
- return 'init' !== templateName;
203
- }
204
- function isTypeScriptTemplate(templateName) {
205
- return templateName.includes("typescript") || templateName.includes('react') || templateName.includes('preact') || templateName.includes('svelte') || templateName.includes('solid');
206
- }
207
- const allowlist = [
208
- 'LICENSE',
209
- 'node_modules'
210
- ];
211
- async function createDirectory(projectPath, projectName) {
212
- console.log(startingNewExtension(projectName));
213
- try {
214
- const isCurrentDirWriteable = await isDirectoryWriteable(projectPath, projectName);
215
- console.log(checkingIfPathIsWriteable());
216
- if (!isCurrentDirWriteable) {
217
- console.error(destinationNotWriteable(projectPath));
218
- process.exit(1);
219
- }
220
- const currentDir = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readdir(projectPath);
221
- console.log(scanningPossiblyConflictingFiles());
222
- const conflictingFiles = await Promise.all(currentDir.filter((file)=>!file.startsWith('.')).filter((file)=>!file.endsWith('.log')).filter((file)=>!allowlist.includes(file)).map(async (file)=>{
223
- const stats = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.lstat(__WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, file));
224
- return stats.isDirectory() ? `${file}/` : `${file}`;
225
- }));
226
- if (conflictingFiles.length > 0) {
227
- const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
228
- throw new Error(conflictMessage);
229
- }
230
- } catch (error) {
231
- console.error(createDirectoryError(projectName, error));
232
- process.exit(1);
233
- }
234
- }
235
- const import_local_template_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
236
- const import_local_template_dirname = __WEBPACK_EXTERNAL_MODULE_path__.dirname(import_local_template_filename);
237
- async function importLocalTemplate(projectPath, projectName, template) {
238
- const localTemplatePath = __WEBPACK_EXTERNAL_MODULE_path__.resolve(import_local_template_dirname, 'template');
239
- try {
240
- console.log(installingFromTemplate(projectName, template));
241
- await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
242
- } catch (error) {
243
- console.error(installingFromTemplateError(projectName, template, error));
244
- process.exit(1);
245
- }
246
- }
247
- const import_external_template_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
248
- const import_external_template_dirname = __WEBPACK_EXTERNAL_MODULE_path__.dirname(import_external_template_filename);
249
- async function importExternalTemplate(projectPath, projectName, template) {
250
- const installationPath = __WEBPACK_EXTERNAL_MODULE_path__.dirname(projectPath);
251
- const templateName = __WEBPACK_EXTERNAL_MODULE_path__.basename(template);
252
- const examplesUrl = 'https://github.com/extension-js/extension.js/tree/main/examples';
253
- const templateUrl = `${examplesUrl}/${template}`;
254
- try {
255
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(projectPath, {
256
- recursive: true
257
- });
258
- if ('development' === process.env.EXTENSION_ENV) {
259
- console.log(installingFromTemplate(projectName, template));
260
- const localTemplatePath = __WEBPACK_EXTERNAL_MODULE_path__.join(import_external_template_dirname, '..', '..', '..', 'examples', templateName);
261
- await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
262
- } else {
263
- const tempPath = __WEBPACK_EXTERNAL_MODULE_path__.join(installationPath, projectName + '-temp');
264
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(tempPath, {
265
- recursive: true
266
- });
267
- await (0, __WEBPACK_EXTERNAL_MODULE_go_git_it_78aeb103__["default"])(templateUrl, tempPath, installingFromTemplate(projectName, templateName));
268
- const srcPath = __WEBPACK_EXTERNAL_MODULE_path__.join(tempPath, templateName);
269
- await moveDirectoryContents(srcPath, projectPath);
270
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.rm(tempPath, {
271
- recursive: true,
272
- force: true
273
- });
274
- }
275
- } catch (error) {
276
- console.error(installingFromTemplateError(projectName, templateName, error));
277
- process.exit(1);
278
- }
279
- }
280
- const extensionJsPackageJsonScripts = {
281
- dev: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension dev' : 'extension dev',
282
- start: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension start' : 'extension start',
283
- build: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build' : 'extension build'
284
- };
285
- async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
286
- const templatePath = getTemplatePath(process.cwd());
287
- const packageJsonPath = isExternalTemplate(template) ? __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'package.json') : __WEBPACK_EXTERNAL_MODULE_path__.join(templatePath, 'package.json');
288
- const packageJsonContent = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readFile(packageJsonPath);
289
- const packageJson = JSON.parse(packageJsonContent.toString());
290
- packageJson.scripts = packageJson.scripts || {};
291
- packageJson.dependencies = packageJson.dependencies || {};
292
- packageJson.devDependencies = {
293
- ...packageJson.devDependencies || {},
294
- extension: 'development' === process.env.EXTENSION_ENV ? '*' : `^${cliVersion}`
295
- };
296
- const packageMetadata = {
297
- ...packageJson,
298
- name: __WEBPACK_EXTERNAL_MODULE_path__.basename(projectPath),
299
- private: true,
300
- scripts: {
301
- ...packageJson.scripts,
302
- ...extensionJsPackageJsonScripts
303
- },
304
- dependencies: packageJson.dependencies,
305
- devDependencies: packageJson.devDependencies,
306
- author: {
307
- name: 'Your Name',
308
- email: 'your@email.com',
309
- url: 'https://yourwebsite.com'
310
- }
311
- };
312
- try {
313
- console.log(writingPackageJsonMetadata());
314
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.writeFile(__WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'package.json'), JSON.stringify(packageMetadata, null, 2));
315
- } catch (error) {
316
- console.error(writingPackageJsonMetadataError(projectName, error));
317
- process.exit(1);
318
- }
319
- }
320
- function getInstallArgs() {
321
- return [
322
- 'install',
323
- '--silent'
324
- ];
325
- }
326
- async function installDependencies(projectPath, projectName) {
327
- const nodeModulesPath = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'node_modules');
328
- const command = await getInstallCommand();
329
- const dependenciesArgs = getInstallArgs();
330
- console.log(installingDependencies());
331
- try {
332
- await __WEBPACK_EXTERNAL_MODULE_fs__.promises.mkdir(nodeModulesPath, {
333
- recursive: true
334
- });
335
- const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
336
- const child = (0, __WEBPACK_EXTERNAL_MODULE_cross_spawn_96b24ecb__.spawn)(command, dependenciesArgs, {
337
- stdio,
338
- cwd: projectPath
339
- });
340
- await new Promise((resolve, reject)=>{
341
- child.on('close', (code)=>{
342
- if (0 !== code) reject(new Error(installingDependenciesFailed(command, dependenciesArgs, code)));
343
- else resolve();
344
- });
345
- child.on('error', (error)=>{
346
- console.error(installingDependenciesProcessError(projectName, error));
347
- reject(error);
348
- });
349
- });
350
- } catch (error) {
351
- console.error(cantInstallDependencies(projectName, error));
352
- process.exit(1);
353
- }
354
- }
355
- const write_readme_file_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
356
- const write_readme_file_dirname = __WEBPACK_EXTERNAL_MODULE_path__.dirname(write_readme_file_filename);
357
- async function writeReadmeFile(projectPath, projectName) {
358
- const initTemplateReadme = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readFile(__WEBPACK_EXTERNAL_MODULE_path__.join(write_readme_file_dirname, 'template', 'README.md'), 'utf-8');
359
- const installCommand = await getInstallCommand();
360
- const manifestJsonPath = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'manifest.json');
361
- const manifestJson = JSON.parse(await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readFile(manifestJsonPath, 'utf-8'));
362
- const readmeFileEdited = initTemplateReadme.replaceAll('[projectName]', projectName).replaceAll("[templateDescription]", manifestJson.description).replaceAll('[runCommand]', installCommand);
363
- try {
364
- console.log(writingReadmeMetaData());
365
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(projectPath, {
366
- recursive: true
367
- });
368
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.writeFile(__WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'README.md'), readmeFileEdited);
369
- } catch (error) {
370
- console.error(writingReadmeMetaDataEError(projectName, error));
371
- process.exit(1);
372
- }
373
- }
374
- async function writeManifestJson(projectPath, projectName) {
375
- const manifestJsonPath = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'manifest.json');
376
- const manifestJsonContent = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readFile(manifestJsonPath);
377
- const manifestJson = JSON.parse(manifestJsonContent.toString());
378
- const manifestMetadata = {
379
- ...manifestJson,
380
- name: __WEBPACK_EXTERNAL_MODULE_path__.basename(projectPath),
381
- author: 'Your Name'
382
- };
383
- try {
384
- console.log(writingManifestJsonMetadata());
385
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.writeFile(__WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'manifest.json'), JSON.stringify(manifestMetadata, null, 2));
386
- } catch (error) {
387
- console.error(writingManifestJsonMetadataError(projectName, error));
388
- process.exit(1);
389
- }
390
- }
391
- async function generateExtensionTypes(projectPath, projectName) {
392
- const extensionEnvFile = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'extension-env.d.ts');
393
- const typePath = 'development' === process.env.EXTENSION_ENV ? __WEBPACK_EXTERNAL_MODULE_path__.resolve(process.cwd(), 'programs/cli/types') : 'extension/dist/types';
394
- const fileContent = `\
395
- // Required Extension.js types for TypeScript projects.
1
+ "use strict";var ze=Object.create;var b=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var Ye=(e,t)=>{for(var r in t)b(e,r,{get:t[r],enumerable:!0})},O=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Xe(t))!Ue.call(e,i)&&i!==r&&b(e,i,{get:()=>t[i],enumerable:!(o=Ve(t,i))||o.enumerable});return e};var c=(e,t,r)=>(r=e!=null?ze(Le(e)):{},O(t||!e||!e.__esModule?b(r,"default",{value:e,enumerable:!0}):r,e)),Be=e=>O(b({},"__esModule",{value:!0}),e);var at={};Ye(at,{extensionCreate:()=>ot});module.exports=Be(at);var C=c(require("path"));var y=c(require("path")),n=require("@colors/colors/safe"),j=c(require("fs/promises")),A=require("package-manager-detector");function G(e){let t=y.default.basename(e);return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write in the destination directory
2
+
3
+ Path is not writable. Ensure you have write permissions for this folder.
4
+ ${(0,n.red)("NOT WRITEABLE")}: ${(0,n.underline)(t)}`}async function W(e,t){let r=y.default.basename(e),o=`
5
+ Conflict! Path to ${(0,n.cyan)(r)} includes conflicting files:
6
+
7
+ `;for(let i of t){let s=await j.default.lstat(y.default.join(e,i));o+=s.isDirectory()?`${(0,n.gray)("-")} ${(0,n.brightYellow)(i)}
8
+ `:`${(0,n.gray)("-")} ${(0,n.brightYellow)(i)}
9
+ `}return o+=`
10
+ You need to either rename/remove the files listed above, or choose a new directory name for your extension.
11
+
12
+ Path to conflicting directory: ${(0,n.underline)(e)}`,o}function z(){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} You need to provide an extension name to create one. See ${(0,n.brightYellow)("--help")} for command info.`}function V(){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} URLs are not allowed as a project path. Either write a name or a path to a local folder.`}async function X(e,t){let r=y.default.relative(process.cwd(),e),o=await(0,A.detect)(),i="npm run";switch(o?.name){case"yarn":i="yarn dev";break;case"pnpm":i="pnpm dev";break;default:i="npm run dev"}return process.env.npm_config_user_agent&&process.env.npm_config_user_agent.includes("pnpm")&&(i="pnpm dev"),`\u{1F9E9} - ${(0,n.brightGreen)("Success!")} Extension ${(0,n.cyan)(t)} created.
13
+
14
+ Now ${(0,n.magenta)(`cd ${(0,n.underline)(r)}`)} and ${(0,n.magenta)(`${i}`)} to open a new browser instance
15
+ with your extension installed, loaded, and enabled for development.
16
+
17
+ ${(0,n.brightGreen)("You are ready")}. Time to hack on your extension!`}function L(e){return`\u{1F423} - Starting a new browser extension named ${(0,n.cyan)(e)}...`}function U(){return"\u{1F91E} - Checking if destination path is writeable..."}function Y(){return"\u{1F50E} - Scanning for potential conflicting files..."}function B(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't create directory ${(0,n.cyan)(e)}:
18
+ ${(0,n.red)(t)}`}function q(e){return`\u{1F537} - Writing type definitions for ${(0,n.cyan)(e)}...`}function H(e){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write the extension type definition.
19
+ ${(0,n.red)(e)}`}function x(e,t){return t==="init"?`\u{1F9F0} - Installing ${(0,n.cyan)(e)}...`:`\u{1F9F0} - Installing ${(0,n.cyan)(e)} from template ${(0,n.magenta)(t)}...`}function D(e,t,r){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't find template ${(0,n.magenta)(t)} for ${(0,n.cyan)(e)}:
20
+ ${(0,n.red)(r)}`}function K(e){return`\u{1F332} - Initializing git repository for ${(0,n.cyan)(e)}...`}function Q(e,t,r){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${(0,n.brightYellow)(e)} ${(0,n.brightYellow)(t.join(" "))} failed with exit code ${r}`}function Z(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't initialize ${(0,n.brightYellow)("git")} for ${(0,n.cyan)(e)}:
21
+ ${(0,n.red)(t.message)}`}function ee(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't initialize ${(0,n.brightYellow)("git")} for ${(0,n.cyan)(e)}:
22
+ ${(0,n.red)(t.message||t.toString())}`}function te(){return"\u{1F6E0} - Installing dependencies... (takes a moment)"}function ne(e,t,r){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Command ${e} ${t.join(" ")} failed with exit code ${r}`}function ie(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't install dependencies for ${(0,n.cyan)(e)}:
23
+ ${(0,n.red)(t)}`}function re(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't install dependencies for ${(0,n.cyan)(e)}:
24
+ ${(0,n.red)(t.message||t.toString())}`}function se(){return`\u{1F4DD} - Writing ${(0,n.brightYellow)("package.json")} metadata...`}function oe(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,n.brightYellow)("package.json")} for ${(0,n.cyan)(e)}:
25
+ ${(0,n.red)(t)}`}function ae(){return`\u{1F4DC} - Writing ${(0,n.brightYellow)("manifest.json")} metadata...`}function ce(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,n.brightYellow)("manifest.json")} for ${(0,n.cyan)(e)}:
26
+ ${(0,n.red)(t)}`}function le(){return`\u{1F4C4} - Writing ${(0,n.brightYellow)("README.md")} metadata...`}function me(){return`\u{1F648} - Writing ${(0,n.brightYellow)(".gitignore")} lines...`}function pe(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write the ${(0,n.brightYellow)("README.md")} file for ${(0,n.cyan)(e)}:
27
+ ${(0,n.red)(t)}`}function ge(e){return`\u{1F91D} - Ensuring ${(0,n.cyan)(e)} folder exists...`}function fe(e){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Error while checking directory writability:
28
+ `+(0,n.red)(e)}function de(e,t){return`${(0,n.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't setup built-in tests for ${(0,n.cyan)(e)}:
29
+ ${(0,n.red)(t)}`}var h=c(require("fs/promises")),$=c(require("path")),ue=require("package-manager-detector");async function E(e,t){let r=await h.default.readdir(e,{withFileTypes:!0});return await h.default.mkdir(t,{recursive:!0}),await Promise.all(r.map(async o=>{let i=$.default.join(e,o.name),s=$.default.join(t,o.name);o.isDirectory()?await E(i,s):await h.default.copyFile(i,s)}))}async function T(){let e=await(0,ue.detect)(),t="npm";if(process.env.npm_config_user_agent&&process.env.npm_config_user_agent.includes("pnpm"))return"pnpm";switch(e?.name){case"yarn":t="yarn";break;case"pnpm":t="pnpm";break;default:t="npm"}return t}function we(e){let t=$.default.resolve(__dirname,"template");return $.default.resolve(e,t)}async function ye(e,t){try{return console.log(ge(t)),await h.default.mkdir(e,{recursive:!0}),!0}catch(r){return console.log(fe(r)),!1}}function xe(e){return e!=="init"}function he(e){return e.includes("typescript")||e.includes("react")||e.includes("preact")||e.includes("svelte")||e.includes("solid")}var $e=c(require("path")),P=c(require("fs/promises"));var qe=["LICENSE","node_modules"];async function Ee(e,t){console.log(L(t));try{let r=await ye(e,t);console.log(U()),r||(console.error(G(e)),process.exit(1));let o=await P.default.readdir(e);console.log(Y());let i=await Promise.all(o.filter(s=>!s.startsWith(".")).filter(s=>!s.endsWith(".log")).filter(s=>!qe.includes(s)).map(async s=>(await P.default.lstat($e.default.join(e,s))).isDirectory()?`${s}/`:`${s}`));if(i.length>0){let s=await W(e,i);throw new Error(s)}}catch(r){console.error(B(t,r)),process.exit(1)}}var ve=c(require("path"));async function be(e,t,r){let o=ve.default.resolve(__dirname,"template");try{console.log(x(t,r)),await E(o,e)}catch(i){console.error(D(t,r,i)),process.exit(1)}}var g=c(require("path")),u=c(require("fs/promises")),De=c(require("go-git-it"));async function Te(e,t,r){let o=g.default.dirname(e),i=g.default.basename(r),l=`https://github.com/extension-js/extension.js/tree/main/examples/${r}`;try{await u.default.mkdir(e,{recursive:!0});let a="";if(process.env.EXTENSION_ENV==="development"){console.log(x(t,r)),a=g.default.join(e,i);let m=g.default.join(__dirname,"..","..","..","examples",i);await E(m,a)}else await(0,De.default)(l,o,x(t,i)),a=g.default.join(o,i);if(t!==i){let m=g.default.join(o,t);await u.default.mkdir(m,{recursive:!0});let p=await u.default.readdir(a);for(let d of p)await u.default.rename(g.default.join(a,d),g.default.join(m,d));await u.default.rm(a,{recursive:!0,force:!0})}else{let m=g.default.join(o,t+"-temp");await u.default.rename(a,m);let p=g.default.join(m,i),d=g.default.join(o,t);await u.default.mkdir(d,{recursive:!0});let We=await u.default.readdir(p);for(let N of We)await u.default.rename(g.default.join(p,N),g.default.join(d,N));await u.default.rm(m,{recursive:!0,force:!0})}}catch(a){console.error(D(t,i,a)),process.exit(1)}}var v=c(require("path")),_=c(require("fs/promises"));var He={dev:process.env.EXTENSION_ENV==="development"?"node node_modules/extension dev":"extension dev",start:process.env.EXTENSION_ENV==="development"?"node node_modules/extension start":"extension start",build:process.env.EXTENSION_ENV==="development"?"node node_modules/extension build":"extension build"};async function Fe(e,t,{template:r,cliVersion:o}){let i=we(process.cwd()),s=xe(r)?v.default.join(e,"package.json"):v.default.join(i,"package.json"),l=await _.default.readFile(s),a=JSON.parse(l.toString());a.scripts=a.scripts||{},a.dependencies=a.dependencies||{},a.devDependencies={...a.devDependencies||{},extension:process.env.EXTENSION_ENV==="development"?"*":`^${o}`};let m={...a,name:v.default.basename(e),private:!0,scripts:{...a.scripts,...He},dependencies:a.dependencies,devDependencies:a.devDependencies,author:{name:"Your Name",email:"your@email.com",url:"https://yourwebsite.com"}};try{console.log(se()),await _.default.writeFile(v.default.join(e,"package.json"),JSON.stringify(m,null,2))}catch(p){console.error(oe(t,p)),process.exit(1)}}var ke=c(require("path")),Se=require("cross-spawn"),Ce=c(require("fs"));function Ke(){return["install","--silent"]}async function Pe(e,t){let r=ke.default.join(e,"node_modules"),o=await T(),i=Ke();console.log(te());try{let s=process.cwd();process.chdir(e),await Ce.default.promises.mkdir(r,{recursive:!0});let l=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",a=(0,Se.spawn)(o,i,{stdio:l});await new Promise((m,p)=>{a.on("close",d=>{process.chdir(s),d!==0?p(new Error(ne(o,i,d))):m()}),a.on("error",d=>{process.chdir(s),console.error(ie(t,d)),p(d)})})}catch(s){console.error(re(t,s)),process.exit(1)}}var F=c(require("path")),k=c(require("fs/promises"));async function _e(e,t){let r=await k.default.readFile(F.default.join(__dirname,"template","README.md"),"utf-8"),o=await T(),i=require(F.default.join(e,"manifest.json")),s=r.replaceAll("[projectName]",t).replaceAll("[templateDescription]",i.description).replaceAll("[runCommand]",o);try{console.log(le()),await k.default.mkdir(e,{recursive:!0}),await k.default.writeFile(F.default.join(e,"README.md"),s)}catch(l){console.error(pe(t,l)),process.exit(1)}}var S=c(require("path")),I=c(require("fs/promises"));async function Ie(e,t){let r=S.default.join(e,"manifest.json"),o=await I.default.readFile(r),s={...JSON.parse(o.toString()),name:S.default.basename(e),author:"Your Name"};try{console.log(ae()),await I.default.writeFile(S.default.join(e,"manifest.json"),JSON.stringify(s,null,2))}catch(l){console.error(ce(t,l)),process.exit(1)}}var J=c(require("path")),M=c(require("fs/promises"));async function Je(e,t){let r=J.default.join(e,"extension-env.d.ts"),o=process.env.EXTENSION_ENV==="development"?J.default.resolve(process.cwd(),"programs/cli/types"):"extension/dist/types",i=`// Required Extension.js types for TypeScript projects.
396
30
  // This file is auto-generated and should not be excluded.
397
31
  // If you need additional types, consider creating a new *.d.ts file and
398
32
  // referencing it in the "include" array of your tsconfig.json file.
399
33
  // See https://www.typescriptlang.org/tsconfig#include for more information.
400
- /// <reference types="${typePath}/index.d.ts" />
34
+ /// <reference types="${o}/index.d.ts" />
401
35
 
402
36
  // Polyfill types for browser.* APIs.
403
- /// <reference types="${typePath}/polyfill.d.ts" />
404
- `;
405
- try {
406
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir(projectPath, {
407
- recursive: true
408
- });
409
- console.log(writingTypeDefinitions(projectName));
410
- await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.writeFile(extensionEnvFile, fileContent);
411
- } catch (error) {
412
- console.error(writingTypeDefinitionsError(error));
413
- process.exit(1);
414
- }
415
- }
416
- const globalDependencies = [
417
- '',
418
- '# dependencies',
419
- 'node_modules'
420
- ];
421
- const globalTesting = [
422
- '',
423
- '# testing',
424
- 'coverage'
425
- ];
426
- const globalProduction = [
427
- '',
428
- '# production',
429
- 'dist'
430
- ];
431
- const globalMisc = [
432
- '',
433
- '# misc',
434
- '.DS_Store'
435
- ];
436
- const envFiles = [
437
- '',
438
- '# local env files',
439
- '.env.local',
440
- '.env.development.local',
441
- '.env.test.local',
442
- '.env.production.local'
443
- ];
444
- const debugFiles = [
445
- '',
446
- '# debug files',
447
- 'npm-debug.log*',
448
- 'yarn-debug.log*',
449
- 'yarn-error.log*'
450
- ];
451
- const extensionJsFiles = [
452
- '',
453
- '# extension.js',
454
- 'extension-env.d.ts'
455
- ];
456
- const globalLines = [
457
- '# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.',
458
- ...globalDependencies,
459
- ...globalTesting,
460
- ...globalProduction,
461
- ...globalMisc,
462
- ...envFiles,
463
- ...debugFiles,
464
- ...extensionJsFiles
465
- ];
466
- async function writeGitignore(projectPath) {
467
- const gitIgnorePath = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, '.gitignore');
468
- const fileHandle = await __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.open(gitIgnorePath, 'a+').catch((err)=>{
469
- console.error(err);
470
- process.exit(1);
471
- });
472
- const paths = new Set();
473
- for await (let line of fileHandle.readLines({
474
- autoClose: false
475
- })){
476
- line = line.trim();
477
- if (0 !== line.length) paths.add(line);
478
- }
479
- const linesToAdd = globalLines.filter((line)=>!paths.has(line));
480
- while('' === linesToAdd[linesToAdd.length - 1])linesToAdd.pop();
481
- console.log(writingGitIgnore());
482
- await fileHandle.appendFile(linesToAdd.join('\n')).catch((err)=>{
483
- console.error(err);
484
- process.exit(1);
485
- });
486
- }
487
- async function initializeGitRepository(projectPath, projectName) {
488
- const gitCommand = 'git';
489
- const gitArgs = [
490
- 'init',
491
- '--quiet'
492
- ];
493
- console.log(initializingGitForRepository(projectName));
494
- try {
495
- const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
496
- const child = (0, __WEBPACK_EXTERNAL_MODULE_cross_spawn_96b24ecb__.spawn)(gitCommand, gitArgs, {
497
- stdio,
498
- cwd: projectPath
499
- });
500
- await new Promise((resolve, reject)=>{
501
- child.on('close', (code)=>{
502
- if (0 !== code) reject(new Error(initializingGitForRepositoryFailed(gitCommand, gitArgs, code)));
503
- else resolve();
504
- });
505
- child.on('error', (error)=>{
506
- console.error(initializingGitForRepositoryProcessError(projectName, error));
507
- reject(error);
508
- });
509
- });
510
- } catch (error) {
511
- console.error(initializingGitForRepositoryError(projectName, error));
512
- process.exit(1);
513
- }
514
- }
515
- async function setupBuiltInTests(projectPath, projectName) {
516
- try {
517
- const testSpecPath = __WEBPACK_EXTERNAL_MODULE_path__.join(projectPath, 'tests', 'templates.spec.ts');
518
- if (__WEBPACK_EXTERNAL_MODULE_fs__.existsSync(testSpecPath)) __WEBPACK_EXTERNAL_MODULE_fs__.unlinkSync(testSpecPath);
519
- } catch (error) {
520
- console.error(cantSetupBuiltInTests(projectName, error));
521
- process.exit(1);
522
- }
523
- }
524
- async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = true }) {
525
- if (!projectNameInput) throw new Error(noProjectName());
526
- if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
527
- const projectPath = __WEBPACK_EXTERNAL_MODULE_path__.isAbsolute(projectNameInput) ? projectNameInput : __WEBPACK_EXTERNAL_MODULE_path__.join(process.cwd(), projectNameInput);
528
- const projectName = __WEBPACK_EXTERNAL_MODULE_path__.basename(projectPath);
529
- try {
530
- await createDirectory(projectPath, projectName);
531
- if ('init' === template) await importLocalTemplate(projectPath, projectName, template);
532
- else await importExternalTemplate(projectPath, projectName, template);
533
- await overridePackageJson(projectPath, projectName, {
534
- template,
535
- cliVersion
536
- });
537
- if (install) await installDependencies(projectPath, projectName);
538
- await writeReadmeFile(projectPath, projectName);
539
- await writeManifestJson(projectPath, projectName);
540
- await initializeGitRepository(projectPath, projectName);
541
- await writeGitignore(projectPath);
542
- await setupBuiltInTests(projectPath, projectName);
543
- if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
544
- const successfulInstall = await successfullInstall(projectPath, projectName);
545
- console.log(successfulInstall);
546
- } catch (error) {
547
- console.error(error);
548
- throw error;
549
- }
550
- }
551
- export { extensionCreate };
37
+ /// <reference types="${o}/polyfill.d.ts" />
38
+ `;try{await M.default.mkdir(e,{recursive:!0}),console.log(q(t)),await M.default.writeFile(r,i)}catch(s){console.error(H(s)),process.exit(1)}}var Me=c(require("fs/promises")),Re=c(require("path"));var Qe=["","# dependencies","node_modules"],Ze=["","# testing","coverage"],et=["","# production","dist"],tt=["","# misc",".DS_Store"],nt=["","# local env files",".env.local",".env.development.local",".env.test.local",".env.production.local"],it=["","# debug files","npm-debug.log*","yarn-debug.log*","yarn-error.log*"],rt=["","# extension.js","extension-env.d.ts"],st=["# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.",...Qe,...Ze,...et,...tt,...nt,...it,...rt];async function Ne(e){let t=Re.default.join(e,".gitignore"),r=await Me.default.open(t,"a+").catch(s=>{console.error(s),process.exit(1)}),o=new Set;for await(let s of r.readLines({autoClose:!1}))s=s.trim(),s.length!==0&&o.add(s);let i=st.filter(s=>!o.has(s));for(;i[i.length-1]==="";)i.pop();console.log(me()),await r.appendFile(i.join(`
39
+ `),{flush:!0}).catch(s=>{console.error(s),process.exit(1)})}var Oe=require("cross-spawn");async function je(e,t){let r="git",o=["init","--quiet"];console.log(K(t));try{let i=process.cwd();process.chdir(e);let s=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",l=(0,Oe.spawn)(r,o,{stdio:s});await new Promise((a,m)=>{l.on("close",p=>{process.chdir(i),p!==0?m(new Error(Q(r,o,p))):a()}),l.on("error",p=>{process.chdir(i),console.error(Z(t,p)),m(p)})})}catch(i){console.error(ee(t,i)),process.exit(1)}}var Ae=c(require("path")),R=c(require("fs"));async function Ge(e,t){try{let r=Ae.default.join(e,"tests","templates.spec.ts");R.default.existsSync(r)&&R.default.unlinkSync(r)}catch(r){console.error(de(t,r)),process.exit(1)}}async function ot(e,{cliVersion:t,template:r="init",install:o=!0}){if(!e)throw new Error(z());if(e.startsWith("http"))throw new Error(V());let i=C.default.isAbsolute(e)?e:C.default.join(process.cwd(),e),s=C.default.basename(i);try{await Ee(i,s),r==="init"?await be(i,s,r):await Te(i,s,r),await Fe(i,s,{template:r,cliVersion:t}),o&&await Pe(i,s),await _e(i,s),await Ie(i,s),await je(i,s),await Ne(i),await Ge(i,s),he(r)&&await Je(i,s);let l=await X(i,s);console.log(l)}catch(l){throw console.error(l),l}}0&&(module.exports={extensionCreate});
@@ -5,7 +5,6 @@
5
5
  "url": "https://github.com/extension-js/extension.git",
6
6
  "directory": "examples/init"
7
7
  },
8
- "type": "module",
9
8
  "name": "init",
10
9
  "description": "An Extension.js example.",
11
10
  "version": "0.0.1",
package/package.json CHANGED
@@ -8,50 +8,42 @@
8
8
  "engines": {
9
9
  "node": ">=18"
10
10
  },
11
- "type": "module",
12
- "exports": {
13
- ".": {
14
- "types": "./dist/module.d.ts",
15
- "import": "./dist/module.js"
16
- }
17
- },
11
+ "name": "extension-create",
12
+ "version": "2.0.0-rc.25",
13
+ "description": "The Extension.js create step",
18
14
  "main": "./dist/module.js",
19
15
  "types": "./dist/module.d.ts",
20
16
  "files": [
21
17
  "dist"
22
18
  ],
23
- "name": "extension-create",
24
- "version": "2.0.0-rc.24",
25
- "description": "The create step of Extension.js",
26
19
  "author": {
27
20
  "name": "Cezar Augusto",
28
21
  "email": "boss@cezaraugusto.net",
29
22
  "url": "https://cezaraugusto.com"
30
23
  },
31
24
  "dependencies": {
25
+ "@colors/colors": "^1.6.0",
32
26
  "@types/firefox-webext-browser": "^120.0.4",
33
- "chalk": "^5.3.0",
34
27
  "cross-spawn": "^7.0.6",
35
- "go-git-it": "4.0.0-1",
36
- "package-manager-detector": "^0.2.7",
37
- "tiny-glob": "^0.2.9"
28
+ "go-git-it": "2.0.4",
29
+ "package-manager-detector": "^0.2.7"
38
30
  },
39
31
  "devDependencies": {
40
- "@rslib/core": "^0.6.9",
41
32
  "@types/cross-spawn": "^6.0.6",
42
33
  "@types/node": "^22.10.1",
43
34
  "@types/react-dom": "^19.0.1",
44
- "@vitest/coverage-v8": "^1.3.1",
45
35
  "globals": "^15.13.0",
36
+ "jest": "^29.7.0",
37
+ "ts-jest": "^29.3.1",
46
38
  "tsconfig": "*",
47
- "typescript": "5.7.2",
48
- "vitest": "^1.3.1"
39
+ "tsup": "^8.3.5",
40
+ "typescript": "5.7.2"
49
41
  },
50
42
  "scripts": {
51
43
  "clean": "rm -rf dist",
52
- "watch": "rslib build --watch",
53
- "compile": "rslib build && bash install_scripts.sh",
54
- "test:create": "vitest run",
55
- "test:coverage": "vitest run --coverage"
44
+ "watch": "tsup-node ./module.ts --format cjs --dts --target=node18 --watch",
45
+ "compile": "tsup-node ./module.ts --format cjs --dts --target=node18 --minify && bash install_scripts.sh",
46
+ "test": "echo \"Note: no test specified\" && exit 0",
47
+ "test:create": "jest ./create.spec.ts --no-cache"
56
48
  }
57
49
  }