extension-create 3.1.0-next.7 → 3.1.1

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.
@@ -2,7 +2,7 @@ export declare function destinationNotWriteable(workingDir: string): string;
2
2
  export declare function directoryHasConflicts(projectPath: string, conflictingFiles: string[]): Promise<string>;
3
3
  export declare function noProjectName(): string;
4
4
  export declare function noUrlAllowed(): string;
5
- export declare function successfullInstall(projectPath: string, projectName: string): Promise<string>;
5
+ export declare function successfullInstall(projectPath: string, projectName: string, depsInstalled: boolean): Promise<string>;
6
6
  export declare function startingNewExtension(projectName: string): string;
7
7
  export declare function checkingIfPathIsWriteable(): string;
8
8
  export declare function scanningPossiblyConflictingFiles(): string;
@@ -1,8 +1,5 @@
1
- export declare function copyDirectory(source: string, destination: string): Promise<void[]>;
2
1
  export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<void>;
3
2
  export declare function moveDirectoryContents(source: string, destination: string): Promise<void>;
4
3
  export declare function getInstallCommand(): Promise<string>;
5
- export declare function getTemplatePath(workingDir: string): string;
6
4
  export declare function isDirectoryWriteable(directory: string, projectName: string): Promise<boolean>;
7
- export declare function isExternalTemplate(_templateName: string): boolean;
8
5
  export declare function isTypeScriptTemplate(templateName: string): boolean;
package/dist/module.js CHANGED
@@ -43,6 +43,7 @@ const external_fs_namespaceObject = require("fs");
43
43
  const external_pintor_namespaceObject = require("pintor");
44
44
  var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
45
45
  const external_package_manager_detector_namespaceObject = require("package-manager-detector");
46
+ const statusPrefix = external_pintor_default().brightBlue('►►►');
46
47
  function destinationNotWriteable(workingDir) {
47
48
  const workingDirFolder = external_path_namespaceObject.basename(workingDir);
48
49
  return `${external_pintor_default().red('Error')} Couldn't write to the destination directory.\n${external_pintor_default().red('Next step: choose a writable path or update folder permissions.')}\n${external_pintor_default().red('Path')} ${external_pintor_default().underline(workingDirFolder)}`;
@@ -63,7 +64,7 @@ function noProjectName() {
63
64
  function noUrlAllowed() {
64
65
  return `${external_pintor_default().red('Error')} URLs are not allowed as a project path.\nNext step: provide a project name or a local directory path.`;
65
66
  }
66
- async function successfullInstall(projectPath, projectName) {
67
+ async function successfullInstall(projectPath, projectName, depsInstalled) {
67
68
  const relativePath = external_path_namespaceObject.relative(process.cwd(), projectPath);
68
69
  const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
69
70
  let command = 'npm run';
@@ -87,35 +88,37 @@ async function successfullInstall(projectPath, projectName) {
87
88
  installCmd = 'pnpm install';
88
89
  }
89
90
  }
90
- return `${external_pintor_default().green('Created')} ${external_pintor_default().blue(projectName)}\n\nNext steps:\n\n 1. ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n 2. ${external_pintor_default().blue(installCmd)}\n 3. ${external_pintor_default().blue(command)} (runs a fresh browser profile with your extension loaded)\n`;
91
+ const steps = depsInstalled ? ` 1. ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n 2. ${external_pintor_default().blue(command)} (runs a fresh browser profile with your extension loaded)\n` : ` 1. ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n 2. ${external_pintor_default().blue(installCmd)}\n 3. ${external_pintor_default().blue(command)} (runs a fresh browser profile with your extension loaded)\n`;
92
+ const depsNote = depsInstalled ? `\n${external_pintor_default().gray('Dependencies installed. You can start developing now.')}\n` : '\n';
93
+ return `${statusPrefix} ${external_pintor_default().green('Created')} ${external_pintor_default().blue(projectName)}\n\nNext steps:\n\n` + steps + depsNote;
91
94
  }
92
95
  function startingNewExtension(projectName) {
93
- return `Creating ${external_pintor_default().blue(projectName)}...`;
96
+ return `${statusPrefix} Creating ${external_pintor_default().blue(projectName)}...`;
94
97
  }
95
98
  function checkingIfPathIsWriteable() {
96
- return 'Checking if the destination path is writable...';
99
+ return `${statusPrefix} Checking if the destination path is writable...`;
97
100
  }
98
101
  function scanningPossiblyConflictingFiles() {
99
- return 'Scanning for conflicting files...';
102
+ return `${statusPrefix} Scanning for conflicting files...`;
100
103
  }
101
104
  function createDirectoryError(projectName, error) {
102
105
  return `${external_pintor_default().red('Error')} Couldn't create directory ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check the path and permissions, then try again.')}`;
103
106
  }
104
107
  function writingTypeDefinitions(projectName) {
105
- return `Writing type definitions for ${external_pintor_default().blue(projectName)}...`;
108
+ return `${statusPrefix} Writing type definitions for ${external_pintor_default().blue(projectName)}...`;
106
109
  }
107
110
  function writingTypeDefinitionsError(error) {
108
111
  return `${external_pintor_default().red('Error')} Couldn't write the extension type definitions.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
109
112
  }
110
113
  function installingFromTemplate(projectName, templateName) {
111
- if ('init' === templateName) return `Installing ${external_pintor_default().blue(projectName)}...`;
112
- return `Installing ${external_pintor_default().blue(projectName)} from template ${external_pintor_default().yellow(templateName)}...`;
114
+ if ('init' === templateName) return `${statusPrefix} Installing ${external_pintor_default().blue(projectName)}...`;
115
+ return `${statusPrefix} Installing ${external_pintor_default().blue(projectName)} from template ${external_pintor_default().yellow(templateName)}...`;
113
116
  }
114
117
  function installingFromTemplateError(projectName, template, error) {
115
118
  return `${external_pintor_default().red('Error')} Couldn't find template ${external_pintor_default().yellow(template)} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: choose a valid template name or URL.')}`;
116
119
  }
117
120
  function initializingGitForRepository(projectName) {
118
- return `Initializing git repository for ${external_pintor_default().blue(projectName)}...`;
121
+ return `${statusPrefix} Initializing git repository for ${external_pintor_default().blue(projectName)}...`;
119
122
  }
120
123
  function initializingGitForRepositoryFailed(gitCommand, gitArgs, code) {
121
124
  return `${external_pintor_default().red('Error')} Command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`Exit code: ${external_pintor_default().yellow(String(code))}`)}\n${external_pintor_default().red('Next step: run the command manually to inspect the error.')}`;
@@ -127,7 +130,7 @@ function initializingGitForRepositoryError(projectName, error) {
127
130
  return `${external_pintor_default().red('Error')} Couldn't initialize ${external_pintor_default().yellow('git')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: retry initialization or create the repository manually.')}`;
128
131
  }
129
132
  function installingDependencies() {
130
- return 'Installing dependencies (this may take a moment)...';
133
+ return `${statusPrefix} Installing dependencies (this may take a moment)...`;
131
134
  }
132
135
  function installingDependenciesFailed(gitCommand, gitArgs, code) {
133
136
  return `${external_pintor_default().red('Error')} Command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`Exit code: ${external_pintor_default().yellow(String(code))}`)}\n${external_pintor_default().red('Next step: run the command manually to inspect the error.')}`;
@@ -139,28 +142,28 @@ function cantInstallDependencies(projectName, error) {
139
142
  return `${external_pintor_default().red('Error')} Couldn't install dependencies for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: check your package manager settings, then try again.')}`;
140
143
  }
141
144
  function writingPackageJsonMetadata() {
142
- return `Writing ${external_pintor_default().yellow('package.json')}...`;
145
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('package.json')}...`;
143
146
  }
144
147
  function writingPackageJsonMetadataError(projectName, error) {
145
148
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('package.json')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
146
149
  }
147
150
  function writingManifestJsonMetadata() {
148
- return `Writing ${external_pintor_default().yellow('manifest.json')}...`;
151
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('manifest.json')}...`;
149
152
  }
150
153
  function writingManifestJsonMetadataError(projectName, error) {
151
154
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('manifest.json')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
152
155
  }
153
156
  function writingReadmeMetaData() {
154
- return `Writing ${external_pintor_default().yellow('README.md')}...`;
157
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('README.md')}...`;
155
158
  }
156
159
  function writingGitIgnore() {
157
- return `Writing ${external_pintor_default().yellow('.gitignore')}...`;
160
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('.gitignore')}...`;
158
161
  }
159
162
  function writingReadmeMetaDataEError(projectName, error) {
160
163
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('README.md')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
161
164
  }
162
165
  function folderExists(projectName) {
163
- return `Ensuring ${external_pintor_default().blue(projectName)} exists...`;
166
+ return `${statusPrefix} Ensuring ${external_pintor_default().blue(projectName)} exists...`;
164
167
  }
165
168
  function writingDirectoryError(error) {
166
169
  return `${external_pintor_default().red('Error')} Couldn't check directory writability.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check the path and permissions, then try again.')}`;
@@ -169,9 +172,6 @@ function cantSetupBuiltInTests(projectName, error) {
169
172
  return `${external_pintor_default().red('Error')} Couldn't set up built-in tests for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: run the setup step again or skip tests.')}`;
170
173
  }
171
174
  const promises_namespaceObject = require("fs/promises");
172
- const external_url_namespaceObject = require("url");
173
- const utils_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
174
- const utils_dirname = external_path_namespaceObject.dirname(utils_filename);
175
175
  async function copyDirectoryWithSymlinks(source, destination) {
176
176
  const entries = await promises_namespaceObject.readdir(source, {
177
177
  withFileTypes: true
@@ -237,10 +237,6 @@ async function getInstallCommand() {
237
237
  }
238
238
  return command;
239
239
  }
240
- function getTemplatePath(workingDir) {
241
- const templatesDir = external_path_namespaceObject.resolve(utils_dirname, '..', 'template');
242
- return external_path_namespaceObject.resolve(workingDir, templatesDir);
243
- }
244
240
  async function isDirectoryWriteable(directory, projectName) {
245
241
  try {
246
242
  console.log(folderExists(projectName));
@@ -253,9 +249,6 @@ async function isDirectoryWriteable(directory, projectName) {
253
249
  return false;
254
250
  }
255
251
  }
256
- function isExternalTemplate(_templateName) {
257
- return true;
258
- }
259
252
  function isTypeScriptTemplate(templateName) {
260
253
  return templateName.includes("typescript") || templateName.includes('react') || templateName.includes('preact') || templateName.includes('svelte') || templateName.includes('solid');
261
254
  }
@@ -286,6 +279,7 @@ async function createDirectory(projectPath, projectName) {
286
279
  throw new Error(createDirectoryError(projectName, error));
287
280
  }
288
281
  }
282
+ const external_url_namespaceObject = require("url");
289
283
  const external_os_namespaceObject = require("os");
290
284
  const external_axios_namespaceObject = require("axios");
291
285
  var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
@@ -305,7 +299,22 @@ async function importExternalTemplate(projectPath, projectName, template) {
305
299
  });
306
300
  if ('development' === process.env.EXTENSION_ENV) {
307
301
  console.log(installingFromTemplate(projectName, template));
308
- const localTemplatesRoot = external_path_namespaceObject.resolve(import_external_template_dirname, '..', '..', '..', '..', 'templates');
302
+ async function findTemplatesRoot(startDir) {
303
+ let current = startDir;
304
+ const maxDepth = 6;
305
+ for(let i = 0; i < maxDepth; i++){
306
+ const candidate = external_path_namespaceObject.join(current, 'templates');
307
+ try {
308
+ const stats = await promises_namespaceObject.stat(candidate);
309
+ if (stats.isDirectory()) return candidate;
310
+ } catch {}
311
+ const parent = external_path_namespaceObject.dirname(current);
312
+ if (parent === current) break;
313
+ current = parent;
314
+ }
315
+ }
316
+ const localTemplatesRoot = await findTemplatesRoot(import_external_template_dirname);
317
+ if (!localTemplatesRoot) throw new Error('Local templates directory not found');
309
318
  const localTemplateName = 'init' === templateName ? "javascript" : templateName;
310
319
  const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, localTemplateName);
311
320
  await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
@@ -381,9 +390,8 @@ const extensionJsPackageJsonScripts = {
381
390
  'build:firefox': 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build --browser firefox' : 'extension build --browser firefox',
382
391
  'build:edge': 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build --browser edge' : 'extension build --browser edge'
383
392
  };
384
- async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
385
- const templatePath = getTemplatePath(process.cwd());
386
- const candidatePath = isExternalTemplate(template) ? external_path_namespaceObject.join(projectPath, 'package.json') : external_path_namespaceObject.join(templatePath, 'package.json');
393
+ async function overridePackageJson(projectPath, projectName, { template: _template, cliVersion }) {
394
+ const candidatePath = external_path_namespaceObject.join(projectPath, 'package.json');
387
395
  let packageJson = {};
388
396
  try {
389
397
  const packageJsonContent = await promises_namespaceObject.readFile(candidatePath);
@@ -725,6 +733,15 @@ async function setupBuiltInTests(projectPath, projectName) {
725
733
  throw error;
726
734
  }
727
735
  }
736
+ const external_module_namespaceObject = require("module");
737
+ async function preflightOptionalDependenciesForCreate(projectPath) {
738
+ try {
739
+ const requireFromProject = (0, external_module_namespaceObject.createRequire)(external_path_namespaceObject.join(projectPath, 'package.json'));
740
+ const develop = requireFromProject('extension-develop');
741
+ const preflight = develop?.preflightOptionalDependenciesForProject;
742
+ if ('function' == typeof preflight) await preflight(projectPath, 'development');
743
+ } catch {}
744
+ }
728
745
  async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = false }) {
729
746
  if (!projectNameInput) throw new Error(noProjectName());
730
747
  if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
@@ -737,14 +754,17 @@ async function extensionCreate(projectNameInput, { cliVersion, template = 'init'
737
754
  template,
738
755
  cliVersion
739
756
  });
740
- if (install) await installDependencies(projectPath, projectName);
757
+ if (install) {
758
+ await installDependencies(projectPath, projectName);
759
+ await preflightOptionalDependenciesForCreate(projectPath);
760
+ }
741
761
  await writeReadmeFile(projectPath, projectName);
742
762
  await writeManifestJson(projectPath, projectName);
743
763
  await initializeGitRepository(projectPath, projectName);
744
764
  await writeGitignore(projectPath);
745
765
  await setupBuiltInTests(projectPath, projectName);
746
766
  if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
747
- const successfulInstall = await successfullInstall(projectPath, projectName);
767
+ const successfulInstall = await successfullInstall(projectPath, projectName, Boolean(install));
748
768
  console.log(successfulInstall);
749
769
  } catch (error) {
750
770
  console.error(error);
@@ -0,0 +1 @@
1
+ export declare function preflightOptionalDependenciesForCreate(projectPath: string): Promise<void>;
@@ -2,5 +2,5 @@ interface OverridePackageJsonOptions {
2
2
  template: string;
3
3
  cliVersion?: string;
4
4
  }
5
- export declare function overridePackageJson(projectPath: string, projectName: string, { template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
5
+ export declare function overridePackageJson(projectPath: string, projectName: string, { template: _template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
6
6
  export {};
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "name": "extension-create",
25
- "version": "3.1.0-next.7",
25
+ "version": "3.1.1",
26
26
  "description": "The standalone extension creation engine for Extension.js",
27
27
  "author": {
28
28
  "name": "Cezar Augusto",
@@ -1,26 +0,0 @@
1
- declare namespace NodeJS {
2
- interface ProcessEnv {
3
- EXTENSION_BROWSER: 'chrome' | 'edge' | 'firefox' | 'chromium-based' | 'gecko-based';
4
- EXTENSION_MODE: 'development' | 'production';
5
- EXTENSION_PUBLIC_BROWSER: 'chrome' | 'edge' | 'firefox' | 'chromium-based' | 'gecko-based';
6
- EXTENSION_PUBLIC_MODE: 'development' | 'production';
7
- EXTENSION_PUBLIC_DESCRIPTION_TEXT: string;
8
- EXTENSION_PUBLIC_LLM_API_KEY: string;
9
- EXTENSION_ENV: 'development' | 'production';
10
- }
11
- }
12
- interface ImportMetaEnv {
13
- EXTENSION_BROWSER: NodeJS.ProcessEnv['EXTENSION_BROWSER'];
14
- EXTENSION_MODE: NodeJS.ProcessEnv['EXTENSION_MODE'];
15
- EXTENSION_PUBLIC_BROWSER: NodeJS.ProcessEnv['EXTENSION_BROWSER'];
16
- EXTENSION_PUBLIC_MODE: NodeJS.ProcessEnv['EXTENSION_MODE'];
17
- [key: string]: string | undefined;
18
- }
19
- interface ImportMeta {
20
- readonly env: ImportMetaEnv;
21
- readonly webpackHot?: {
22
- accept: (module?: string | string[], callback?: () => void) => void;
23
- dispose: (callback: () => void) => void;
24
- };
25
- url: string;
26
- }
@@ -1 +0,0 @@
1
- export declare function importLocalTemplate(projectPath: string, projectName: string, template: string): Promise<void>;