extension-create 3.1.1 → 3.2.0-next.10
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/lib/package-manager.d.ts +3 -0
- package/dist/lib/utils.d.ts +1 -1
- package/dist/module.js +199 -38
- package/package.json +1 -2
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<void>;
|
|
2
2
|
export declare function moveDirectoryContents(source: string, destination: string): Promise<void>;
|
|
3
|
-
export declare function getInstallCommand(): Promise<
|
|
3
|
+
export declare function getInstallCommand(): Promise<"pnpm" | "yarn" | "npm">;
|
|
4
4
|
export declare function isDirectoryWriteable(directory: string, projectName: string): Promise<boolean>;
|
|
5
5
|
export declare function isTypeScriptTemplate(templateName: string): boolean;
|
package/dist/module.js
CHANGED
|
@@ -42,7 +42,17 @@ const external_path_namespaceObject = require("path");
|
|
|
42
42
|
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
|
+
function detectPackageManagerFromEnv() {
|
|
46
|
+
const userAgent = process.env.npm_config_user_agent || '';
|
|
47
|
+
if (userAgent.includes('pnpm')) return 'pnpm';
|
|
48
|
+
if (userAgent.includes('yarn')) return 'yarn';
|
|
49
|
+
if (userAgent.includes('npm')) return 'npm';
|
|
50
|
+
const execPath = process.env.npm_execpath || process.env.NPM_EXEC_PATH || '';
|
|
51
|
+
if (execPath.includes('pnpm')) return 'pnpm';
|
|
52
|
+
if (execPath.includes('yarn')) return 'yarn';
|
|
53
|
+
execPath.includes('npm');
|
|
54
|
+
return 'npm';
|
|
55
|
+
}
|
|
46
56
|
const statusPrefix = external_pintor_default().brightBlue('►►►');
|
|
47
57
|
function destinationNotWriteable(workingDir) {
|
|
48
58
|
const workingDirFolder = external_path_namespaceObject.basename(workingDir);
|
|
@@ -66,10 +76,10 @@ function noUrlAllowed() {
|
|
|
66
76
|
}
|
|
67
77
|
async function successfullInstall(projectPath, projectName, depsInstalled) {
|
|
68
78
|
const relativePath = external_path_namespaceObject.relative(process.cwd(), projectPath);
|
|
69
|
-
const pm =
|
|
79
|
+
const pm = detectPackageManagerFromEnv();
|
|
70
80
|
let command = 'npm run';
|
|
71
81
|
let installCmd = 'npm install';
|
|
72
|
-
switch(pm
|
|
82
|
+
switch(pm){
|
|
73
83
|
case 'yarn':
|
|
74
84
|
command = 'yarn dev';
|
|
75
85
|
installCmd = 'yarn';
|
|
@@ -82,12 +92,6 @@ async function successfullInstall(projectPath, projectName, depsInstalled) {
|
|
|
82
92
|
command = 'npm run dev';
|
|
83
93
|
installCmd = 'npm install';
|
|
84
94
|
}
|
|
85
|
-
if (process.env.npm_config_user_agent) {
|
|
86
|
-
if (process.env.npm_config_user_agent.includes('pnpm')) {
|
|
87
|
-
command = 'pnpm dev';
|
|
88
|
-
installCmd = 'pnpm install';
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
95
|
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
96
|
const depsNote = depsInstalled ? `\n${external_pintor_default().gray('Dependencies installed. You can start developing now.')}\n` : '\n';
|
|
93
97
|
return `${statusPrefix} ${external_pintor_default().green('Created')} ${external_pintor_default().blue(projectName)}\n\nNext steps:\n\n` + steps + depsNote;
|
|
@@ -220,22 +224,7 @@ async function moveDirectoryContents(source, destination) {
|
|
|
220
224
|
});
|
|
221
225
|
}
|
|
222
226
|
async function getInstallCommand() {
|
|
223
|
-
|
|
224
|
-
let command = 'npm';
|
|
225
|
-
if (process.env.npm_config_user_agent) {
|
|
226
|
-
if (process.env.npm_config_user_agent.includes('pnpm')) return 'pnpm';
|
|
227
|
-
}
|
|
228
|
-
switch(pm?.name){
|
|
229
|
-
case 'yarn':
|
|
230
|
-
command = 'yarn';
|
|
231
|
-
break;
|
|
232
|
-
case 'pnpm':
|
|
233
|
-
command = 'pnpm';
|
|
234
|
-
break;
|
|
235
|
-
default:
|
|
236
|
-
command = 'npm';
|
|
237
|
-
}
|
|
238
|
-
return command;
|
|
227
|
+
return detectPackageManagerFromEnv();
|
|
239
228
|
}
|
|
240
229
|
async function isDirectoryWriteable(directory, projectName) {
|
|
241
230
|
try {
|
|
@@ -292,7 +281,10 @@ const import_external_template_dirname = external_path_namespaceObject.dirname(i
|
|
|
292
281
|
async function importExternalTemplate(projectPath, projectName, template) {
|
|
293
282
|
const templateName = external_path_namespaceObject.basename(template);
|
|
294
283
|
const examplesUrl = 'https://github.com/extension-js/examples/tree/main/examples';
|
|
295
|
-
const
|
|
284
|
+
const resolvedTemplate = 'init' === templateName ? "javascript" : template;
|
|
285
|
+
const resolvedTemplateName = 'init' === templateName ? "javascript" : templateName;
|
|
286
|
+
const templateUrl = `${examplesUrl}/${resolvedTemplate}`;
|
|
287
|
+
const examplesZipUrl = 'https://codeload.github.com/extension-js/examples/zip/refs/heads/main';
|
|
296
288
|
try {
|
|
297
289
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
298
290
|
recursive: true
|
|
@@ -315,8 +307,7 @@ async function importExternalTemplate(projectPath, projectName, template) {
|
|
|
315
307
|
}
|
|
316
308
|
const localTemplatesRoot = await findTemplatesRoot(import_external_template_dirname);
|
|
317
309
|
if (!localTemplatesRoot) throw new Error('Local templates directory not found');
|
|
318
|
-
const
|
|
319
|
-
const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, localTemplateName);
|
|
310
|
+
const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, resolvedTemplateName);
|
|
320
311
|
await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
|
|
321
312
|
} else {
|
|
322
313
|
const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
|
|
@@ -369,9 +360,39 @@ async function importExternalTemplate(projectPath, projectName, template) {
|
|
|
369
360
|
zip.extractAllTo(tempPath, true);
|
|
370
361
|
await moveDirectoryContents(tempPath, projectPath);
|
|
371
362
|
} else {
|
|
372
|
-
await
|
|
373
|
-
|
|
374
|
-
|
|
363
|
+
const ok = await (async ()=>{
|
|
364
|
+
const zipExtractRoot = external_path_namespaceObject.join(tempPath, 'zip-extract');
|
|
365
|
+
try {
|
|
366
|
+
const { data } = await external_axios_default().get(examplesZipUrl, {
|
|
367
|
+
responseType: 'arraybuffer',
|
|
368
|
+
maxRedirects: 5
|
|
369
|
+
});
|
|
370
|
+
const zip = new (external_adm_zip_default())(Buffer.from(data));
|
|
371
|
+
zip.extractAllTo(zipExtractRoot, true);
|
|
372
|
+
const entries = await promises_namespaceObject.readdir(zipExtractRoot, {
|
|
373
|
+
withFileTypes: true
|
|
374
|
+
});
|
|
375
|
+
const rootDir = entries.find((e)=>e.isDirectory())?.name;
|
|
376
|
+
if (!rootDir) return false;
|
|
377
|
+
const srcPath = external_path_namespaceObject.join(zipExtractRoot, rootDir, 'examples', resolvedTemplateName);
|
|
378
|
+
await moveDirectoryContents(srcPath, projectPath);
|
|
379
|
+
return true;
|
|
380
|
+
} catch {
|
|
381
|
+
return false;
|
|
382
|
+
} finally{
|
|
383
|
+
try {
|
|
384
|
+
await promises_namespaceObject.rm(zipExtractRoot, {
|
|
385
|
+
recursive: true,
|
|
386
|
+
force: true
|
|
387
|
+
});
|
|
388
|
+
} catch {}
|
|
389
|
+
}
|
|
390
|
+
})();
|
|
391
|
+
if (!ok) {
|
|
392
|
+
await withFilteredOutput(()=>external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName)));
|
|
393
|
+
const srcPath = external_path_namespaceObject.join(tempPath, resolvedTemplateName);
|
|
394
|
+
await moveDirectoryContents(srcPath, projectPath);
|
|
395
|
+
}
|
|
375
396
|
}
|
|
376
397
|
await promises_namespaceObject.rm(tempRoot, {
|
|
377
398
|
recursive: true,
|
|
@@ -608,17 +629,137 @@ async function writeManifestJson(projectPath, projectName) {
|
|
|
608
629
|
}
|
|
609
630
|
async function generateExtensionTypes(projectPath, projectName) {
|
|
610
631
|
const extensionEnvFile = external_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
|
|
611
|
-
const
|
|
632
|
+
const { dependencies, devDependencies, peerDependencies, optionalDependencies } = await readPackageJson(projectPath);
|
|
633
|
+
const hasDependency = (name)=>Boolean(dependencies[name] || devDependencies[name] || peerDependencies[name] || optionalDependencies[name]);
|
|
634
|
+
const usesReact = hasDependency('react') || hasDependency('@types/react');
|
|
635
|
+
const usesReactDom = hasDependency('react-dom') || hasDependency('@types/react-dom');
|
|
636
|
+
const usesSvelte = hasDependency('svelte');
|
|
637
|
+
const frameworkTypeRefs = [
|
|
638
|
+
usesReact ? '/// <reference types="react" />' : '',
|
|
639
|
+
usesReactDom ? '/// <reference types="react-dom" />' : '',
|
|
640
|
+
usesSvelte ? '/// <reference types="svelte" />' : ''
|
|
641
|
+
].filter(Boolean).join('\n');
|
|
612
642
|
const fileContent = `\
|
|
613
643
|
// Required Extension.js types for TypeScript projects.
|
|
614
644
|
// This file is auto-generated and should not be excluded.
|
|
615
|
-
//
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
/// <reference types="
|
|
645
|
+
//
|
|
646
|
+
/// <reference types="webextension-polyfill" />
|
|
647
|
+
/// <reference types="node" />
|
|
648
|
+
/// <reference types="chrome" />
|
|
649
|
+
${frameworkTypeRefs}
|
|
650
|
+
|
|
651
|
+
declare global {
|
|
652
|
+
const browser: typeof import('webextension-polyfill')
|
|
653
|
+
|
|
654
|
+
type ExtensionBrowser =
|
|
655
|
+
| 'chrome'
|
|
656
|
+
| 'edge'
|
|
657
|
+
| 'firefox'
|
|
658
|
+
| 'chromium-based'
|
|
659
|
+
| 'gecko-based'
|
|
660
|
+
|
|
661
|
+
type ExtensionMode = 'development' | 'production'
|
|
662
|
+
|
|
663
|
+
interface ExtensionEnv {
|
|
664
|
+
EXTENSION_BROWSER: ExtensionBrowser
|
|
665
|
+
EXTENSION_MODE: ExtensionMode
|
|
666
|
+
EXTENSION_PUBLIC_BROWSER: ExtensionBrowser
|
|
667
|
+
EXTENSION_PUBLIC_MODE: ExtensionMode
|
|
668
|
+
EXTENSION_PUBLIC_DESCRIPTION_TEXT: string
|
|
669
|
+
EXTENSION_PUBLIC_LLM_API_KEY: string
|
|
670
|
+
EXTENSION_AUTHOR_MODE: string
|
|
671
|
+
EXTENSION_PUBLIC_AUTHOR_MODE: string
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
namespace NodeJS {
|
|
675
|
+
interface ProcessEnv extends ExtensionEnv {
|
|
676
|
+
[key: string]: string | undefined
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
interface ImportMetaEnv extends ExtensionEnv {
|
|
681
|
+
[key: string]: string | undefined
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
interface ImportMeta {
|
|
685
|
+
readonly env: ImportMetaEnv
|
|
686
|
+
readonly webpackHot?: {
|
|
687
|
+
accept: (module?: string | string[], callback?: () => void) => void
|
|
688
|
+
dispose: (callback: () => void) => void
|
|
689
|
+
}
|
|
690
|
+
url: string
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
interface Window {
|
|
694
|
+
/**
|
|
695
|
+
* @deprecated
|
|
696
|
+
* @description
|
|
697
|
+
* This is how Extension.js used to inject the shadow root into the window object.
|
|
698
|
+
* Use the shadowRoot reference from the content script instead.
|
|
699
|
+
*/
|
|
700
|
+
__EXTENSION_SHADOW_ROOT__: ShadowRoot
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
type CSSContentData = Readonly<Record<string, string>>
|
|
705
|
+
type CSSModuleData = Readonly<Record<string, string>>
|
|
706
|
+
|
|
707
|
+
declare module '*.css' {
|
|
708
|
+
const content: CSSContentData
|
|
709
|
+
export default content
|
|
710
|
+
}
|
|
619
711
|
|
|
620
|
-
|
|
621
|
-
|
|
712
|
+
declare module '*.module.css' {
|
|
713
|
+
const content: CSSModuleData
|
|
714
|
+
export default content
|
|
715
|
+
}
|
|
716
|
+
declare module '*.module.scss' {
|
|
717
|
+
const content: CSSModuleData
|
|
718
|
+
export default content
|
|
719
|
+
}
|
|
720
|
+
declare module '*.module.sass' {
|
|
721
|
+
const content: CSSModuleData
|
|
722
|
+
export default content
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
declare module '*.png' {
|
|
726
|
+
const content: string
|
|
727
|
+
export default content
|
|
728
|
+
}
|
|
729
|
+
declare module '*.jpg' {
|
|
730
|
+
const content: string
|
|
731
|
+
export default content
|
|
732
|
+
}
|
|
733
|
+
declare module '*.jpeg' {
|
|
734
|
+
const content: string
|
|
735
|
+
export default content
|
|
736
|
+
}
|
|
737
|
+
declare module '*.gif' {
|
|
738
|
+
const content: string
|
|
739
|
+
export default content
|
|
740
|
+
}
|
|
741
|
+
declare module '*.webp' {
|
|
742
|
+
const content: string
|
|
743
|
+
export default content
|
|
744
|
+
}
|
|
745
|
+
declare module '*.avif' {
|
|
746
|
+
const content: string
|
|
747
|
+
export default content
|
|
748
|
+
}
|
|
749
|
+
declare module '*.ico' {
|
|
750
|
+
const content: string
|
|
751
|
+
export default content
|
|
752
|
+
}
|
|
753
|
+
declare module '*.bmp' {
|
|
754
|
+
const content: string
|
|
755
|
+
export default content
|
|
756
|
+
}
|
|
757
|
+
declare module '*.svg' {
|
|
758
|
+
const content: any
|
|
759
|
+
export default content
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
export {}
|
|
622
763
|
`;
|
|
623
764
|
try {
|
|
624
765
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
@@ -631,6 +772,26 @@ async function generateExtensionTypes(projectPath, projectName) {
|
|
|
631
772
|
throw error;
|
|
632
773
|
}
|
|
633
774
|
}
|
|
775
|
+
async function readPackageJson(projectPath) {
|
|
776
|
+
const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
|
|
777
|
+
try {
|
|
778
|
+
const content = await promises_namespaceObject.readFile(packageJsonPath, 'utf8');
|
|
779
|
+
const parsed = JSON.parse(content) || {};
|
|
780
|
+
return {
|
|
781
|
+
dependencies: parsed.dependencies || {},
|
|
782
|
+
devDependencies: parsed.devDependencies || {},
|
|
783
|
+
peerDependencies: parsed.peerDependencies || {},
|
|
784
|
+
optionalDependencies: parsed.optionalDependencies || {}
|
|
785
|
+
};
|
|
786
|
+
} catch {
|
|
787
|
+
return {
|
|
788
|
+
dependencies: {},
|
|
789
|
+
devDependencies: {},
|
|
790
|
+
peerDependencies: {},
|
|
791
|
+
optionalDependencies: {}
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
}
|
|
634
795
|
const globalDependencies = [
|
|
635
796
|
'',
|
|
636
797
|
'# dependencies',
|
package/package.json
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"name": "extension-create",
|
|
25
|
-
"version": "3.
|
|
25
|
+
"version": "3.2.0-next.10",
|
|
26
26
|
"description": "The standalone extension creation engine for Extension.js",
|
|
27
27
|
"author": {
|
|
28
28
|
"name": "Cezar Augusto",
|
|
@@ -71,7 +71,6 @@
|
|
|
71
71
|
"axios": "^1.13.2",
|
|
72
72
|
"cross-spawn": "^7.0.6",
|
|
73
73
|
"go-git-it": "^5.0.3",
|
|
74
|
-
"package-manager-detector": "^1.6.0",
|
|
75
74
|
"pintor": "0.3.0",
|
|
76
75
|
"tiny-glob": "^0.2.9"
|
|
77
76
|
},
|