extension-create 2.0.0 → 2.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.
package/README.md CHANGED
@@ -1,8 +1,27 @@
1
+ [npm-version-image]: https://img.shields.io/npm/v/extension-create.svg?color=0971fe
2
+ [npm-version-url]: https://www.npmjs.com/package/extension-create
3
+ [downloads-image]: https://img.shields.io/npm/dm/extension-create.svg?color=2ecc40
4
+ [downloads-url]: https://npmjs.org/package/extension-create
5
+ [empowering-image]: https://img.shields.io/badge/Empowering-Extension.js-0971fe
6
+ [empowering-url]: https://extension.js.org
7
+
8
+ [![Empowering][empowering-image]][empowering-url] [![Version][npm-version-image]][npm-version-url] [![Downloads][downloads-image]][downloads-url]
9
+
1
10
  # extension-create
2
11
 
3
- > The **create** part of [Extension.js](https://github.com/cezaraugusto/extension). Available as a standalone package.
12
+ > Scaffold a new [Extension.js](https://extension.js.org) project from a template.
13
+
14
+ This package implements the logic Extension.js uses to scaffold a new extension project from a selected template.
15
+ It performs, in order:
4
16
 
5
- This package stores all logic needed by Extension.js to create new projects.
17
+ - Create or reuse the target directory (and fail on conflicting files)
18
+ - Import the selected template (local in dev, remote via Git in prod)
19
+ - Write `package.json` metadata and add Extension.js scripts
20
+ - Write `manifest.json` metadata
21
+ - Initialize a Git repository
22
+ - Write a `.gitignore`
23
+ - Remove template-only test files
24
+ - If the template is TypeScript-based, generate `extension-env.d.ts`
6
25
 
7
26
  ## Installation
8
27
 
@@ -19,8 +38,9 @@ async function createNewExtension () {
19
38
  await extensionCreate(
20
39
  projectName: /* string (required) */,
21
40
  {
22
- /* string - Template name or URL. Defaults to 'init' */
23
- template
41
+ template: 'init', // or any template name (see /examples)
42
+ install: false, // optionally run the package manager install step
43
+ cliVersion: '2.x' // used to pin the CLI when not in dev mode
24
44
  }
25
45
  )
26
46
  }
@@ -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,677 @@
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
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
+ return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
+ }();
5
+ var __webpack_require__ = {};
6
+ (()=>{
7
+ __webpack_require__.n = (module)=>{
8
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
9
+ __webpack_require__.d(getter, {
10
+ a: getter
11
+ });
12
+ return getter;
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.d = (exports1, definition)=>{
17
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
18
+ enumerable: true,
19
+ get: definition[key]
20
+ });
21
+ };
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
25
+ })();
26
+ (()=>{
27
+ __webpack_require__.r = (exports1)=>{
28
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
29
+ value: 'Module'
30
+ });
31
+ Object.defineProperty(exports1, '__esModule', {
32
+ value: true
33
+ });
34
+ };
35
+ })();
36
+ var __webpack_exports__ = {};
37
+ __webpack_require__.r(__webpack_exports__);
38
+ __webpack_require__.d(__webpack_exports__, {
39
+ extensionCreate: ()=>extensionCreate
40
+ });
41
+ const external_path_namespaceObject = require("path");
42
+ const external_fs_namespaceObject = require("fs");
43
+ const external_pintor_namespaceObject = require("pintor");
44
+ var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
45
+ const external_package_manager_detector_namespaceObject = require("package-manager-detector");
46
+ function destinationNotWriteable(workingDir) {
47
+ const workingDirFolder = external_path_namespaceObject.basename(workingDir);
48
+ return `${external_pintor_default().red('ERROR')} Failed to write in the destination directory.\n${external_pintor_default().red('Path is not writable. Ensure you have write permissions for this folder.')}\n${external_pintor_default().red('NOT WRITEABLE')} ${external_pintor_default().underline(workingDirFolder)}`;
49
+ }
50
+ async function directoryHasConflicts(projectPath, conflictingFiles) {
51
+ const projectName = external_path_namespaceObject.basename(projectPath);
52
+ let message = `Conflict! Path to ${external_pintor_default().yellow(projectName)} includes conflicting files.\n`;
53
+ for (const file of conflictingFiles){
54
+ const stats = await external_fs_namespaceObject.promises.lstat(external_path_namespaceObject.join(projectPath, file));
55
+ message += stats.isDirectory() ? `${external_pintor_default().gray('-')} ${external_pintor_default().yellow(file)}\n` : `${external_pintor_default().gray('-')} ${external_pintor_default().yellow(file)}\n`;
56
+ }
57
+ message += `${external_pintor_default().red('You need to either rename/remove the files listed above, or choose a new directory name for your extension.')}\nPath to conflicting directory: ${external_pintor_default().underline(projectPath)}`;
58
+ return message;
59
+ }
60
+ function noProjectName() {
61
+ return `${external_pintor_default().red('ERROR')} You need to provide an extension name to create one. See ${external_pintor_default().blue('--help')} for command info.`;
62
+ }
63
+ function noUrlAllowed() {
64
+ return `${external_pintor_default().red('ERROR')} URLs are not allowed as a project path. Either write a name or a path to a local folder.`;
65
+ }
66
+ async function successfullInstall(projectPath, projectName) {
67
+ const relativePath = external_path_namespaceObject.relative(process.cwd(), projectPath);
68
+ const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
69
+ let command = 'npm run';
70
+ let installCmd = 'npm install';
71
+ switch(null == pm ? void 0 : pm.name){
72
+ case 'yarn':
73
+ command = 'yarn dev';
74
+ installCmd = 'yarn';
75
+ break;
76
+ case 'pnpm':
77
+ command = 'pnpm dev';
78
+ installCmd = 'pnpm install';
79
+ break;
80
+ default:
81
+ command = 'npm run dev';
82
+ installCmd = 'npm install';
83
+ }
84
+ if (process.env.npm_config_user_agent) {
85
+ if (process.env.npm_config_user_agent.includes('pnpm')) {
86
+ command = 'pnpm dev';
87
+ installCmd = 'pnpm install';
88
+ }
89
+ }
90
+ return `\u{1F9E9} - ${external_pintor_default().green('Success!')} Extension ${external_pintor_default().yellow(projectName)} created.\nNow ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n${external_pintor_default().blue(installCmd)} to install dependencies\n${external_pintor_default().blue(command)} to open a new browser instance\nwith your extension installed, loaded, and enabled for development.\n${external_pintor_default().green('You are ready')}. Time to hack on your extension!`;
91
+ }
92
+ function startingNewExtension(projectName) {
93
+ return `\u{1F423} - Starting a new browser extension named ${external_pintor_default().yellow(projectName)}...`;
94
+ }
95
+ function checkingIfPathIsWriteable() {
96
+ return `\u{1F91E} - Checking if destination path is writeable...`;
97
+ }
98
+ function scanningPossiblyConflictingFiles() {
99
+ return "\uD83D\uDD0E - Scanning for potential conflicting files...";
100
+ }
101
+ function createDirectoryError(projectName, error) {
102
+ return `${external_pintor_default().red('ERROR')} Can't create directory ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
103
+ }
104
+ function writingTypeDefinitions(projectName) {
105
+ return `\u{1F537} - Writing type definitions for ${external_pintor_default().yellow(projectName)}...`;
106
+ }
107
+ function writingTypeDefinitionsError(error) {
108
+ return `${external_pintor_default().red('ERROR')} Failed to write the extension type definition.\n${external_pintor_default().red(String(error))}`;
109
+ }
110
+ function installingFromTemplate(projectName, templateName) {
111
+ if ('init' === templateName) return `\u{1F9F0} - Installing ${external_pintor_default().yellow(projectName)}...`;
112
+ return `\u{1F9F0} - Installing ${external_pintor_default().yellow(projectName)} from template ${external_pintor_default().yellow(templateName)}...`;
113
+ }
114
+ function installingFromTemplateError(projectName, template, error) {
115
+ return `${external_pintor_default().red('ERROR')} Can't find template ${external_pintor_default().yellow(template)} for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
116
+ }
117
+ function initializingGitForRepository(projectName) {
118
+ return `\u{1F332} - Initializing git repository for ${external_pintor_default().yellow(projectName)}...`;
119
+ }
120
+ function initializingGitForRepositoryFailed(gitCommand, gitArgs, code) {
121
+ return `${external_pintor_default().red('ERROR')} Command ${external_pintor_default().gray(gitCommand)} ${external_pintor_default().gray(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`exit code ${external_pintor_default().gray(String(code))}`)}`;
122
+ }
123
+ function initializingGitForRepositoryProcessError(projectName, error) {
124
+ return `${external_pintor_default().red('ERROR')} Child process error: Can't initialize ${external_pintor_default().gray('git')} for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String((null == error ? void 0 : error.message) || error))}`;
125
+ }
126
+ function initializingGitForRepositoryError(projectName, error) {
127
+ return `${external_pintor_default().red('ERROR')} Can't initialize ${external_pintor_default().gray('git')} for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String((null == error ? void 0 : error.message) || error))}`;
128
+ }
129
+ function installingDependencies() {
130
+ return "\uD83D\uDEE0 - Installing dependencies... (takes a moment)";
131
+ }
132
+ function installingDependenciesFailed(gitCommand, gitArgs, code) {
133
+ return `${external_pintor_default().red('ERROR')} Command ${external_pintor_default().gray(gitCommand)} ${external_pintor_default().gray(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`exit code ${external_pintor_default().gray(String(code))}`)}`;
134
+ }
135
+ function installingDependenciesProcessError(projectName, error) {
136
+ return `${external_pintor_default().red('ERROR')} Child process error: Can't install dependencies for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
137
+ }
138
+ function cantInstallDependencies(projectName, error) {
139
+ return `${external_pintor_default().red('ERROR')} Can't install dependencies for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String((null == error ? void 0 : error.message) || error))}`;
140
+ }
141
+ function writingPackageJsonMetadata() {
142
+ return `\u{1F4DD} - Writing ${external_pintor_default().yellow('package.json')} metadata...`;
143
+ }
144
+ function writingPackageJsonMetadataError(projectName, error) {
145
+ return `${external_pintor_default().red('ERROR')} Can't write ${external_pintor_default().yellow('package.json')} for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
146
+ }
147
+ function writingManifestJsonMetadata() {
148
+ return `\u{1F4DC} - Writing ${external_pintor_default().yellow('manifest.json')} metadata...`;
149
+ }
150
+ function writingManifestJsonMetadataError(projectName, error) {
151
+ return `${external_pintor_default().red('ERROR')} Can't write ${external_pintor_default().yellow('manifest.json')} for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
152
+ }
153
+ function writingReadmeMetaData() {
154
+ return `\u{1F4C4} - Writing ${external_pintor_default().yellow('README.md')} metadata...`;
155
+ }
156
+ function writingGitIgnore() {
157
+ return `\u{1F648} - Writing ${external_pintor_default().yellow('.gitignore')} lines...`;
158
+ }
159
+ function writingReadmeMetaDataEError(projectName, error) {
160
+ return `${external_pintor_default().red('ERROR')} Can't write the ${external_pintor_default().yellow('README.md')} file for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
161
+ }
162
+ function folderExists(projectName) {
163
+ return `\u{1F91D} - Ensuring ${external_pintor_default().yellow(projectName)} folder exists...`;
164
+ }
165
+ function writingDirectoryError(error) {
166
+ return `${external_pintor_default().red('ERROR')} Error while checking directory writability.\n${external_pintor_default().red(String(error))}`;
167
+ }
168
+ function cantSetupBuiltInTests(projectName, error) {
169
+ return `${external_pintor_default().red('ERROR')} Can't setup built-in tests for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}`;
170
+ }
171
+ 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
+ async function copyDirectoryWithSymlinks(source, destination) {
176
+ const entries = await promises_namespaceObject.readdir(source, {
177
+ withFileTypes: true
178
+ });
179
+ await promises_namespaceObject.mkdir(destination, {
180
+ recursive: true
181
+ });
182
+ for (const entry of entries){
183
+ const sourcePath = external_path_namespaceObject.join(source, entry.name);
184
+ const destPath = external_path_namespaceObject.join(destination, entry.name);
185
+ if (entry.isDirectory()) await copyDirectoryWithSymlinks(sourcePath, destPath);
186
+ else if (entry.isSymbolicLink()) {
187
+ const target = await promises_namespaceObject.readlink(sourcePath);
188
+ await promises_namespaceObject.symlink(target, destPath);
189
+ } else await promises_namespaceObject.copyFile(sourcePath, destPath);
190
+ }
191
+ }
192
+ async function moveDirectoryContents(source, destination) {
193
+ await promises_namespaceObject.mkdir(destination, {
194
+ recursive: true
195
+ });
196
+ const entries = await promises_namespaceObject.readdir(source, {
197
+ withFileTypes: true
198
+ });
199
+ for (const entry of entries){
200
+ const sourcePath = external_path_namespaceObject.join(source, entry.name);
201
+ const destPath = external_path_namespaceObject.join(destination, entry.name);
202
+ if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
203
+ else if (entry.isSymbolicLink()) {
204
+ const target = await promises_namespaceObject.readlink(sourcePath);
205
+ await promises_namespaceObject.symlink(target, destPath);
206
+ } else await promises_namespaceObject.rename(sourcePath, destPath);
207
+ }
208
+ await promises_namespaceObject.rm(source, {
209
+ recursive: true,
210
+ force: true
211
+ });
212
+ }
213
+ async function getInstallCommand() {
214
+ const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
215
+ let command = 'npm';
216
+ if (process.env.npm_config_user_agent) {
217
+ if (process.env.npm_config_user_agent.includes('pnpm')) return 'pnpm';
218
+ }
219
+ switch(null == pm ? void 0 : pm.name){
220
+ case 'yarn':
221
+ command = 'yarn';
222
+ break;
223
+ case 'pnpm':
224
+ command = 'pnpm';
225
+ break;
226
+ default:
227
+ command = 'npm';
228
+ }
229
+ return command;
230
+ }
231
+ function getTemplatePath(workingDir) {
232
+ const templatesDir = external_path_namespaceObject.resolve(utils_dirname, '..', 'template');
233
+ return external_path_namespaceObject.resolve(workingDir, templatesDir);
234
+ }
235
+ async function isDirectoryWriteable(directory, projectName) {
236
+ try {
237
+ console.log(folderExists(projectName));
238
+ await promises_namespaceObject.mkdir(directory, {
239
+ recursive: true
240
+ });
241
+ return true;
242
+ } catch (err) {
243
+ console.log(writingDirectoryError(err));
244
+ return false;
245
+ }
246
+ }
247
+ function isExternalTemplate(_templateName) {
248
+ return true;
249
+ }
250
+ function isTypeScriptTemplate(templateName) {
251
+ return templateName.includes("typescript") || templateName.includes('react') || templateName.includes('preact') || templateName.includes('svelte') || templateName.includes('solid');
252
+ }
253
+ const allowlist = [
254
+ 'LICENSE',
255
+ 'node_modules'
256
+ ];
257
+ async function createDirectory(projectPath, projectName) {
258
+ console.log(startingNewExtension(projectName));
259
+ try {
260
+ const isCurrentDirWriteable = await isDirectoryWriteable(projectPath, projectName);
261
+ console.log(checkingIfPathIsWriteable());
262
+ if (!isCurrentDirWriteable) {
263
+ console.error(destinationNotWriteable(projectPath));
264
+ throw new Error(destinationNotWriteable(projectPath));
265
+ }
266
+ const currentDir = await promises_namespaceObject.readdir(projectPath);
267
+ console.log(scanningPossiblyConflictingFiles());
268
+ const conflictingFiles = await Promise.all(currentDir.filter((file)=>!file.startsWith('.')).filter((file)=>!file.endsWith('.log')).filter((file)=>!allowlist.includes(file)).map(async (file)=>{
269
+ const stats = await promises_namespaceObject.lstat(external_path_namespaceObject.join(projectPath, file));
270
+ return stats.isDirectory() ? `${file}/` : `${file}`;
271
+ }));
272
+ if (conflictingFiles.length > 0) {
273
+ const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
274
+ throw new Error(conflictMessage);
275
+ }
276
+ } catch (error) {
277
+ console.error(createDirectoryError(projectName, error));
278
+ throw error;
279
+ }
280
+ }
281
+ const external_os_namespaceObject = require("os");
282
+ const external_axios_namespaceObject = require("axios");
283
+ var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
284
+ const external_adm_zip_namespaceObject = require("adm-zip");
285
+ var external_adm_zip_default = /*#__PURE__*/ __webpack_require__.n(external_adm_zip_namespaceObject);
286
+ const external_go_git_it_namespaceObject = require("go-git-it");
287
+ var external_go_git_it_default = /*#__PURE__*/ __webpack_require__.n(external_go_git_it_namespaceObject);
288
+ const import_external_template_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
289
+ const import_external_template_dirname = external_path_namespaceObject.dirname(import_external_template_filename);
290
+ async function importExternalTemplate(projectPath, projectName, template) {
291
+ external_path_namespaceObject.dirname(projectPath);
292
+ const templateName = external_path_namespaceObject.basename(template);
293
+ const examplesUrl = 'https://github.com/extension-js/examples/tree/main/examples';
294
+ const templateUrl = `${examplesUrl}/${template}`;
295
+ try {
296
+ await promises_namespaceObject.mkdir(projectPath, {
297
+ recursive: true
298
+ });
299
+ if ('development' === process.env.EXTENSION_ENV) {
300
+ console.log(installingFromTemplate(projectName, template));
301
+ const localTemplatePath = external_path_namespaceObject.join(import_external_template_dirname, '..', '..', '..', 'examples', templateName);
302
+ await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
303
+ } else {
304
+ const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
305
+ const tempPath = external_path_namespaceObject.join(tempRoot, projectName + '-temp');
306
+ await promises_namespaceObject.mkdir(tempPath, {
307
+ recursive: true
308
+ });
309
+ const isHttp = /^https?:\/\//i.test(template);
310
+ const isGithub = /^https?:\/\/github.com\//i.test(template);
311
+ if (isGithub) {
312
+ await external_go_git_it_default()(template, tempPath, installingFromTemplate(projectName, templateName));
313
+ const candidates = await promises_namespaceObject.readdir(tempPath, {
314
+ withFileTypes: true
315
+ });
316
+ const preferred = candidates.find((d)=>d.isDirectory() && d.name === templateName);
317
+ const srcPath = preferred ? external_path_namespaceObject.join(tempPath, templateName) : tempPath;
318
+ await moveDirectoryContents(srcPath, projectPath);
319
+ } else if (isHttp) {
320
+ const { data, headers } = await external_axios_default().get(template, {
321
+ responseType: 'arraybuffer',
322
+ maxRedirects: 5
323
+ });
324
+ const contentType = String((null == headers ? void 0 : headers['content-type']) || '');
325
+ const looksZip = /zip|octet-stream/i.test(contentType) || template.toLowerCase().endsWith('.zip');
326
+ if (!looksZip) throw new Error(`Remote template does not appear to be a ZIP archive: ${template}`);
327
+ const zip = new (external_adm_zip_default())(Buffer.from(data));
328
+ zip.extractAllTo(tempPath, true);
329
+ await moveDirectoryContents(tempPath, projectPath);
330
+ } else {
331
+ await external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName));
332
+ const srcPath = external_path_namespaceObject.join(tempPath, templateName);
333
+ await moveDirectoryContents(srcPath, projectPath);
334
+ }
335
+ await promises_namespaceObject.rm(tempRoot, {
336
+ recursive: true,
337
+ force: true
338
+ });
339
+ }
340
+ } catch (error) {
341
+ console.error(installingFromTemplateError(projectName, templateName, error));
342
+ throw error;
343
+ }
344
+ }
345
+ const extensionJsPackageJsonScripts = {
346
+ dev: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension dev' : 'extension dev',
347
+ start: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension start' : 'extension start',
348
+ build: 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build' : 'extension build'
349
+ };
350
+ async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
351
+ const templatePath = getTemplatePath(process.cwd());
352
+ const candidatePath = isExternalTemplate(template) ? external_path_namespaceObject.join(projectPath, 'package.json') : external_path_namespaceObject.join(templatePath, 'package.json');
353
+ let packageJson = {};
354
+ try {
355
+ const packageJsonContent = await promises_namespaceObject.readFile(candidatePath);
356
+ packageJson = JSON.parse(packageJsonContent.toString());
357
+ } catch {
358
+ packageJson = {
359
+ name: external_path_namespaceObject.basename(projectPath),
360
+ private: true,
361
+ scripts: {},
362
+ dependencies: {},
363
+ devDependencies: {}
364
+ };
365
+ }
366
+ packageJson.scripts = packageJson.scripts || {};
367
+ packageJson.dependencies = packageJson.dependencies || {};
368
+ packageJson.devDependencies = {
369
+ ...packageJson.devDependencies || {},
370
+ extension: 'development' === process.env.EXTENSION_ENV ? '*' : `^${cliVersion}`
371
+ };
372
+ const packageMetadata = {
373
+ ...packageJson,
374
+ name: external_path_namespaceObject.basename(projectPath),
375
+ private: true,
376
+ scripts: {
377
+ ...packageJson.scripts,
378
+ ...extensionJsPackageJsonScripts
379
+ },
380
+ dependencies: packageJson.dependencies,
381
+ devDependencies: packageJson.devDependencies,
382
+ author: {
383
+ name: 'Your Name',
384
+ email: 'your@email.com',
385
+ url: 'https://yourwebsite.com'
386
+ }
387
+ };
388
+ try {
389
+ console.log(writingPackageJsonMetadata());
390
+ await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'package.json'), JSON.stringify(packageMetadata, null, 2));
391
+ } catch (error) {
392
+ console.error(writingPackageJsonMetadataError(projectName, error));
393
+ throw error;
394
+ }
395
+ }
396
+ const external_cross_spawn_namespaceObject = require("cross-spawn");
397
+ function getInstallArgs() {
398
+ return [
399
+ 'install',
400
+ '--silent'
401
+ ];
402
+ }
403
+ async function installDependencies(projectPath, projectName) {
404
+ const nodeModulesPath = external_path_namespaceObject.join(projectPath, 'node_modules');
405
+ const command = await getInstallCommand();
406
+ const dependenciesArgs = getInstallArgs();
407
+ console.log(installingDependencies());
408
+ try {
409
+ await external_fs_namespaceObject.promises.mkdir(nodeModulesPath, {
410
+ recursive: true
411
+ });
412
+ const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
413
+ const child = (0, external_cross_spawn_namespaceObject.spawn)(command, dependenciesArgs, {
414
+ stdio,
415
+ cwd: projectPath
416
+ });
417
+ await new Promise((resolve, reject)=>{
418
+ child.on('close', (code)=>{
419
+ if (0 !== code) reject(new Error(installingDependenciesFailed(command, dependenciesArgs, code)));
420
+ else resolve();
421
+ });
422
+ child.on('error', (error)=>{
423
+ console.error(installingDependenciesProcessError(projectName, error));
424
+ reject(error);
425
+ });
426
+ });
427
+ } catch (error) {
428
+ console.error(cantInstallDependencies(projectName, error));
429
+ throw error;
430
+ }
431
+ }
432
+ async function writeReadmeFile(projectPath, projectName) {
433
+ try {
434
+ await promises_namespaceObject.access(external_path_namespaceObject.join(projectPath, 'README.md'));
435
+ return;
436
+ } catch {}
437
+ const initTemplateReadme = `
438
+ <a href="https://extension.js.org" target="_blank"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0971fe" alt="Powered by Extension.js" align="right" /></a>
439
+
440
+ # [projectName]
441
+
442
+ > [templateDescription]
443
+
444
+ What this example does in the scope of a browser extension. The description should
445
+ describe for an audience of developers looking to use the example. Avoid jargon and
446
+ use simple language.
447
+
448
+ ## Installation
449
+
450
+ \`\`\`bash
451
+ [runCommand] create <project-name> --template init
452
+ cd <project-name>
453
+ npm install
454
+ \`\`\`
455
+
456
+ ## Commands
457
+
458
+ ### dev
459
+
460
+ Run the extension in development mode.
461
+
462
+ \`\`\`bash
463
+ [runCommand] dev
464
+ \`\`\`
465
+
466
+ ### build
467
+
468
+ Build the extension for production.
469
+
470
+ \`\`\`bash
471
+ [runCommand] build
472
+ \`\`\`
473
+
474
+ ### Preview
475
+
476
+ Preview the extension in the browser.
477
+
478
+ \`\`\`bash
479
+ [runCommand] preview
480
+ \`\`\`
481
+
482
+ ## Learn more
483
+
484
+ Learn more about this and other examples at @https://extension.js.org/
485
+ `;
486
+ const installCommand = await getInstallCommand();
487
+ const manifestJsonPath = external_path_namespaceObject.join(projectPath, 'manifest.json');
488
+ const manifestJson = JSON.parse(await promises_namespaceObject.readFile(manifestJsonPath, 'utf-8'));
489
+ const readmeFileEdited = initTemplateReadme.replaceAll('[projectName]', projectName).replaceAll("[templateDescription]", manifestJson.description).replaceAll('[runCommand]', installCommand);
490
+ try {
491
+ console.log(writingReadmeMetaData());
492
+ await promises_namespaceObject.mkdir(projectPath, {
493
+ recursive: true
494
+ });
495
+ await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'README.md'), readmeFileEdited);
496
+ } catch (error) {
497
+ console.error(writingReadmeMetaDataEError(projectName, error));
498
+ throw error;
499
+ }
500
+ }
501
+ async function writeManifestJson(projectPath, projectName) {
502
+ const manifestJsonPath = external_path_namespaceObject.join(projectPath, 'manifest.json');
503
+ const manifestJsonContent = await promises_namespaceObject.readFile(manifestJsonPath);
504
+ const manifestJson = JSON.parse(manifestJsonContent.toString());
505
+ const manifestMetadata = {
506
+ ...manifestJson,
507
+ name: external_path_namespaceObject.basename(projectPath),
508
+ author: 'Your Name'
509
+ };
510
+ try {
511
+ console.log(writingManifestJsonMetadata());
512
+ await promises_namespaceObject.writeFile(external_path_namespaceObject.join(projectPath, 'manifest.json'), JSON.stringify(manifestMetadata, null, 2));
513
+ } catch (error) {
514
+ console.error(writingManifestJsonMetadataError(projectName, error));
515
+ throw error;
516
+ }
517
+ }
518
+ async function generateExtensionTypes(projectPath, projectName) {
519
+ const extensionEnvFile = external_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
520
+ const typePath = 'extension';
521
+ const fileContent = `\
522
+ // Required Extension.js types for TypeScript projects.
30
523
  // This file is auto-generated and should not be excluded.
31
524
  // If you need additional types, consider creating a new *.d.ts file and
32
525
  // referencing it in the "include" array of your tsconfig.json file.
33
526
  // See https://www.typescriptlang.org/tsconfig#include for more information.
34
- /// <reference types="${s}/index.d.ts" />
527
+ /// <reference types="${typePath}/types" />
35
528
 
36
- // 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});
529
+ // Polyfill types for browser.* APIs
530
+ /// <reference types="${typePath}/types/polyfill" />
531
+ `;
532
+ try {
533
+ await promises_namespaceObject.mkdir(projectPath, {
534
+ recursive: true
535
+ });
536
+ console.log(writingTypeDefinitions(projectName));
537
+ await promises_namespaceObject.writeFile(extensionEnvFile, fileContent);
538
+ } catch (error) {
539
+ console.error(writingTypeDefinitionsError(error));
540
+ throw error;
541
+ }
542
+ }
543
+ const globalDependencies = [
544
+ '',
545
+ '# dependencies',
546
+ 'node_modules'
547
+ ];
548
+ const globalTesting = [
549
+ '',
550
+ '# testing',
551
+ 'coverage'
552
+ ];
553
+ const globalProduction = [
554
+ '',
555
+ '# production',
556
+ 'dist'
557
+ ];
558
+ const globalMisc = [
559
+ '',
560
+ '# misc',
561
+ '.DS_Store'
562
+ ];
563
+ const envFiles = [
564
+ '',
565
+ '# local env files',
566
+ '.env.local',
567
+ '.env.development.local',
568
+ '.env.test.local',
569
+ '.env.production.local'
570
+ ];
571
+ const debugFiles = [
572
+ '',
573
+ '# debug files',
574
+ 'npm-debug.log*',
575
+ 'yarn-debug.log*',
576
+ 'yarn-error.log*'
577
+ ];
578
+ const globalLines = [
579
+ '# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.',
580
+ ...globalDependencies,
581
+ ...globalTesting,
582
+ ...globalProduction,
583
+ ...globalMisc,
584
+ ...envFiles,
585
+ ...debugFiles
586
+ ];
587
+ async function writeGitignore(projectPath) {
588
+ const gitIgnorePath = external_path_namespaceObject.join(projectPath, '.gitignore');
589
+ const fileHandle = await promises_namespaceObject.open(gitIgnorePath, 'a+').catch((err)=>{
590
+ console.error(err);
591
+ throw err;
592
+ });
593
+ const paths = new Set();
594
+ for await (let line of fileHandle.readLines({
595
+ autoClose: false
596
+ })){
597
+ line = line.trim();
598
+ if (0 !== line.length) paths.add(line);
599
+ }
600
+ const linesToAdd = globalLines.filter((line)=>!paths.has(line));
601
+ while('' === linesToAdd[linesToAdd.length - 1])linesToAdd.pop();
602
+ console.log(writingGitIgnore());
603
+ await fileHandle.appendFile(linesToAdd.join('\n')).catch((err)=>{
604
+ console.error(err);
605
+ throw err;
606
+ });
607
+ }
608
+ async function initializeGitRepository(projectPath, projectName) {
609
+ const gitCommand = 'git';
610
+ const gitArgs = [
611
+ 'init',
612
+ '--quiet'
613
+ ];
614
+ console.log(initializingGitForRepository(projectName));
615
+ try {
616
+ const stdio = 'development' === process.env.EXTENSION_ENV ? 'inherit' : 'ignore';
617
+ const child = (0, external_cross_spawn_namespaceObject.spawn)(gitCommand, gitArgs, {
618
+ stdio,
619
+ cwd: projectPath
620
+ });
621
+ await new Promise((resolve, reject)=>{
622
+ child.on('close', (code)=>{
623
+ if (0 !== code) reject(new Error(initializingGitForRepositoryFailed(gitCommand, gitArgs, code)));
624
+ else resolve();
625
+ });
626
+ child.on('error', (error)=>{
627
+ console.error(initializingGitForRepositoryProcessError(projectName, error));
628
+ reject(error);
629
+ });
630
+ });
631
+ } catch (error) {
632
+ console.error(initializingGitForRepositoryError(projectName, error));
633
+ throw error;
634
+ }
635
+ }
636
+ async function setupBuiltInTests(projectPath, projectName) {
637
+ try {
638
+ const testSpecPath = external_path_namespaceObject.join(projectPath, 'tests', 'templates.spec.ts');
639
+ if (external_fs_namespaceObject.existsSync(testSpecPath)) external_fs_namespaceObject.unlinkSync(testSpecPath);
640
+ } catch (error) {
641
+ console.error(cantSetupBuiltInTests(projectName, error));
642
+ throw error;
643
+ }
644
+ }
645
+ async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = false }) {
646
+ if (!projectNameInput) throw new Error(noProjectName());
647
+ if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
648
+ const projectPath = external_path_namespaceObject.isAbsolute(projectNameInput) ? projectNameInput : external_path_namespaceObject.join(process.cwd(), projectNameInput);
649
+ const projectName = external_path_namespaceObject.basename(projectPath);
650
+ try {
651
+ await createDirectory(projectPath, projectName);
652
+ await importExternalTemplate(projectPath, projectName, template);
653
+ await overridePackageJson(projectPath, projectName, {
654
+ template,
655
+ cliVersion
656
+ });
657
+ if (install) await installDependencies(projectPath, projectName);
658
+ await writeReadmeFile(projectPath, projectName);
659
+ await writeManifestJson(projectPath, projectName);
660
+ await initializeGitRepository(projectPath, projectName);
661
+ await writeGitignore(projectPath);
662
+ await setupBuiltInTests(projectPath, projectName);
663
+ if (isTypeScriptTemplate(template)) await generateExtensionTypes(projectPath, projectName);
664
+ const successfulInstall = await successfullInstall(projectPath, projectName);
665
+ console.log(successfulInstall);
666
+ } catch (error) {
667
+ console.error(error);
668
+ throw error;
669
+ }
670
+ }
671
+ exports.extensionCreate = __webpack_exports__.extensionCreate;
672
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
673
+ "extensionCreate"
674
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
675
+ Object.defineProperty(exports, '__esModule', {
676
+ value: true
677
+ });
@@ -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>;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
package/package.json CHANGED
@@ -8,42 +8,78 @@
8
8
  "engines": {
9
9
  "node": ">=18"
10
10
  },
11
- "name": "extension-create",
12
- "version": "2.0.0",
13
- "description": "The Extension.js create step",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/module.d.ts",
14
+ "import": "./dist/module.js",
15
+ "require": "./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.1.1",
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
  },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "registry": "https://registry.npmjs.org",
34
+ "tag": "latest"
35
+ },
36
+ "keywords": [
37
+ "webextension",
38
+ "browser-extension",
39
+ "manifest-v3",
40
+ "mv3",
41
+ "cross-browser",
42
+ "scaffold",
43
+ "generator",
44
+ "project-generator",
45
+ "create-extension",
46
+ "create-browser-extension",
47
+ "starter-template",
48
+ "template",
49
+ "templates",
50
+ "starter-kit",
51
+ "boilerplate",
52
+ "init",
53
+ "bootstrap",
54
+ "chrome-extension",
55
+ "firefox-extension",
56
+ "edge-extension"
57
+ ],
24
58
  "dependencies": {
25
- "@colors/colors": "^1.6.0",
26
- "@types/firefox-webext-browser": "^120.0.4",
59
+ "adm-zip": "^0.5.12",
60
+ "axios": "^1.7.2",
27
61
  "cross-spawn": "^7.0.6",
28
- "go-git-it": "2.0.4",
29
- "package-manager-detector": "^0.2.7"
62
+ "go-git-it": "^5.0.0",
63
+ "package-manager-detector": "^0.2.7",
64
+ "pintor": "0.3.0",
65
+ "tiny-glob": "^0.2.9"
30
66
  },
31
67
  "devDependencies": {
68
+ "@rslib/core": "^0.6.9",
32
69
  "@types/cross-spawn": "^6.0.6",
33
70
  "@types/node": "^22.10.1",
34
- "@types/react-dom": "^19.0.1",
71
+ "@vitest/coverage-v8": "3.2.2",
35
72
  "globals": "^15.13.0",
36
- "jest": "^29.7.0",
37
- "ts-jest": "^29.2.5",
38
73
  "tsconfig": "*",
39
- "tsup": "^8.3.5",
40
- "typescript": "5.7.2"
74
+ "typescript": "5.7.2",
75
+ "vitest": "3.2.2"
41
76
  },
42
77
  "scripts": {
43
78
  "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"
79
+ "watch": "rslib build --watch",
80
+ "compile": "rslib build",
81
+ "pretest:create": "pnpm compile",
82
+ "test:create": "vitest run",
83
+ "test:coverage": "vitest run --coverage"
48
84
  }
49
85
  }
@@ -1,35 +0,0 @@
1
- # [projectName]
2
-
3
- > [templateDescription]
4
-
5
- ## Available Scripts
6
-
7
- In the project directory, you can run the following scripts:
8
-
9
- ### [runCommand] dev
10
-
11
- **Development Mode**: This command runs your extension in development mode. It will launch a new browser instance with your extension loaded. The page will automatically reload whenever you make changes to your code, allowing for a smooth development experience.
12
-
13
- ```bash
14
- [runCommand] dev
15
- ```
16
-
17
- ### [runCommand] start
18
-
19
- **Production Preview**: This command runs your extension in production mode. It will launch a new browser instance with your extension loaded, simulating the environment and behavior of your extension as it will appear once published.
20
-
21
- ```bash
22
- [runCommand] start
23
- ```
24
-
25
- ### [runCommand] build
26
-
27
- **Build for Production**: This command builds your extension for production. It optimizes and bundles your extension, preparing it for deployment to the target browser's store.
28
-
29
- ```bash
30
- [runCommand] build
31
- ```
32
-
33
- ## Learn More
34
-
35
- To learn more about creating cross-browser extensions with Extension.js, visit the [official documentation](https://extension.js.org).
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/chrome-manifest.json",
3
- "manifest_version": 3,
4
- "version": "1.0",
5
- "name": "Default Extension",
6
- "description": "A minimum extension template. This template includes a manifest file."
7
- }
@@ -1,17 +0,0 @@
1
- {
2
- "license": "MIT",
3
- "repository": {
4
- "type": "git",
5
- "url": "https://github.com/extension-js/extension.git",
6
- "directory": "examples/init"
7
- },
8
- "name": "init",
9
- "description": "An Extension.js example.",
10
- "version": "0.0.1",
11
- "keywords": [
12
- "extension",
13
- "browser-extension",
14
- "web-extension",
15
- "template"
16
- ]
17
- }