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

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.
@@ -0,0 +1,31 @@
1
+ export declare function destinationNotWriteable(workingDir: string): string;
2
+ export declare function directoryHasConflicts(projectPath: string, conflictingFiles: string[]): Promise<string>;
3
+ export declare function noProjectName(): string;
4
+ export declare function noUrlAllowed(): string;
5
+ export declare function successfullInstall(projectPath: string, projectName: string): Promise<string>;
6
+ export declare function startingNewExtension(projectName: string): string;
7
+ export declare function checkingIfPathIsWriteable(): string;
8
+ export declare function scanningPossiblyConflictingFiles(): string;
9
+ export declare function createDirectoryError(projectName: string, error: any): string;
10
+ export declare function writingTypeDefinitions(projectName: string): string;
11
+ export declare function writingTypeDefinitionsError(error: any): string;
12
+ export declare function installingFromTemplate(projectName: string, templateName: string): string;
13
+ export declare function installingFromTemplateError(projectName: string, template: string, error: any): string;
14
+ export declare function initializingGitForRepository(projectName: string): string;
15
+ export declare function initializingGitForRepositoryFailed(gitCommand: string, gitArgs: string[], code: number | null): string;
16
+ export declare function initializingGitForRepositoryProcessError(projectName: string, error: any): string;
17
+ export declare function initializingGitForRepositoryError(projectName: string, error: any): string;
18
+ export declare function installingDependencies(): string;
19
+ export declare function installingDependenciesFailed(gitCommand: string, gitArgs: string[], code: number | null): string;
20
+ export declare function installingDependenciesProcessError(projectName: string, error: any): string;
21
+ export declare function cantInstallDependencies(projectName: string, error: any): string;
22
+ export declare function writingPackageJsonMetadata(): string;
23
+ export declare function writingPackageJsonMetadataError(projectName: string, error: any): string;
24
+ export declare function writingManifestJsonMetadata(): string;
25
+ export declare function writingManifestJsonMetadataError(projectName: string, error: any): string;
26
+ export declare function writingReadmeMetaData(): string;
27
+ export declare function writingGitIgnore(): string;
28
+ export declare function writingReadmeMetaDataEError(projectName: string, error: any): string;
29
+ export declare function folderExists(projectName: string): string;
30
+ export declare function writingDirectoryError(error: any): string;
31
+ export declare function cantSetupBuiltInTests(projectName: string, error: any): string;
@@ -0,0 +1,26 @@
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_OPENAI_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
+ }
@@ -0,0 +1,8 @@
1
+ export declare function copyDirectory(source: string, destination: string): Promise<void[]>;
2
+ export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<void>;
3
+ export declare function moveDirectoryContents(source: string, destination: string): Promise<void>;
4
+ export declare function getInstallCommand(): Promise<string>;
5
+ export declare function getTemplatePath(workingDir: string): string;
6
+ export declare function isDirectoryWriteable(directory: string, projectName: string): Promise<boolean>;
7
+ export declare function isExternalTemplate(templateName: string): boolean;
8
+ export declare function isTypeScriptTemplate(templateName: string): boolean;
package/dist/module.d.ts CHANGED
@@ -1,7 +1,6 @@
1
- interface CreateOptions {
1
+ export interface CreateOptions {
2
2
  template: string;
3
3
  install?: boolean;
4
+ cliVersion?: string;
4
5
  }
5
- declare function extensionCreate(projectNameInput: string | undefined, { template, install }: CreateOptions): Promise<void>;
6
-
7
- export { type CreateOptions, extensionCreate };
6
+ export declare function extensionCreate(projectNameInput: string | undefined, { cliVersion, template, install }: CreateOptions): Promise<void>;
package/dist/module.js CHANGED
@@ -1,39 +1,551 @@
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})},j=(e,t,r,s)=>{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:!(s=Ve(t,i))||s.enumerable});return e};var a=(e,t,r)=>(r=e!=null?ze(Le(e)):{},j(t||!e||!e.__esModule?b(r,"default",{value:e,enumerable:!0}):r,e)),Be=e=>j(b({},"__esModule",{value:!0}),e);var at={};Ye(at,{extensionCreate:()=>ot});module.exports=Be(at);var C=a(require("path"));var y=a(require("path")),n=require("@colors/colors/safe"),A=a(require("fs/promises")),G=require("package-manager-detector");function W(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 O(e,t){let r=y.default.basename(e),s=`
5
- Conflict! Path to ${(0,n.cyan)(r)} includes conflicting files:
6
-
7
- `;for(let i of t){let o=await A.default.lstat(y.default.join(e,i));s+=o.isDirectory()?`${(0,n.gray)("-")} ${(0,n.brightYellow)(i)}
8
- `:`${(0,n.gray)("-")} ${(0,n.brightYellow)(i)}
9
- `}return s+=`
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)}`,s}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),s=await(0,G.detect)(),i="npm run";switch(s?.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=a(require("fs/promises")),E=a(require("path")),ue=require("package-manager-detector");async function $(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 s=>{let i=E.default.join(e,s.name),o=E.default.join(t,s.name);s.isDirectory()?await $(i,o):await h.default.copyFile(i,o)}))}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=E.default.resolve(__dirname,"template");return E.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 Ee=a(require("path")),_=a(require("fs/promises"));var qe=["LICENSE","node_modules"];async function $e(e,t){console.log(L(t));try{let r=await ye(e,t);console.log(U()),r||(console.error(W(e)),process.exit(1));let s=await _.default.readdir(e);console.log(Y());let i=await Promise.all(s.filter(o=>!o.startsWith(".")).filter(o=>!o.endsWith(".log")).filter(o=>!qe.includes(o)).map(async o=>(await _.default.lstat(Ee.default.join(e,o))).isDirectory()?`${o}/`:`${o}`));if(i.length>0){let o=await O(e,i);throw new Error(o)}}catch(r){console.error(B(t,r)),process.exit(1)}}var ve=a(require("path"));async function be(e,t,r){let s=ve.default.resolve(__dirname,"template");try{console.log(x(t,r)),await $(s,e)}catch(i){console.error(D(t,r,i)),process.exit(1)}}var p=a(require("path")),u=a(require("fs/promises")),De=a(require("go-git-it"));async function Te(e,t,r){let s=p.default.dirname(e),i=p.default.basename(r),c=`https://github.com/extension-js/extension.js/tree/main/examples/${r}`;try{await u.default.mkdir(e,{recursive:!0});let l="";if(process.env.EXTENSION_ENV==="development"){console.log(x(t,r)),l=p.default.join(e,i);let m=p.default.join(__dirname,"..","..","..","examples",i);await $(m,l)}else await(0,De.default)(c,s,x(t,i)),l=p.default.join(s,i);if(t!==i){let m=p.default.join(s,t);await u.default.mkdir(m,{recursive:!0});let g=await u.default.readdir(l);for(let d of g)await u.default.rename(p.default.join(l,d),p.default.join(m,d));await u.default.rm(l,{recursive:!0,force:!0})}else{let m=p.default.join(s,t+"-temp");await u.default.rename(l,m);let g=p.default.join(m,i),d=p.default.join(s,t);await u.default.mkdir(d,{recursive:!0});let Oe=await u.default.readdir(g);for(let N of Oe)await u.default.rename(p.default.join(g,N),p.default.join(d,N));await u.default.rm(m,{recursive:!0,force:!0})}}catch(l){console.error(D(t,i,l)),process.exit(1)}}var v=a(require("path")),I=a(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,r){let s=we(process.cwd()),i=xe(r)?v.default.join(e,"package.json"):v.default.join(s,"package.json"),o=await I.default.readFile(i),c=JSON.parse(o.toString());c.scripts=c.scripts||{},c.dependencies=c.dependencies||{},c.devDependencies={...c.devDependencies||{},extension:process.env.EXTENSION_ENV==="development"?"*":"latest"};let l={...c,name:v.default.basename(e),private:!0,scripts:{...c.scripts,...He},dependencies:c.dependencies,devDependencies:c.devDependencies,author:{name:"Your Name",email:"your@email.com",url:"https://yourwebsite.com"}};try{console.log(se()),await I.default.writeFile(v.default.join(e,"package.json"),JSON.stringify(l,null,2))}catch(m){console.error(oe(t,m)),process.exit(1)}}var ke=a(require("path")),Se=require("cross-spawn"),Ce=a(require("fs"));function Ke(){return["install","--silent"]}async function _e(e,t){let r=ke.default.join(e,"node_modules"),s=await T(),i=Ke();console.log(te());try{let o=process.cwd();process.chdir(e),await Ce.default.promises.mkdir(r,{recursive:!0});let c=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",l=(0,Se.spawn)(s,i,{stdio:c});await new Promise((m,g)=>{l.on("close",d=>{process.chdir(o),d!==0?g(new Error(ne(s,i,d))):m()}),l.on("error",d=>{process.chdir(o),console.error(ie(t,d)),g(d)})})}catch(o){console.error(re(t,o)),process.exit(1)}}var F=a(require("path")),k=a(require("fs/promises"));async function Ie(e,t){let r=await k.default.readFile(F.default.join(__dirname,"template","README.md"),"utf-8"),s=await T(),i=require(F.default.join(e,"manifest.json")),o=r.replaceAll("[projectName]",t).replaceAll("[templateDescription]",i.description).replaceAll("[runCommand]",s);try{console.log(le()),await k.default.mkdir(e,{recursive:!0}),await k.default.writeFile(F.default.join(e,"README.md"),o)}catch(c){console.error(pe(t,c)),process.exit(1)}}var S=a(require("path")),P=a(require("fs/promises"));async function Pe(e,t){let r=S.default.join(e,"manifest.json"),s=await P.default.readFile(r),o={...JSON.parse(s.toString()),name:S.default.basename(e),author:"Your Name"};try{console.log(ae()),await P.default.writeFile(S.default.join(e,"manifest.json"),JSON.stringify(o,null,2))}catch(c){console.error(ce(t,c)),process.exit(1)}}var J=a(require("path")),M=a(require("fs/promises"));async function Je(e,t){let r=J.default.join(e,"extension-env.d.ts"),s=process.env.EXTENSION_ENV==="development"?J.default.resolve(process.cwd(),"programs/cli/types"):"extension/dist/types",i=`// Required Extension.js types for TypeScript projects.
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.
30
396
  // This file is auto-generated and should not be excluded.
31
397
  // If you need additional types, consider creating a new *.d.ts file and
32
398
  // referencing it in the "include" array of your tsconfig.json file.
33
399
  // See https://www.typescriptlang.org/tsconfig#include for more information.
34
- /// <reference types="${s}/index.d.ts" />
400
+ /// <reference types="${typePath}/index.d.ts" />
35
401
 
36
402
  // Polyfill types for browser.* APIs.
37
- /// <reference types="${s}/polyfill.d.ts" />
38
- `;try{await M.default.mkdir(e,{recursive:!0}),console.log(q(t)),await M.default.writeFile(r,i)}catch(o){console.error(H(o)),process.exit(1)}}var Me=a(require("fs/promises")),Re=a(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(o=>{console.error(o),process.exit(1)}),s=new Set;for await(let o of r.readLines({autoClose:!1}))o=o.trim(),o.length!==0&&s.add(o);let i=st.filter(o=>!s.has(o));for(;i[i.length-1]==="";)i.pop();console.log(me()),await r.appendFile(i.join(`
39
- `),{flush:!0}).catch(o=>{console.error(o),process.exit(1)})}var je=require("cross-spawn");async function Ae(e,t){let r="git",s=["init","--quiet"];console.log(K(t));try{let i=process.cwd();process.chdir(e);let o=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",c=(0,je.spawn)(r,s,{stdio:o});await new Promise((l,m)=>{c.on("close",g=>{process.chdir(i),g!==0?m(new Error(Q(r,s,g))):l()}),c.on("error",g=>{process.chdir(i),console.error(Z(t,g)),m(g)})})}catch(i){console.error(ee(t,i)),process.exit(1)}}var Ge=a(require("path")),R=a(require("fs"));async function We(e,t){try{let r=Ge.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,{template:t="init",install:r=!0}){if(!e)throw new Error(z());if(e.startsWith("http"))throw new Error(V());let s=C.default.isAbsolute(e)?e:C.default.join(process.cwd(),e),i=C.default.basename(s);try{await $e(s,i),t==="init"?await be(s,i,t):await Te(s,i,t),await Fe(s,i,t),r&&await _e(s,i),await Ie(s,i),await Pe(s,i),await Ae(s,i),await Ne(s),await We(s,i),he(t)&&await Je(s,i);let o=await X(s,i);console.log(o)}catch(o){throw console.error(o),o}}0&&(module.exports={extensionCreate});
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 };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@rslib/core").RslibConfig;
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export declare function createDirectory(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function generateExtensionTypes(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function importExternalTemplate(projectPath: string, projectName: string, template: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function importLocalTemplate(projectPath: string, projectName: string, template: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function initializeGitRepository(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function installDependencies(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function setupBuiltInTests(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function writeGitignore(projectPath: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function writeManifestJson(projectPath: string, projectName: string): Promise<void>;
@@ -0,0 +1,6 @@
1
+ interface OverridePackageJsonOptions {
2
+ template: string;
3
+ cliVersion?: string;
4
+ }
5
+ export declare function overridePackageJson(projectPath: string, projectName: string, { template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
6
+ export {};
@@ -0,0 +1 @@
1
+ export declare function writeReadmeFile(projectPath: string, projectName: string): Promise<void>;
@@ -5,6 +5,7 @@
5
5
  "url": "https://github.com/extension-js/extension.git",
6
6
  "directory": "examples/init"
7
7
  },
8
+ "type": "module",
8
9
  "name": "init",
9
10
  "description": "An Extension.js example.",
10
11
  "version": "0.0.1",
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
package/package.json CHANGED
@@ -8,42 +8,50 @@
8
8
  "engines": {
9
9
  "node": ">=18"
10
10
  },
11
- "name": "extension-create",
12
- "version": "2.0.0-rc.1",
13
- "description": "The Extension.js create step",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/module.d.ts",
15
+ "import": "./dist/module.js"
16
+ }
17
+ },
14
18
  "main": "./dist/module.js",
15
19
  "types": "./dist/module.d.ts",
16
20
  "files": [
17
21
  "dist"
18
22
  ],
23
+ "name": "extension-create",
24
+ "version": "2.0.0-rc.24",
25
+ "description": "The create step of Extension.js",
19
26
  "author": {
20
27
  "name": "Cezar Augusto",
21
28
  "email": "boss@cezaraugusto.net",
22
29
  "url": "https://cezaraugusto.com"
23
30
  },
24
31
  "dependencies": {
25
- "@colors/colors": "^1.6.0",
26
32
  "@types/firefox-webext-browser": "^120.0.4",
33
+ "chalk": "^5.3.0",
27
34
  "cross-spawn": "^7.0.6",
28
- "go-git-it": "2.0.4",
29
- "package-manager-detector": "^0.2.7"
35
+ "go-git-it": "4.0.0-1",
36
+ "package-manager-detector": "^0.2.7",
37
+ "tiny-glob": "^0.2.9"
30
38
  },
31
39
  "devDependencies": {
40
+ "@rslib/core": "^0.6.9",
32
41
  "@types/cross-spawn": "^6.0.6",
33
42
  "@types/node": "^22.10.1",
34
43
  "@types/react-dom": "^19.0.1",
44
+ "@vitest/coverage-v8": "^1.3.1",
35
45
  "globals": "^15.13.0",
36
- "jest": "^29.7.0",
37
- "ts-jest": "^29.2.5",
38
46
  "tsconfig": "*",
39
- "tsup": "^8.3.5",
40
- "typescript": "5.7.2"
47
+ "typescript": "5.7.2",
48
+ "vitest": "^1.3.1"
41
49
  },
42
50
  "scripts": {
43
51
  "clean": "rm -rf dist",
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"
52
+ "watch": "rslib build --watch",
53
+ "compile": "rslib build && bash install_scripts.sh",
54
+ "test:create": "vitest run",
55
+ "test:coverage": "vitest run --coverage"
48
56
  }
49
57
  }