extension-create 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +1 -1
- package/dist/module.d.ts +2 -2
- package/dist/module.js +17 -16
- package/dist/template/README.md +13 -15
- package/package.json +11 -10
package/README.md
CHANGED
package/dist/module.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface CreateOptions {
|
|
2
2
|
template: string;
|
|
3
|
-
|
|
3
|
+
install?: boolean;
|
|
4
4
|
}
|
|
5
|
-
declare function extensionCreate(projectNameInput: string | undefined, { template,
|
|
5
|
+
declare function extensionCreate(projectNameInput: string | undefined, { template, install }: CreateOptions): Promise<void>;
|
|
6
6
|
|
|
7
7
|
export { type CreateOptions, extensionCreate };
|
package/dist/module.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var je=Object.create;var $=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var Xe=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var Ue=(e,n)=>{for(var t in n)$(e,t,{get:n[t],enumerable:!0})},N=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of Ve(n))!Le.call(e,i)&&i!==t&&$(e,i,{get:()=>n[i],enumerable:!(o=ze(n,i))||o.enumerable});return e};var c=(e,n,t)=>(t=e!=null?je(Xe(e)):{},N(n||!e||!e.__esModule?$(t,"default",{value:e,enumerable:!0}):t,e)),Ye=e=>N($({},"__esModule",{value:!0}),e);var cn={};Ue(cn,{extensionCreate:()=>an});module.exports=Ye(cn);var _=c(require("path"));var w=c(require("path")),r=require("@colors/colors/safe"),G=c(require("fs/promises")),A=require("detect-package-manager");function O(e){let n=w.default.basename(e);return`Failed to write in the destination directory. Path for \`${n}\` is not writable.
|
|
2
2
|
Ensure you have write permissions for this folder.
|
|
3
|
-
Path: ${
|
|
4
|
-
Conflict! Path to ${(0,r.cyan)(
|
|
3
|
+
Path: ${n}`}async function W(e,n){let t=w.default.basename(e),o=`
|
|
4
|
+
Conflict! Path to ${(0,r.cyan)(t)} includes conflicting files:
|
|
5
5
|
|
|
6
|
-
`;for(let
|
|
7
|
-
`:`${(0,r.gray)("-")} ${(0,r.brightYellow)(
|
|
8
|
-
`}return
|
|
6
|
+
`;for(let i of n){let s=await G.default.lstat(w.default.join(e,i));o+=s.isDirectory()?`${(0,r.gray)("-")} ${(0,r.brightYellow)(i)}
|
|
7
|
+
`:`${(0,r.gray)("-")} ${(0,r.brightYellow)(i)}
|
|
8
|
+
`}return o+=`
|
|
9
9
|
You need to either rename/remove the files listed above, or choose a new directory name for your extension.
|
|
10
10
|
|
|
11
|
-
Path to conflicting directory: ${(0,r.underline)(e)}`,
|
|
11
|
+
Path to conflicting directory: ${(0,r.underline)(e)}`,o}function j(){return"You need to provide an extension name to create one. \nSee `--help` for command info."}function z(){return"URLs are not allowed as a project path. Either write a name or a path to a local folder."}async function V(e,n){let t=w.default.relative(process.cwd(),e),o=await(0,A.detect)(),i="npm run";switch(o){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,r.brightGreen)("Success!")} Extension ${(0,r.cyan)(n)} created.
|
|
12
12
|
|
|
13
|
-
Now ${(0,r.brightBlue)(`cd ${(0,r.underline)(
|
|
13
|
+
Now ${(0,r.brightBlue)(`cd ${(0,r.underline)(t)}`)} and ${(0,r.brightBlue)(`${i}`)} to open a new browser instance
|
|
14
14
|
with your extension installed, loaded, and enabled for development.
|
|
15
15
|
|
|
16
|
-
${(0,r.brightGreen)("You are ready")}. Time to hack on your extension!`}function
|
|
17
|
-
// This file auto-generated and should not be excluded.
|
|
18
|
-
// If you need
|
|
19
|
-
// referencing it in the "include" array
|
|
20
|
-
// See https://www.typescriptlang.org/tsconfig#include for
|
|
21
|
-
/// <reference types="${
|
|
16
|
+
${(0,r.brightGreen)("You are ready")}. Time to hack on your extension!`}function X(e){return`\u{1F423} - Starting a new browser extension named ${(0,r.cyan)(e)}...`}function L(){return"\u{1F91E} - Checking if destination path is writeable..."}function U(){return"\u{1F50E} - Scanning for potential conflicting files..."}function Y(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't create directory ${(0,r.cyan)(e)}. ${n}`}function q(e){return`\u{1F537} - Writing ${(0,r.cyan)(e)} type definitions...`}function H(e){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write the extension type definition. ${e}`}function y(e,n){return n==="init"?`\u{1F9F0} - Installing ${(0,r.cyan)(e)}...`:`\u{1F9F0} - Installing ${(0,r.cyan)(e)} from template ${(0,r.brightBlue)(n)}...`}function v(e,n,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't find template ${(0,r.brightBlue)(n)} for ${(0,r.cyan)(e)}. ${t}`}function B(e){return`\u{1F332} - Initializing git repository for ${(0,r.cyan)(e)}...`}function K(e,n,t){return`Command ${e} ${n.join(" ")} failed with exit code ${t}`}function Q(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't initialize ${(0,r.brightYellow)("git")} for ${(0,r.cyan)(e)}. ${n.message}`}function Z(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't initialize ${(0,r.brightYellow)("git")} for ${(0,r.cyan)(e)}. ${n.message||n.toString()}`}function ee(){return"\u{1F6E0} - Installing dependencies... (takes a moment)"}function ne(e,n,t){return`Command ${e} ${n.join(" ")} failed with exit code ${t}`}function te(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't install dependencies for ${(0,r.cyan)(e)}. ${n}`}function ie(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't install dependencies for ${(0,r.cyan)(e)}. ${n.message||n.toString()}`}function re(){return"Symlink created successfully."}function oe(e,n){return`Failed to create symlink: ${e} ${n.join(" ")}`}function se(){return`\u{1F4DD} - Writing ${(0,r.brightYellow)("package.json")} metadata...`}function ae(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,r.brightYellow)("package.json")} for ${(0,r.cyan)(e)}. ${n}`}function ce(){return`\u{1F4DC} - Writing ${(0,r.brightYellow)("manifest.json")} metadata...`}function le(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,r.brightYellow)("manifest.json")} for ${(0,r.cyan)(e)}. ${n}`}function me(){return`\u{1F4C4} - Writing ${(0,r.brightYellow)("README.md")} metadata...`}function pe(){return`\u{1F648} - Writing ${(0,r.brightYellow)(".gitignore")} lines...`}function ge(e,n){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write the ${(0,r.brightYellow)("README.md")} file for ${(0,r.cyan)(e)}. ${n}`}function de(e){return`\u{1F91D} - Ensuring ${(0,r.cyan)(e)} folder exists...`}function fe(e){return"Error while checking directory writability: "+e}var x=c(require("fs/promises")),h=c(require("path")),ue=require("detect-package-manager");async function C(e,n){let t=await x.default.readdir(e,{withFileTypes:!0});return await x.default.mkdir(n,{recursive:!0}),await Promise.all(t.map(async o=>{let i=h.default.join(e,o.name),s=h.default.join(n,o.name);o.isDirectory()?await C(i,s):await x.default.copyFile(i,s)}))}async function f(){let e=await(0,ue.detect)(),n="npm";if(process.env.npm_config_user_agent&&process.env.npm_config_user_agent.includes("pnpm"))return"pnpm";switch(e){case"yarn":n="yarn";break;case"pnpm":n="pnpm";break;default:n="npm"}return n}function we(e){let n=h.default.resolve(__dirname,"template");return h.default.resolve(e,n)}async function ye(e,n){try{return console.log(de(n)),await x.default.mkdir(e,{recursive:!0}),!0}catch(t){return console.log(fe(t)),!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=c(require("path")),S=c(require("fs/promises"));var qe=["LICENSE","node_modules"];async function $e(e,n){console.log(X(n));try{let t=await ye(e,n);console.log(L()),t||(console.error(O(e)),process.exit(1));let o=await S.default.readdir(e);console.log(U());let i=await Promise.all(o.filter(s=>!s.startsWith(".")).filter(s=>!s.endsWith(".log")).filter(s=>!qe.includes(s)).map(async s=>(await S.default.lstat(Ee.default.join(e,s))).isDirectory()?`${s}/`:`${s}`));if(i.length>0){let s=await W(e,i);throw new Error(s)}}catch(t){console.error(Y(n,t)),process.exit(1)}}var ve=c(require("path"));async function be(e,n,t){let o=ve.default.resolve(__dirname,"template");try{console.log(y(n,t)),await C(o,e)}catch(i){console.error(v(n,t,i)),process.exit(1)}}var b=c(require("path")),k=c(require("fs/promises")),ke=c(require("go-git-it"));async function De(e,n,t){let o=b.default.dirname(e),s=`https://github.com/extension-js/extension.js/tree/main/examples/${t}`;try{if(await k.default.mkdir(e,{recursive:!0}),process.env.EXTENSION_ENV==="development"){console.log(y(n,t));let a=b.default.join(__dirname,"..","..","..","examples",t);await k.default.cp(a,e,{recursive:!0})}else await(0,ke.default)(s,o,y(n,t)),await k.default.rename(b.default.join(o,t),e)}catch(a){console.error(v(n,t,a)),process.exit(1)}}var E=c(require("path")),I=c(require("fs/promises"));var He={dev:process.env.EXTENSION_ENV==="development"?"node node_modules/extension dev":"extension dev",start:process.env.EXTENSION_ENV==="development"?"node node_modules/extension start":"extension start",build:process.env.EXTENSION_ENV==="development"?"node node_modules/extension build":"extension build"};async function Fe(e,n,t){let o=we(process.cwd()),i=xe(t)?E.default.join(e,"package.json"):E.default.join(o,"package.json"),s=await I.default.readFile(i),a=JSON.parse(s.toString());a.scripts=a.scripts||{},a.dependencies=a.dependencies||{},a.devDependencies={...a.devDependencies||{},extension:process.env.EXTENSION_ENV==="development"?"*":"latest"};let g={...a,name:E.default.basename(e),private:!0,scripts:{...a.scripts,...He},dependencies:a.dependencies,devDependencies:a.devDependencies,author:{name:"Your Name",email:"your@email.com",url:"https://yourwebsite.com"}};try{console.log(se()),await I.default.writeFile(E.default.join(e,"package.json"),JSON.stringify(g,null,2))}catch(m){console.error(ae(n,m)),process.exit(1)}}var Ce=c(require("path")),Se=require("cross-spawn"),Ie=c(require("fs"));var Te=c(require("path")),J=require("cross-spawn");async function _e(e){let n=Te.default.join(__dirname,"../../cli"),t=await f(),o=["link"];await new Promise((i,s)=>{(0,J.spawn)(t,o,{cwd:n}).on("close",()=>{(0,J.spawn)(t,[...o,"extension"],{stdio:"inherit",cwd:e}).on("close",m=>{m===0?(console.log(re()),i()):s(new Error(oe(t,o)))})})}),console.log("Symlink creation completed.")}function Be(){return["install","--silent"]}async function Je(e,n){let t=Ce.default.join(e,"node_modules"),o=await f(),i=Be();console.log(ee()),process.env.EXTENSION_ENV==="development"&&await _e(e);try{let s=process.cwd();process.chdir(e),await Ie.default.promises.mkdir(t,{recursive:!0});let a=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",g=(0,Se.spawn)(o,i,{stdio:a});await new Promise((m,p)=>{g.on("close",u=>{process.chdir(s),u!==0?p(new Error(ne(o,i,u))):m()}),g.on("error",u=>{process.chdir(s),console.error(te(n,u)),p(u)})})}catch(s){console.error(ie(n,s)),process.exit(1)}}var D=c(require("path")),F=c(require("fs/promises"));async function Pe(e,n){let t=await F.default.readFile(D.default.join(__dirname,"template","README.md"),"utf-8"),o=await f(),i=require(D.default.join(e,"manifest.json")),s=t.replaceAll("[projectName]",n).replaceAll("[templateDescription]",i.description).replaceAll("[runCommand]",o);try{console.log(me()),await F.default.mkdir(e,{recursive:!0}),await F.default.writeFile(D.default.join(e,"README.md"),s)}catch(a){console.error(ge(n,a)),process.exit(1)}}var T=c(require("path")),P=c(require("fs/promises"));async function Me(e,n){let t=T.default.join(e,"manifest.json"),o=await P.default.readFile(t),s={...JSON.parse(o.toString()),name:T.default.basename(e),author:"Your Name"};try{console.log(ce()),await P.default.writeFile(T.default.join(e,"manifest.json"),JSON.stringify(s,null,2))}catch(a){console.error(le(n,a)),process.exit(1)}}var M=c(require("path")),R=c(require("fs/promises"));async function Re(e,n){let t=M.default.join(e,"extension-env.d.ts"),o=process.env.EXTENSION_ENV==="development"?M.default.resolve(process.cwd(),"programs/cli/types"):"./node_modules/extension/dist/types",i=`// Required Extension.js types for TypeScript projects.
|
|
17
|
+
// This file is auto-generated and should not be excluded.
|
|
18
|
+
// If you need additional types, consider creating a new *.d.ts file and
|
|
19
|
+
// referencing it in the "include" array of your tsconfig.json file.
|
|
20
|
+
// See https://www.typescriptlang.org/tsconfig#include for more information.
|
|
21
|
+
/// <reference types="${o}/index.d.ts" />
|
|
22
22
|
|
|
23
23
|
// Polyfill types for browser.* APIs.
|
|
24
|
-
/// <reference types="${
|
|
25
|
-
`;try{await R.default.mkdir(e,{recursive:!0}),console.log(
|
|
24
|
+
/// <reference types="${o}/polyfill.d.ts" />
|
|
25
|
+
`;try{await R.default.mkdir(e,{recursive:!0}),console.log(q(n)),await R.default.writeFile(t,i)}catch(s){console.error(H(s)),process.exit(1)}}var Ne=c(require("fs/promises")),Ge=c(require("path"));var Ke=["","# dependencies","node_modules"],Qe=["","# testing","coverage"],Ze=["","# production","dist"],en=["","# misc",".DS_Store"],nn=["","# local env files",".env.local",".env.development.local",".env.test.local",".env.production.local"],tn=["","# debug files","npm-debug.log*","yarn-debug.log*","yarn-error.log*"],rn=["","# lock files","yarn.lock","package-lock.json"],on=["","# extension.js","extension-env.d.ts"],sn=["# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.",...Ke,...Qe,...Ze,...en,...nn,...rn,...tn,...on];async function Ae(e){let n=Ge.default.join(e,".gitignore"),t=await Ne.default.open(n,"a+").catch(s=>{console.error(s),process.exit(1)}),o=new Set;for await(let s of t.readLines({autoClose:!1}))s=s.trim(),s.length!==0&&o.add(s);let i=sn.filter(s=>!o.has(s));for(;i[i.length-1]==="";)i.pop();console.log(pe()),await t.appendFile(i.join(`
|
|
26
|
+
`),{flush:!0}).catch(s=>{console.error(s),process.exit(1)})}var Oe=require("cross-spawn");async function We(e,n){let t="git",o=["init","--quiet"];console.log(B(n));try{let i=process.cwd();process.chdir(e);let s=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",a=(0,Oe.spawn)(t,o,{stdio:s});await new Promise((g,m)=>{a.on("close",p=>{process.chdir(i),p!==0?m(new Error(K(t,o,p))):g()}),a.on("error",p=>{process.chdir(i),console.error(Q(n,p)),m(p)})})}catch(i){console.error(Z(n,i)),process.exit(1)}}async function an(e,{template:n="init",install:t=!0}){if(!e)throw new Error(j());if(e.startsWith("http"))throw new Error(z());let o=_.default.isAbsolute(e)?e:_.default.join(process.cwd(),e),i=_.default.basename(o);try{await $e(o,i),n==="init"?await be(o,i,n):await De(o,i,n),await Fe(o,i,n),t&&await Je(o,i),await Pe(o,i),await Me(o,i),await We(o,i),await Ae(o),he(n)&&await Re(o,i);let s=await V(o,i);console.log(s)}catch(s){throw console.error(s),s}}0&&(module.exports={extensionCreate});
|
package/dist/template/README.md
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
# [
|
|
1
|
+
# [templateName]
|
|
2
2
|
|
|
3
3
|
> [templateDescription]
|
|
4
4
|
|
|
5
|
-
## Scripts
|
|
5
|
+
## Available Scripts
|
|
6
6
|
|
|
7
|
-
In the project directory, you can run:
|
|
7
|
+
In the project directory, you can run the following scripts:
|
|
8
8
|
|
|
9
9
|
### [runCommand] dev
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// The page will reload when you make changes.
|
|
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
|
|
15
14
|
[runCommand] dev
|
|
16
15
|
```
|
|
17
16
|
|
|
18
17
|
### [runCommand] start
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// This is how your browser extension will work once published.
|
|
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
|
|
24
22
|
[runCommand] start
|
|
25
23
|
```
|
|
26
24
|
|
|
27
25
|
### [runCommand] build
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
32
30
|
[runCommand] build
|
|
33
31
|
```
|
|
34
32
|
|
|
35
33
|
## Learn More
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
To learn more about creating cross-browser extensions with Extension.js, visit the [official documentation](https://extension.js.org).
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
11
|
"name": "extension-create",
|
|
12
|
-
"version": "2.0.0-alpha.
|
|
12
|
+
"version": "2.0.0-alpha.21",
|
|
13
13
|
"description": "The Extension.js create step",
|
|
14
14
|
"main": "./dist/module.js",
|
|
15
15
|
"types": "./dist/module.d.ts",
|
|
@@ -21,21 +21,15 @@
|
|
|
21
21
|
"email": "boss@cezaraugusto.net",
|
|
22
22
|
"url": "https://cezaraugusto.com"
|
|
23
23
|
},
|
|
24
|
-
"scripts": {
|
|
25
|
-
"clean": "rm -rf dist",
|
|
26
|
-
"watch": "yarn compile --watch",
|
|
27
|
-
"compile": "tsup-node ./module.ts --format cjs --dts --target=node18 --minify && bash install_scripts.sh",
|
|
28
|
-
"test": "echo \"Note: no test specified\" && exit 0",
|
|
29
|
-
"test:create": "jest ./create.spec.ts --no-cache"
|
|
30
|
-
},
|
|
31
24
|
"dependencies": {
|
|
32
25
|
"@colors/colors": "^1.6.0",
|
|
33
26
|
"cross-spawn": "^7.0.3",
|
|
34
27
|
"detect-package-manager": "^3.0.2",
|
|
35
|
-
"go-git-it": "
|
|
28
|
+
"go-git-it": "2.0.4"
|
|
36
29
|
},
|
|
37
30
|
"devDependencies": {
|
|
38
31
|
"@types/cross-spawn": "^6.0.6",
|
|
32
|
+
"@types/node": "^22.5.3",
|
|
39
33
|
"@types/react-dom": "^18.2.18",
|
|
40
34
|
"globals": "^15.9.0",
|
|
41
35
|
"jest": "^29.7.0",
|
|
@@ -43,5 +37,12 @@
|
|
|
43
37
|
"tsconfig": "*",
|
|
44
38
|
"tsup": "^8.0.1",
|
|
45
39
|
"typescript": "5.3.3"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"clean": "rm -rf dist",
|
|
43
|
+
"watch": "tsup-node ./module.ts --format cjs --dts --target=node18 --watch",
|
|
44
|
+
"compile": "tsup-node ./module.ts --format cjs --dts --target=node18 --minify && bash install_scripts.sh",
|
|
45
|
+
"test": "echo \"Note: no test specified\" && exit 0",
|
|
46
|
+
"test:create": "jest ./create.spec.ts --no-cache"
|
|
46
47
|
}
|
|
47
|
-
}
|
|
48
|
+
}
|