extension-create 1.3.0 → 2.0.0-alpha.0
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 +16 -92
- package/dist/module.d.ts +7 -0
- package/dist/module.js +25 -0
- package/dist/template/README.md +37 -0
- package/dist/template/manifest.json +6 -0
- package/dist/template/package.json +17 -0
- package/package.json +16 -39
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -311
- package/dist/stylelint.config.js +0 -7
- package/dist/tailwind.config.js +0 -25
package/README.md
CHANGED
|
@@ -1,106 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
[action-url]: https://github.com/cezaraugusto/extension-create/actions
|
|
3
|
-
[npm-image]: https://img.shields.io/npm/v/extension-create.svg
|
|
4
|
-
[npm-url]: https://npmjs.org/package/extension-create
|
|
5
|
-
[downloads-image]: https://img.shields.io/npm/dm/extension-create.svg
|
|
6
|
-
[downloads-url]: https://npmjs.org/package/extension-create
|
|
7
|
-
[node]: https://img.shields.io/node/v/extension-create.svg
|
|
8
|
-
[node-url]: https://nodejs.org
|
|
9
|
-
[prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
|
|
10
|
-
[prs-url]: https://github.com/cezaraugusto/extension-create/blob/main/CONTRIBUTING.md
|
|
11
|
-
[vunlerabilities]: https://snyk.io/test/github/cezaraugusto/extension-create/badge.svg
|
|
12
|
-
[fossa-image]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcezaraugusto%2Fextension-create.svg?type=shield
|
|
13
|
-
[fossa-url]: https://app.fossa.com/projects/git%2Bgithub.com%2Fcezaraugusto%2Fextension-create?ref=badge_large
|
|
1
|
+
# @extension/create
|
|
14
2
|
|
|
15
|
-
|
|
3
|
+
> The **create** part of [Extension.js](https://github.com/cezaraugusto/extension). Available as a standalone package.
|
|
16
4
|
|
|
17
|
-
|
|
5
|
+
This package stores all logic needed by Extension.js to create new projects.
|
|
18
6
|
|
|
19
|
-
|
|
7
|
+
## Installation
|
|
20
8
|
|
|
21
|
-
- [Creating an extension](#creating-an-extension) — How to create a new extension.
|
|
22
|
-
- [Getting started immediately](#getting-started-immediately) — Get work done in no time.
|
|
23
|
-
- [I have an extension](#i-have-an-extension) - Use only specific parts of `extension-create`.
|
|
24
|
-
|
|
25
|
-
`extension-create` helps you develop cross-browser extensions with built-in support for module imports/exports, auto-reload, and more.
|
|
26
|
-
|
|
27
|
-
## Creating an Extension
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
npx extension-create@latest create my-extension-hello
|
|
31
|
-
cd my-extension-hello
|
|
32
|
-
npm run dev
|
|
33
9
|
```
|
|
34
|
-
|
|
35
|
-
A new browser instance will open up with your extension ready for development.
|
|
36
|
-
|
|
37
|
-
You are done. Time to hack on your extension!
|
|
38
|
-
|
|
39
|
-
<p align="center">
|
|
40
|
-
<img src="https://user-images.githubusercontent.com/4672033/106184765-ba0c2b80-6180-11eb-9d0f-d9d00d168290.gif" width="720" alt="npm start">
|
|
41
|
-
</p>
|
|
42
|
-
|
|
43
|
-
## Getting Started Immediately
|
|
44
|
-
|
|
45
|
-
### Kickstart any sample from Chrome Extension Samples
|
|
46
|
-
|
|
47
|
-
The [chrome-extensions-sample](https://github.com/GoogleChrome/chrome-extensions-samples/) project is a great way to kickstart developing your extension.
|
|
48
|
-
|
|
49
|
-
If we go to the samples repository and look for an extension sample to work, let's say the [page-redder](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder) sample, all we need is to copy and paste it's URL as an argument for the start command:
|
|
50
|
-
|
|
51
|
-
#### Command
|
|
52
|
-
|
|
53
|
-
```sh
|
|
54
|
-
# This command will:
|
|
55
|
-
# 1. Download the Chrome extension sample URL to the current working directory
|
|
56
|
-
# 2. Bundle the downloaded extension using extension-create
|
|
57
|
-
# 3. Enable the extension in Chrome using a fresh user profile
|
|
58
|
-
npx extension-create dev https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder
|
|
10
|
+
yarn add @extension-create/create
|
|
59
11
|
```
|
|
60
12
|
|
|
61
|
-
|
|
62
|
-
<img src="https://user-images.githubusercontent.com/4672033/106188671-04dc7200-6186-11eb-940a-52aebab46f31.gif" width="720" alt="npm start">
|
|
63
|
-
</p>
|
|
64
|
-
|
|
65
|
-
Will not only download the extension but also kickstart a Chrome instance in a fresh profile with your sample extension loaded and default auto-reload support. Try it yourself!
|
|
66
|
-
|
|
67
|
-
### Use `Microsoft Edge` to kickstart any sample from [chrome-extesions-sample](https://github.com/GoogleChrome/chrome-extensions-samples/)
|
|
68
|
-
|
|
69
|
-
**You read it!** Just run the command above with the `--browser=edge` flag:
|
|
70
|
-
|
|
71
|
-
```sh
|
|
72
|
-
npx extension-create dev --browser=edge https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/functional-samples/sample.page-redder
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
And see a Chrome Extension sample running automatically. On Edge!
|
|
76
|
-
|
|
77
|
-
## I have an extension
|
|
78
|
-
|
|
79
|
-
Just add `extension-create` to your npm scripts. Here's how it should look in your `package.json`:
|
|
13
|
+
## Usage
|
|
80
14
|
|
|
81
15
|
```js
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
"extension-create": "latest"
|
|
91
|
-
}
|
|
16
|
+
import createExtension from '@extension-create/create'
|
|
17
|
+
|
|
18
|
+
async function createNewExtension () {
|
|
19
|
+
await createExtension(
|
|
20
|
+
projectName: /* string (required) */,
|
|
21
|
+
workingDir /* string (defaults to process.cwd) */,
|
|
22
|
+
template /* string - defaults to 'web' */
|
|
23
|
+
)
|
|
92
24
|
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### Using a specific browser for development
|
|
96
25
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
| Google Chrome ✅ | Microsoft Edge ✅ | Mozilla Firefox ⛔️ | Apple Safari ⛔️ | Opera browser ⛔️ | Chromium (forks) 🤔 |
|
|
100
|
-
|
|
101
|
-
If you want to target a specific browser, just pass the `--browser` flag to the dev/start command (Chrome or Edge, soon others), like `npx extension-create dev --browser=edge`.
|
|
102
|
-
|
|
103
|
-
That's it!
|
|
26
|
+
createNewExtension()
|
|
27
|
+
```
|
|
104
28
|
|
|
105
29
|
## License
|
|
106
30
|
|
package/dist/module.d.ts
ADDED
package/dist/module.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";var We=Object.create;var v=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var ze=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var je=(e,t)=>{for(var i in t)v(e,i,{get:t[i],enumerable:!0})},W=(e,t,i,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ae(t))!Ge.call(e,n)&&n!==i&&v(e,n,{get:()=>t[n],enumerable:!(s=Oe(t,n))||s.enumerable});return e};var c=(e,t,i)=>(i=e!=null?We(ze(e)):{},W(t||!e||!e.__esModule?v(i,"default",{value:e,enumerable:!0}):i,e)),Ve=e=>W(v({},"__esModule",{value:!0}),e);var qe={};je(qe,{extensionCreate:()=>Le});module.exports=Ve(qe);var C=c(require("path"));var w=c(require("path")),r=require("@colors/colors/safe"),O=c(require("fs/promises")),A=require("detect-package-manager");function z(e){let t=w.default.basename(e);return`Failed to write in the destination directory. Path for \`${t}\` is not writable.
|
|
2
|
+
Ensure you have write permissions for this folder.
|
|
3
|
+
Path: ${t}`}async function G(e,t){let i=w.default.basename(e),s=`
|
|
4
|
+
Conflict! Path to ${(0,r.cyan)(i)} includes conflicting files:
|
|
5
|
+
|
|
6
|
+
`;for(let n of t){let o=await O.default.lstat(w.default.join(e,n));s+=o.isDirectory()?`${(0,r.gray)("-")} ${(0,r.brightYellow)(n)}
|
|
7
|
+
`:`${(0,r.gray)("-")} ${(0,r.brightYellow)(n)}
|
|
8
|
+
`}return s+=`
|
|
9
|
+
You need to either rename/remove the files listed above, or choose a new directory name for your extension.
|
|
10
|
+
|
|
11
|
+
Path to conflicting directory: ${(0,r.underline)(e)}`,s}function j(){return"You need to provide an extension name to create one. \nSee `--help` for command info."}function V(){return"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 i=w.default.relative(process.cwd(),e),s=await(0,A.detect)(),n="npm run";switch(s){case"yarn":n="yarn dev";break;case"pnpm":n="pnpm run dev";break;default:n="npm run dev"}return`\u{1F9E9} - ${(0,r.brightGreen)("Success!")} Extension ${(0,r.cyan)(t)} created.
|
|
12
|
+
|
|
13
|
+
Now ${(0,r.brightBlue)(`cd ${(0,r.underline)(i)}`)} and ${(0,r.brightBlue)(`${n}`)} to open a new browser instance
|
|
14
|
+
with your extension installed, loaded, and enabled for development.
|
|
15
|
+
|
|
16
|
+
${(0,r.brightGreen)("You are ready")}. Time to hack on your extension!`}function U(e){return`\u{1F423} - Starting a new browser extension named ${(0,r.cyan)(e)}...`}function Y(){return"\u{1F91E} - Checking if destination path is writeable..."}function L(){return"\u{1F50E} - Scanning for potential conflicting files..."}function q(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't create directory ${(0,r.cyan)(e)}. ${t}`}function H(e){return`\u{1F537} - Writing ${(0,r.cyan)(e)} type definitions...`}function B(e){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Failed to write the extension type definition. ${e}`}function x(e,t){return t==="init"?`\u{1F9F0} - Installing ${(0,r.cyan)(e)}...`:`\u{1F9F0} - Installing ${(0,r.cyan)(e)} from template ${(0,r.brightBlue)(t)}...`}function D(e,t,i){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't find template ${(0,r.brightBlue)(t)} for ${(0,r.cyan)(e)}. ${i}`}function K(e){return`\u{1F332} - Initializing git repository for ${(0,r.cyan)(e)}...`}function Q(e,t,i){return`Command ${e} ${t.join(" ")} failed with exit code ${i}`}function Z(e,t){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)}. ${t.message}`}function ee(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't initialize ${(0,r.brightYellow)("git")} for ${(0,r.cyan)(e)}. ${t.message||t.toString()}`}function te(){return"\u{1F6E0} - Installing dependencies..."}function ne(e,t,i){return`Command ${e} ${t.join(" ")} failed with exit code ${i}`}function re(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Child process error: Can't install dependencies for ${(0,r.cyan)(e)}. ${t}`}function ie(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't install dependencies for ${(0,r.cyan)(e)}. ${t.message||t.toString()}`}function se(){return"Symlink created successfully."}function oe(e,t){return`Failed to create symlink: ${e} ${t.join(" ")}`}function ae(){return`\u{1F4DD} - Writing ${(0,r.brightYellow)("package.json")} metadata...`}function ce(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,r.brightYellow)("package.json")} for ${(0,r.cyan)(e)}. ${t}`}function le(){return`\u{1F4DC} - Writing ${(0,r.brightYellow)("manifest.json")} metadata...`}function me(e,t){return`${(0,r.red)("\u2716\uFE0E\u2716\uFE0E\u2716\uFE0E")} Can't write ${(0,r.brightYellow)("manifest.json")} for ${(0,r.cyan)(e)}. ${t}`}function pe(){return`\u{1F4C4} - Writing ${(0,r.brightYellow)("README.md")} metadata...`}function ge(e,t){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)}. ${t}`}function de(e){return`\u{1F91D} - Ensuring ${(0,r.cyan)(e)} folder exists...`}function fe(e){return"Error while checking directory writability: "+e}var E=c(require("fs/promises")),h=c(require("path")),ue=require("detect-package-manager");async function S(e,t){let i=await E.default.readdir(e,{withFileTypes:!0});return await E.default.mkdir(t,{recursive:!0}),await Promise.all(i.map(async s=>{let n=h.default.join(e,s.name),o=h.default.join(t,s.name);s.isDirectory()?await S(n,o):await E.default.copyFile(n,o)}))}async function f(){let e=await(0,ue.detect)(),t="npm run";switch(e){case"yarn":t="yarn";break;case"pnpm":t="pnpm run";break;default:t="npm run"}return t}function ye(e){let t=h.default.resolve(__dirname,"template");return h.default.resolve(e,t)}async function we(e,t){try{return console.log(de(t)),await E.default.mkdir(e,{recursive:!0}),!0}catch(i){return console.log(fe(i)),!1}}function J(e){return e!=="init"}function xe(e){return J(e)?!1:e==="typescript"||e.startsWith("typescript-")||e.endsWith("-typescript")}var Ee=c(require("path")),I=c(require("fs/promises"));var Xe=["LICENSE","node_modules"];async function he(e,t){console.log(U(t));try{let i=await we(e,t);console.log(Y()),i||(console.error(z(e)),process.exit(1));let s=await I.default.readdir(e);console.log(L());let n=await Promise.all(s.filter(o=>!o.startsWith(".")).filter(o=>!o.endsWith(".log")).filter(o=>!Xe.includes(o)).map(async o=>(await I.default.lstat(Ee.default.join(e,o))).isDirectory()?`${o}/`:`${o}`));if(n.length>0){let o=await G(e,n);throw new Error(o)}}catch(i){console.error(q(t,i)),process.exit(1)}}var $e=c(require("path"));async function ve(e,t,i){let s=$e.default.resolve(__dirname,"template");try{console.log(x(t,i)),await S(s,e)}catch(n){console.error(D(t,i,n)),process.exit(1)}}var u=c(require("path")),k=c(require("fs/promises")),De=c(require("go-git-it"));async function ke(e,t,i){let s=u.default.dirname(e),n=u.default.basename(i),a=`https://github.com/extension-js/extension.js/tree/main/examples/${i}`;try{await k.default.mkdir(e,{recursive:!0}),console.log(x(t,i)),process.env.EXTENSION_ENV==="development"?await k.default.cp(u.default.join(__dirname,"..","..","..","examples",n),u.default.join(s,n),{recursive:!0}):await(0,De.default)(a,s,x(t,n));let m=u.default.join(s,n);await k.default.rename(m,e)}catch(m){console.error(D(t,n,m)),process.exit(1)}}var $=c(require("path")),P=c(require("fs/promises"));var Ue={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 be(e,t,i){let s=ye(process.cwd()),n=J(i)?$.default.join(e,"package.json"):$.default.join(s,"package.json"),o=await P.default.readFile(n),a=JSON.parse(o.toString());a.scripts=a.scripts||{},a.dependencies=a.dependencies||{},a.devDependencies={...a.devDependencies||{},extension:process.env.EXTENSION_ENV==="development"?"*":"latest"};let m={...a,name:$.default.basename(e),private:!0,scripts:{...a.scripts,...Ue},dependencies:a.dependencies,devDependencies:a.devDependencies,author:{name:"Your Name",email:"your@email.com",url:"https://yourwebsite.com"}};try{console.log(ae()),await P.default.writeFile($.default.join(e,"package.json"),JSON.stringify(m,null,2))}catch(p){console.error(ce(t,p)),process.exit(1)}}var Ce=c(require("path")),Se=require("cross-spawn"),Je=c(require("fs"));var Te=c(require("path")),N=require("cross-spawn");async function Fe(e){let t=Te.default.join(__dirname,"../../cli"),i=await f(),s=["link"];await new Promise((n,o)=>{(0,N.spawn)(i,s,{cwd:t}).on("close",()=>{(0,N.spawn)(i,[...s,"extension"],{stdio:"inherit",cwd:e}).on("close",p=>{p===0?(console.log(se()),n()):o(new Error(oe(i,s)))})})}),console.log("Symlink creation completed.")}function Ye(){return["install","--silent"]}async function Ie(e,t){let i=Ce.default.join(e,"node_modules"),s=await f(),n=Ye();console.log(te()),process.env.EXTENSION_ENV==="development"&&await Fe(e);try{let o=process.cwd();process.chdir(e),await Je.default.promises.mkdir(i,{recursive:!0});let a=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",m=(0,Se.spawn)(s,n,{stdio:a});await new Promise((p,g)=>{m.on("close",y=>{process.chdir(o),y!==0?g(new Error(ne(s,n,y))):p()}),m.on("error",y=>{process.chdir(o),console.error(re(t,y)),g(y)})})}catch(o){console.error(ie(t,o)),process.exit(1)}}var b=c(require("path")),T=c(require("fs/promises"));async function Pe(e,t){let i=await T.default.readFile(b.default.join(__dirname,"template","README.md"),"utf-8"),s=await f(),n=require(b.default.join(e,"manifest.json")),o=i.replaceAll("[projectName]",t).replaceAll("[templateDescription]",n.description).replaceAll("[runCommand]",s);try{console.log(pe()),await T.default.mkdir(e,{recursive:!0}),await T.default.writeFile(b.default.join(e,"README.md"),o)}catch(a){console.error(ge(t,a)),process.exit(1)}}var F=c(require("path")),M=c(require("fs/promises"));async function Ne(e,t){let i=F.default.join(e,"manifest.json"),s=await M.default.readFile(i),o={...JSON.parse(s.toString()),name:F.default.basename(e),author:"Your Name"};try{console.log(le()),await M.default.writeFile(F.default.join(e,"manifest.json"),JSON.stringify(o,null,2))}catch(a){console.error(me(t,a)),process.exit(1)}}var _=c(require("path")),R=c(require("fs/promises"));async function Me(e,t){let i=_.default.join(e,"extension-env.d.ts"),s=process.env.EXTENSION_ENV==="development"?_.default.resolve(process.cwd(),"programs/develop/types"):"extension-develop/dist/types",n=`// Required Extension.js types for TypeScript projects.
|
|
17
|
+
// This file auto-generated and should not be excluded.
|
|
18
|
+
// If you need extra types, consider creating a new *.d.ts and
|
|
19
|
+
// referencing it in the "include" array in your tsconfig.json file.
|
|
20
|
+
// See https://www.typescriptlang.org/tsconfig#include for info.
|
|
21
|
+
/// <reference types="${s}/index.d.ts" />
|
|
22
|
+
|
|
23
|
+
// Polyfill types for browser.* APIs.
|
|
24
|
+
/// <reference types="${s}/polyfill.d.ts" />
|
|
25
|
+
`;try{await R.default.mkdir(e,{recursive:!0}),console.log(H(t)),await R.default.writeFile(i,n)}catch(o){console.error(B(o)),process.exit(1)}}var _e=require("cross-spawn");async function Re(e,t){let i="git",s=["init","--quiet"];console.log(K(t));try{let n=process.cwd();process.chdir(e);let o=process.env.EXTENSION_ENV==="development"?"inherit":"ignore",a=(0,_e.spawn)(i,s,{stdio:o});await new Promise((m,p)=>{a.on("close",g=>{process.chdir(n),g!==0?p(new Error(Q(i,s,g))):m()}),a.on("error",g=>{process.chdir(n),console.error(Z(t,g)),p(g)})})}catch(n){console.error(ee(t,n)),process.exit(1)}}async function Le(e,{template:t="init",noInstall:i=!1}){if(!e)throw new Error(j());if(e.startsWith("http"))throw new Error(V());let s=C.default.isAbsolute(e)?e:C.default.join(process.cwd(),e),n=C.default.basename(s);try{await he(s,n),t==="init"?await ve(s,n,t):await ke(s,n,t),await be(s,n,t),i||await Ie(s,n),await Pe(s,n),await Ne(s,n),await Re(s,n),xe(t)&&await Me(s,n);let o=await X(s,n);console.log(o)}catch(o){throw console.error(o),o}}0&&(module.exports={extensionCreate});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# [projectName]
|
|
2
|
+
|
|
3
|
+
> [templateDescription]
|
|
4
|
+
|
|
5
|
+
## Scripts Available
|
|
6
|
+
|
|
7
|
+
In the project directory, you can run:
|
|
8
|
+
|
|
9
|
+
### [runCommand] dev
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
// Runs the app in the development mode.
|
|
13
|
+
// Will open a new browser instance with your extension loaded.
|
|
14
|
+
// The page will reload when you make changes.
|
|
15
|
+
[runCommand] dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### [runCommand] start
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
// Runs the app in the production mode.
|
|
22
|
+
// Will open a new browser instance with your extension loaded.
|
|
23
|
+
// This is how your browser extension will work once published.
|
|
24
|
+
[runCommand] start
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### [runCommand] build
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
// Builds the app for production.
|
|
31
|
+
// Bundles your browser extension in production mode for the target browser.
|
|
32
|
+
[runCommand] build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Learn More
|
|
36
|
+
|
|
37
|
+
Learn more about creating cross-browser extensions in the [Extension.js](https://extension.js.org) documentation.
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -2,66 +2,43 @@
|
|
|
2
2
|
"license": "MIT",
|
|
3
3
|
"repository": {
|
|
4
4
|
"type": "git",
|
|
5
|
-
"url": "https://github.com/cezaraugusto/extension
|
|
6
|
-
"directory": "programs/
|
|
5
|
+
"url": "https://github.com/cezaraugusto/extension.git",
|
|
6
|
+
"directory": "programs/create"
|
|
7
7
|
},
|
|
8
8
|
"engines": {
|
|
9
9
|
"node": ">=18"
|
|
10
10
|
},
|
|
11
11
|
"name": "extension-create",
|
|
12
|
-
"version": "
|
|
13
|
-
"description": "
|
|
14
|
-
"main": "./dist/
|
|
15
|
-
"types": "./dist/
|
|
12
|
+
"version": "2.0.0-alpha.0",
|
|
13
|
+
"description": "The Extension.js create step",
|
|
14
|
+
"main": "./dist/module.js",
|
|
15
|
+
"types": "./dist/module.d.ts",
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"bin": {
|
|
20
|
-
"extension": "./dist/cli.js",
|
|
21
|
-
"extension-create": "./dist/cli.js"
|
|
22
|
-
},
|
|
23
19
|
"author": {
|
|
24
20
|
"name": "Cezar Augusto",
|
|
25
21
|
"email": "boss@cezaraugusto.net",
|
|
26
22
|
"url": "https://cezaraugusto.com"
|
|
27
23
|
},
|
|
28
24
|
"scripts": {
|
|
29
|
-
"compile:readme-files": "node ./scripts/copyMarkdownFilesToCli.js",
|
|
30
|
-
"compile:tailwind-config": "node ./scripts/copyTailwindConfig.js",
|
|
31
|
-
"compile:stylelint-config": "node ./scripts/copyStylelintConfig.js",
|
|
32
|
-
"compile:cli": "tsup-node ./cli.ts --format cjs --dts --target=node18",
|
|
33
|
-
"compile": "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config &&yarn compile:cli",
|
|
34
25
|
"clean": "rm -rf dist",
|
|
35
|
-
"
|
|
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"
|
|
36
30
|
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"zero-config",
|
|
39
|
-
"build",
|
|
40
|
-
"develop",
|
|
41
|
-
"browser",
|
|
42
|
-
"extension",
|
|
43
|
-
"chrome extension",
|
|
44
|
-
"edge extension",
|
|
45
|
-
"firefox extension",
|
|
46
|
-
"web",
|
|
47
|
-
"react",
|
|
48
|
-
"typescript"
|
|
49
|
-
],
|
|
50
31
|
"dependencies": {
|
|
51
32
|
"@colors/colors": "^1.6.0",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"semver": "^7.5.4",
|
|
56
|
-
"update-check": "^1.5.4"
|
|
33
|
+
"cross-spawn": "^7.0.3",
|
|
34
|
+
"detect-package-manager": "^3.0.2",
|
|
35
|
+
"go-git-it": "^2.0.1"
|
|
57
36
|
},
|
|
58
37
|
"devDependencies": {
|
|
59
|
-
"@types/
|
|
60
|
-
"@types/
|
|
61
|
-
"
|
|
62
|
-
"@types/semver": "^7.5.6",
|
|
38
|
+
"@types/cross-spawn": "^6.0.6",
|
|
39
|
+
"@types/react-dom": "^18.2.18",
|
|
40
|
+
"globals": "^15.9.0",
|
|
63
41
|
"jest": "^29.7.0",
|
|
64
|
-
"mock-fs": "^5.2.0",
|
|
65
42
|
"ts-jest": "^29.1.2",
|
|
66
43
|
"tsconfig": "*",
|
|
67
44
|
"tsup": "^8.0.1",
|
package/dist/cli.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
package/dist/cli.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
|
|
30
|
-
// cli.ts
|
|
31
|
-
var import_semver = __toESM(require("semver"));
|
|
32
|
-
var import_commander = require("commander");
|
|
33
|
-
var import_create = __toESM(require("@extension-create/create"));
|
|
34
|
-
var import_develop = require("@extension-create/develop");
|
|
35
|
-
|
|
36
|
-
// check-updates.ts
|
|
37
|
-
var import_update_check = __toESM(require("update-check"));
|
|
38
|
-
var import_safe = require("@colors/colors/safe");
|
|
39
|
-
async function checkUpdates(packageJson) {
|
|
40
|
-
let update = null;
|
|
41
|
-
try {
|
|
42
|
-
update = await (0, import_update_check.default)(packageJson);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
if (process.env.EXTENSION_ENV === "development") {
|
|
45
|
-
console.error((0, import_safe.bold)((0, import_safe.red)(`Failed to check for updates: ${err}`)));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (update) {
|
|
49
|
-
console.log(
|
|
50
|
-
`Your \u{1F9E9} ${(0, import_safe.bold)("extension-create")} version is ${(0, import_safe.red)("outdated")}.
|
|
51
|
-
The latest version is ${(0, import_safe.bold)(update.latest)}. Please update!`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// messages/blockingErrors.ts
|
|
57
|
-
var blockingErrors_exports = {};
|
|
58
|
-
__export(blockingErrors_exports, {
|
|
59
|
-
noURLWithoutStart: () => noURLWithoutStart,
|
|
60
|
-
notImplemented: () => notImplemented,
|
|
61
|
-
unsupportedNodeVersion: () => unsupportedNodeVersion
|
|
62
|
-
});
|
|
63
|
-
function unsupportedNodeVersion() {
|
|
64
|
-
return `
|
|
65
|
-
You are using an unsupported Node version (${process.version}).
|
|
66
|
-
|
|
67
|
-
Please update to a version higher than 18.
|
|
68
|
-
`;
|
|
69
|
-
}
|
|
70
|
-
function noURLWithoutStart(argument) {
|
|
71
|
-
return `
|
|
72
|
-
The default \`create\` command does not accept URLs.
|
|
73
|
-
Are you forgetting a \`start\` command? Maybe:
|
|
74
|
-
|
|
75
|
-
npx extension-create \`start\` ${argument}
|
|
76
|
-
`;
|
|
77
|
-
}
|
|
78
|
-
function notImplemented(argument) {
|
|
79
|
-
return `${argument} command not implemented yet.`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// messages/programHelp.ts
|
|
83
|
-
function programHelp() {
|
|
84
|
-
return `
|
|
85
|
-
# Help center for the extension-create program
|
|
86
|
-
|
|
87
|
-
## Usage: \`extension-create [command] [options]\`
|
|
88
|
-
|
|
89
|
-
**Note:** If you are looking for a specific list of options,
|
|
90
|
-
all high-level commands offer their own \`--help\` file with
|
|
91
|
-
information about usage and a list of command flags available.
|
|
92
|
-
|
|
93
|
-
For example:
|
|
94
|
-
|
|
95
|
-
\`extension-create create --help\`
|
|
96
|
-
outputs information about the \`create\` command.
|
|
97
|
-
|
|
98
|
-
## Options available
|
|
99
|
-
|
|
100
|
-
\`extension-create create <extension-name>\`
|
|
101
|
-
Creates a new extension from template. The "create" command
|
|
102
|
-
is optional and can be ommitted.
|
|
103
|
-
|
|
104
|
-
\`extension-create dev <extension-path>\`
|
|
105
|
-
Starts a new browser instance in development mode, with the target
|
|
106
|
-
extension loaded and auto-reloaded based on file changes.
|
|
107
|
-
|
|
108
|
-
\`extension-create start <extension-path>\`
|
|
109
|
-
Starts a new browser instance in production mode, with the target
|
|
110
|
-
extension compiled based on the browser choice.
|
|
111
|
-
|
|
112
|
-
\`extension-create build <extension-path>\`
|
|
113
|
-
Builds the target extension with browser defaults, ready for packaging.
|
|
114
|
-
|
|
115
|
-
\`extension-create --help\`
|
|
116
|
-
This command ;) Outputs a help file with key command options.
|
|
117
|
-
|
|
118
|
-
Feels something is wrong? Help by reporting a bug:
|
|
119
|
-
https://github.com/cezaraugusto/extension-create/issues/new
|
|
120
|
-
`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// messages/index.ts
|
|
124
|
-
var messages = {
|
|
125
|
-
...blockingErrors_exports,
|
|
126
|
-
programHelp
|
|
127
|
-
};
|
|
128
|
-
var messages_default = messages;
|
|
129
|
-
|
|
130
|
-
// package.json
|
|
131
|
-
var package_default = {
|
|
132
|
-
license: "MIT",
|
|
133
|
-
repository: {
|
|
134
|
-
type: "git",
|
|
135
|
-
url: "https://github.com/cezaraugusto/extension-create.git",
|
|
136
|
-
directory: "programs/cli"
|
|
137
|
-
},
|
|
138
|
-
engines: {
|
|
139
|
-
node: ">=18"
|
|
140
|
-
},
|
|
141
|
-
name: "extension-create",
|
|
142
|
-
version: "1.3.0",
|
|
143
|
-
description: "Create cross-browser extensions with no build configuration.",
|
|
144
|
-
main: "./dist/cli.js",
|
|
145
|
-
types: "./dist/cli.d.ts",
|
|
146
|
-
files: [
|
|
147
|
-
"dist"
|
|
148
|
-
],
|
|
149
|
-
bin: {
|
|
150
|
-
extension: "./dist/cli.js",
|
|
151
|
-
"extension-create": "./dist/cli.js"
|
|
152
|
-
},
|
|
153
|
-
author: {
|
|
154
|
-
name: "Cezar Augusto",
|
|
155
|
-
email: "boss@cezaraugusto.net",
|
|
156
|
-
url: "https://cezaraugusto.com"
|
|
157
|
-
},
|
|
158
|
-
scripts: {
|
|
159
|
-
"compile:readme-files": "node ./scripts/copyMarkdownFilesToCli.js",
|
|
160
|
-
"compile:tailwind-config": "node ./scripts/copyTailwindConfig.js",
|
|
161
|
-
"compile:stylelint-config": "node ./scripts/copyStylelintConfig.js",
|
|
162
|
-
"compile:cli": "tsup-node ./cli.ts --format cjs --dts --target=node18",
|
|
163
|
-
compile: "yarn compile:readme-files && yarn compile:tailwind-config && yarn compile:stylelint-config &&yarn compile:cli",
|
|
164
|
-
clean: "rm -rf dist",
|
|
165
|
-
test: "jest"
|
|
166
|
-
},
|
|
167
|
-
keywords: [
|
|
168
|
-
"zero-config",
|
|
169
|
-
"build",
|
|
170
|
-
"develop",
|
|
171
|
-
"browser",
|
|
172
|
-
"extension",
|
|
173
|
-
"chrome extension",
|
|
174
|
-
"edge extension",
|
|
175
|
-
"firefox extension",
|
|
176
|
-
"web",
|
|
177
|
-
"react",
|
|
178
|
-
"typescript"
|
|
179
|
-
],
|
|
180
|
-
dependencies: {
|
|
181
|
-
"@colors/colors": "^1.6.0",
|
|
182
|
-
"@extension-create/create": "*",
|
|
183
|
-
"@extension-create/develop": "*",
|
|
184
|
-
commander: "^11.1.0",
|
|
185
|
-
semver: "^7.5.4",
|
|
186
|
-
"update-check": "^1.5.4"
|
|
187
|
-
},
|
|
188
|
-
devDependencies: {
|
|
189
|
-
"@types/jest": "^29.5.11",
|
|
190
|
-
"@types/mock-fs": "^4.13.4",
|
|
191
|
-
"@types/node": "^20.11.5",
|
|
192
|
-
"@types/semver": "^7.5.6",
|
|
193
|
-
jest: "^29.7.0",
|
|
194
|
-
"mock-fs": "^5.2.0",
|
|
195
|
-
"ts-jest": "^29.1.2",
|
|
196
|
-
tsconfig: "*",
|
|
197
|
-
tsup: "^8.0.1",
|
|
198
|
-
typescript: "5.3.3"
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// cli.ts
|
|
203
|
-
checkUpdates(package_default);
|
|
204
|
-
if (import_semver.default.lte(process.version, "18.0.0")) {
|
|
205
|
-
messages_default.unsupportedNodeVersion();
|
|
206
|
-
process.exit(1);
|
|
207
|
-
}
|
|
208
|
-
var extensionCreate = import_commander.program;
|
|
209
|
-
var isExtensionCreateNamespace = package_default.name !== "extension";
|
|
210
|
-
if (process.env.EXTENSION_ENV === "development") {
|
|
211
|
-
console.log(`Running extension-create via ${package_default.name}...`);
|
|
212
|
-
}
|
|
213
|
-
extensionCreate.name(package_default.name).description(package_default.description).version(package_default.version).addHelpText("after", messages_default.programHelp());
|
|
214
|
-
var vendors = (browser) => browser === "all" ? "chrome,edge".split(",") : browser.split(",");
|
|
215
|
-
extensionCreate.command("create", { isDefault: isExtensionCreateNamespace }).arguments("<project-name|project-path>").usage("create <project-name|project-path> [options]").description("Creates a new extension.").option(
|
|
216
|
-
"-t, --template <template-name>",
|
|
217
|
-
"specify a template for the created project"
|
|
218
|
-
).action(async function(pathOrRemoteUrl, {
|
|
219
|
-
browser = "chrome",
|
|
220
|
-
template,
|
|
221
|
-
...otherCommandOptions
|
|
222
|
-
}) {
|
|
223
|
-
switch (pathOrRemoteUrl) {
|
|
224
|
-
case "dev":
|
|
225
|
-
for (const vendor of vendors(browser)) {
|
|
226
|
-
await (0, import_develop.extensionDev)(pathOrRemoteUrl, {
|
|
227
|
-
mode: "development",
|
|
228
|
-
browser: vendor,
|
|
229
|
-
...otherCommandOptions
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
case "start":
|
|
234
|
-
for (const vendor of vendors(browser)) {
|
|
235
|
-
await (0, import_develop.extensionStart)(pathOrRemoteUrl, {
|
|
236
|
-
mode: "production",
|
|
237
|
-
browser: vendor,
|
|
238
|
-
...otherCommandOptions
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
break;
|
|
242
|
-
case "build":
|
|
243
|
-
for (const vendor of vendors(browser)) {
|
|
244
|
-
await (0, import_develop.extensionBuild)(pathOrRemoteUrl, {
|
|
245
|
-
browser: vendor,
|
|
246
|
-
...otherCommandOptions
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
break;
|
|
250
|
-
default:
|
|
251
|
-
await (0, import_create.default)(pathOrRemoteUrl, { template });
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
extensionCreate.command("dev").arguments("[project-path|remote-url]").usage("dev [project-path|remote-url] [options]").description("Starts the development server (development mode)").option(
|
|
256
|
-
"-u, --user-data-dir <path-to-file | boolean>",
|
|
257
|
-
"what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile"
|
|
258
|
-
).option(
|
|
259
|
-
"-b, --browser <chrome | edge>",
|
|
260
|
-
"specify a browser to run your extension in development mode"
|
|
261
|
-
).option(
|
|
262
|
-
"--polyfill <boolean>",
|
|
263
|
-
"whether or not to apply the cross-browser polyfill. Defaults to `true`"
|
|
264
|
-
).option(
|
|
265
|
-
"-p, --port <number>",
|
|
266
|
-
"what port should extension-create/develop run. Defaults to `3000`"
|
|
267
|
-
).action(async function(pathOrRemoteUrl, { browser = "chrome", ...devOptions }) {
|
|
268
|
-
for (const vendor of vendors(browser)) {
|
|
269
|
-
await (0, import_develop.extensionDev)(pathOrRemoteUrl, {
|
|
270
|
-
mode: "development",
|
|
271
|
-
browser: vendor,
|
|
272
|
-
...devOptions
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
extensionCreate.command("start").arguments("[project-path|remote-url]").usage("start [project-path|remote-url] [options]").description("Starts the development server (production mode)").option(
|
|
277
|
-
"-u, --user-data-dir <path-to-file | boolean>",
|
|
278
|
-
"what path to use for the browser profile. A boolean value of false sets the profile to the default user profile. Defaults to a fresh profile"
|
|
279
|
-
).option(
|
|
280
|
-
"-b, --browser <chrome | edge>",
|
|
281
|
-
"specify a browser to run your extension in development mode"
|
|
282
|
-
).option(
|
|
283
|
-
"--polyfill <boolean>",
|
|
284
|
-
"whether or not to apply the cross-browser polyfill. Defaults to `true`"
|
|
285
|
-
).option(
|
|
286
|
-
"-p, --port <number>",
|
|
287
|
-
"what port should extension-create/develop run. Defaults to `3000`"
|
|
288
|
-
).action(async function(pathOrRemoteUrl, { browser = "chrome", ...startOptions }) {
|
|
289
|
-
for (const vendor of vendors(browser)) {
|
|
290
|
-
await (0, import_develop.extensionStart)(pathOrRemoteUrl, {
|
|
291
|
-
mode: "production",
|
|
292
|
-
browser: vendor,
|
|
293
|
-
...startOptions
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
extensionCreate.command("build").arguments("[project-name]").usage("build [path-to-remote-extension] [options]").description("Builds the extension for production").option(
|
|
298
|
-
"-b, --browser <chrome | edge>",
|
|
299
|
-
"specify a browser to run your extension in development mode"
|
|
300
|
-
).option(
|
|
301
|
-
"--polyfill <boolean>",
|
|
302
|
-
"whether or not to apply the cross-browser polyfill. Defaults to `false`"
|
|
303
|
-
).action(async function(pathOrRemoteUrl, { browser = "chrome", ...buildOptions }) {
|
|
304
|
-
for (const vendor of vendors(browser)) {
|
|
305
|
-
await (0, import_develop.extensionBuild)(pathOrRemoteUrl, {
|
|
306
|
-
browser: vendor,
|
|
307
|
-
...buildOptions
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
extensionCreate.parse();
|
package/dist/stylelint.config.js
DELETED
package/dist/tailwind.config.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
|
|
4
|
-
const [, pathOrRemoteUrl] = process.argv.slice(2)
|
|
5
|
-
const projectDir = pathOrRemoteUrl.startsWith('http')
|
|
6
|
-
? process.cwd() + path.basename(pathOrRemoteUrl)
|
|
7
|
-
: path.resolve(__dirname, pathOrRemoteUrl)
|
|
8
|
-
|
|
9
|
-
const tailwindConfig = path.join(projectDir, 'tailwind.config.js')
|
|
10
|
-
|
|
11
|
-
/** @type {import('tailwindcss').Config} */
|
|
12
|
-
const tailwindConfigData = fs.existsSync(tailwindConfig)
|
|
13
|
-
? require(tailwindConfig)
|
|
14
|
-
: {content: []}
|
|
15
|
-
|
|
16
|
-
/** @type {import('tailwindcss').Config} */
|
|
17
|
-
const tailwindRootConfig = {
|
|
18
|
-
...tailwindConfigData,
|
|
19
|
-
content: [
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
21
|
-
...tailwindConfigData.content.map((file) => path.join(projectDir, file))
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = tailwindRootConfig
|