extension-create 0.5.1 → 0.5.2
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/create/README.md +5 -7
- package/create/cli.js +2 -2
- package/create/cli.test.js +3 -5
- package/create/createExtension.js +8 -2
- package/create/messages/directoryHasConflicts.js +9 -11
- package/create/messages/programHelp.js +1 -1
- package/create/messages/successfullInstall.js +1 -1
- package/create/steps/abortProjectAndClean.js +8 -5
- package/create/steps/cleanTemplateFolder.js +1 -1
- package/create/steps/createDirectory.js +9 -13
- package/create/steps/getTemplatePath.js +1 -1
- package/create/steps/importExternalTemplate.js +11 -10
- package/create/steps/importLocalTemplate.js +5 -7
- package/create/steps/installDependencies.js +2 -5
- package/create/steps/writePackageJson.js +7 -7
- package/create/templates/standard/template/manifest.json +21 -25
- package/create/templates/standard/template/newtab/newtab.html +8 -5
- package/create/templates/standard/template/newtab/styles.css +2 -2
- package/create/templates/standard/template/popup/popup.css +2 -2
- package/create/templates/standard/template/popup/popup.html +2 -2
- package/create/templates/standard/template.json +1 -2
- package/develop/README.md +5 -7
- package/develop/module.js +1 -1
- package/develop/package-lock.json +7979 -0
- package/develop/package.json +0 -7
- package/develop/start/cli.js +1 -1
- package/develop/start/cli.test.js +2 -4
- package/develop/start/config/browserSwitch.js +1 -1
- package/develop/start/config/compiler.js +3 -19
- package/develop/start/messages/manifestNotFound.js +1 -1
- package/develop/start/messages/programHelp.js +1 -1
- package/develop/start/resolve/resolveExtensionPath.js +1 -1
- package/develop/start/startExtension.js +6 -3
- package/develop/start/steps/resolveManifest.js +1 -1
- package/develop/start/steps/startWebpack.js +7 -4
- package/develop/yarn.lock +9 -266
- package/package.json +13 -11
- package/preinstall.sh +10 -2
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ You are done. Time to hack on your extension!
|
|
|
39
39
|
|
|
40
40
|
### Kickstart any sample from Chrome Extension Samples
|
|
41
41
|
|
|
42
|
-
The [chrome-
|
|
42
|
+
The [chrome-extensions-sample](https://github.com/GoogleChrome/chrome-extensions-samples/) project is a great way to kickstart developing your extension.
|
|
43
43
|
|
|
44
44
|
If we go to the samples repository and look for an extension sample to work, let's say the [make_page_red](https://github.com/GoogleChrome/chrome-extensions-samples/blob/main/mv2-archive/api/browserAction/make_page_red/) sample, all we need is to copy and paste it's URL as an argument for the start command:
|
|
45
45
|
|
package/create/README.md
CHANGED
|
@@ -31,20 +31,18 @@ const createExtensionCLI = require('@extension-create/create')
|
|
|
31
31
|
|
|
32
32
|
const yourCreateProgram = program
|
|
33
33
|
|
|
34
|
-
yourCreateProgram
|
|
35
|
-
.version(packageJson.version)
|
|
34
|
+
yourCreateProgram.version(packageJson.version)
|
|
36
35
|
|
|
37
36
|
createExtensionCLI(yourCreateProgram)
|
|
38
37
|
|
|
39
|
-
yourCreateProgram
|
|
40
|
-
.parse(process.argv)
|
|
38
|
+
yourCreateProgram.parse(process.argv)
|
|
41
39
|
```
|
|
42
40
|
|
|
43
41
|
## Program options table
|
|
44
42
|
|
|
45
|
-
| Flag
|
|
46
|
-
|
|
47
|
-
| -t, --template
|
|
43
|
+
| Flag | Argument | What it does |
|
|
44
|
+
| -------------- | ----------------------------------------------------- | ----------------------------------------- |
|
|
45
|
+
| -t, --template | Path to the template used to bootstrap your extension | Bootstrap your extension using a template |
|
|
48
46
|
|
|
49
47
|
## Contributing
|
|
50
48
|
|
package/create/cli.js
CHANGED
|
@@ -17,12 +17,12 @@ const packageJson = require('./package.json')
|
|
|
17
17
|
let projectName
|
|
18
18
|
let templateName
|
|
19
19
|
|
|
20
|
-
function createExtensionCLI
|
|
20
|
+
function createExtensionCLI(clientProgram = program) {
|
|
21
21
|
clientProgram
|
|
22
22
|
.version(packageJson.version)
|
|
23
23
|
.command('create', {isDefault: true})
|
|
24
24
|
.usage('create <project-directory> [options]')
|
|
25
|
-
.action((cmd) => {
|
|
25
|
+
.action((_, cmd) => {
|
|
26
26
|
const {args, template} = cmd
|
|
27
27
|
|
|
28
28
|
projectName = args[0]
|
package/create/cli.test.js
CHANGED
|
@@ -16,11 +16,9 @@ describe('`create` command line interface', () => {
|
|
|
16
16
|
|
|
17
17
|
it('creates an extension with specified project name', async () => {
|
|
18
18
|
expect.assertions(1)
|
|
19
|
-
spawn.sync(
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
{stdio: 'inherit'}
|
|
23
|
-
)
|
|
19
|
+
spawn.sync('node', [createExtensionCLI, 'my-extension-home'], {
|
|
20
|
+
stdio: 'inherit'
|
|
21
|
+
})
|
|
24
22
|
|
|
25
23
|
const pathStat = await fs.stat(outputpath)
|
|
26
24
|
const isDirectory = pathStat.isDirectory()
|
|
@@ -14,9 +14,15 @@ const messages = require('./messages')
|
|
|
14
14
|
const abortAndClean = require('./steps/abortProjectAndClean')
|
|
15
15
|
const cleanTemplateFolder = require('./steps/cleanTemplateFolder')
|
|
16
16
|
|
|
17
|
-
process.on('unhandledRejection', (error) => {
|
|
17
|
+
process.on('unhandledRejection', (error) => {
|
|
18
|
+
throw error
|
|
19
|
+
})
|
|
18
20
|
|
|
19
|
-
module.exports = async function (
|
|
21
|
+
module.exports = async function createExtension(
|
|
22
|
+
workingDir,
|
|
23
|
+
projectName,
|
|
24
|
+
template
|
|
25
|
+
) {
|
|
20
26
|
try {
|
|
21
27
|
await createDirectory(workingDir, projectName)
|
|
22
28
|
|
|
@@ -10,27 +10,25 @@ const path = require('path')
|
|
|
10
10
|
const fs = require('fs-extra')
|
|
11
11
|
const {log} = require('log-md')
|
|
12
12
|
|
|
13
|
-
module.exports = async function (
|
|
13
|
+
module.exports = async function directoryHasConflicts(
|
|
14
|
+
projectPath,
|
|
15
|
+
conflictingFiles
|
|
16
|
+
) {
|
|
14
17
|
const projectName = path.basename(projectPath)
|
|
15
18
|
|
|
16
|
-
log(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
19
|
+
log(`Conflict! Directory \`${projectName}/\` includes conflicting files:`, {
|
|
20
|
+
gutter: true
|
|
21
|
+
})
|
|
20
22
|
|
|
21
23
|
for (const file of conflictingFiles) {
|
|
22
24
|
const stats = await fs.lstat(path.join(projectPath, file))
|
|
23
25
|
|
|
24
|
-
log(
|
|
25
|
-
stats.isDirectory()
|
|
26
|
-
? ` 📁 - ${file}/`
|
|
27
|
-
: ` 📄 - ${file}`
|
|
28
|
-
)
|
|
26
|
+
log(stats.isDirectory() ? ` 📁 - ${file}/` : ` 📄 - ${file}`)
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
log(
|
|
32
30
|
'You need to either rename/remove the files listed above,\n' +
|
|
33
|
-
|
|
31
|
+
'or choose a new directory name for your extension.',
|
|
34
32
|
{gutter: true}
|
|
35
33
|
)
|
|
36
34
|
|
|
@@ -9,7 +9,7 @@ const path = require('path')
|
|
|
9
9
|
|
|
10
10
|
const {log} = require('log-md')
|
|
11
11
|
|
|
12
|
-
module.exports = function (workingDir, projectName) {
|
|
12
|
+
module.exports = function successfullInstall(workingDir, projectName) {
|
|
13
13
|
const projectPath = path.join(workingDir, projectName)
|
|
14
14
|
const relativePath = path.relative(workingDir, projectPath)
|
|
15
15
|
|
|
@@ -10,7 +10,11 @@ const path = require('path')
|
|
|
10
10
|
const fs = require('fs-extra')
|
|
11
11
|
const {log} = require('log-md')
|
|
12
12
|
|
|
13
|
-
module.exports = async function (
|
|
13
|
+
module.exports = async function abortProjectAndClean(
|
|
14
|
+
error,
|
|
15
|
+
workingDir,
|
|
16
|
+
projectName
|
|
17
|
+
) {
|
|
14
18
|
const projectPath = path.resolve(workingDir, projectName)
|
|
15
19
|
|
|
16
20
|
log('😑👎 Aborting installation.')
|
|
@@ -24,10 +28,9 @@ module.exports = async function (error, workingDir, projectName) {
|
|
|
24
28
|
🚨 Unexpected creation error. This is a bug.
|
|
25
29
|
`)
|
|
26
30
|
log(`Please report: "${error}"`)
|
|
27
|
-
log(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
31
|
+
log('https://github.com/cezaraugusto/extension-create/issues/', {
|
|
32
|
+
gutter: true
|
|
33
|
+
})
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
log('🧹 - Removing files generated from project in:')
|
|
@@ -10,7 +10,7 @@ const {log} = require('log-md')
|
|
|
10
10
|
|
|
11
11
|
const getTemplatePath = require('./getTemplatePath')
|
|
12
12
|
|
|
13
|
-
module.exports = async function (template) {
|
|
13
|
+
module.exports = async function createTemplateFolder(template) {
|
|
14
14
|
// We don't want to delete local templates
|
|
15
15
|
if (!template) {
|
|
16
16
|
return
|
|
@@ -12,16 +12,12 @@ const {log} = require('log-md')
|
|
|
12
12
|
|
|
13
13
|
const messages = require('../messages')
|
|
14
14
|
|
|
15
|
-
const allowlist = [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
log(
|
|
22
|
-
`👍 Starting a new browser extension named **${projectName}**`,
|
|
23
|
-
{gutter: true}
|
|
24
|
-
)
|
|
15
|
+
const allowlist = ['LICENSE', 'node_modules']
|
|
16
|
+
|
|
17
|
+
module.exports = async function createDirectory(workingDir, projectName) {
|
|
18
|
+
log(`👍 Starting a new browser extension named **${projectName}**`, {
|
|
19
|
+
gutter: true
|
|
20
|
+
})
|
|
25
21
|
const projectPath = path.resolve(workingDir, projectName)
|
|
26
22
|
|
|
27
23
|
log(`🤞 - Checking if \`${workingDir}\` exists...`)
|
|
@@ -31,11 +27,11 @@ module.exports = async function (workingDir, projectName) {
|
|
|
31
27
|
const currentDir = await fs.readdir(projectPath)
|
|
32
28
|
const conflictingFiles = currentDir
|
|
33
29
|
// .gitignore, .DS_Store, etc
|
|
34
|
-
.filter(file => !file.startsWith('.'))
|
|
30
|
+
.filter((file) => !file.startsWith('.'))
|
|
35
31
|
// Logs of yarn/npm
|
|
36
|
-
.filter(file => !file.endsWith('.log'))
|
|
32
|
+
.filter((file) => !file.endsWith('.log'))
|
|
37
33
|
// Whatever we think is appropriate
|
|
38
|
-
.filter(file => !allowlist.includes(file))
|
|
34
|
+
.filter((file) => !allowlist.includes(file))
|
|
39
35
|
|
|
40
36
|
// If directory has conflicting files, abort
|
|
41
37
|
if (conflictingFiles.length) {
|
|
@@ -10,7 +10,7 @@ const path = require('path')
|
|
|
10
10
|
const templatesDir = path.resolve(__dirname, '../templates')
|
|
11
11
|
const templateTempDir = (template) => `__temp__${template}`
|
|
12
12
|
|
|
13
|
-
module.exports = function (template) {
|
|
13
|
+
module.exports = function getTemplatePath(template) {
|
|
14
14
|
let thisTemplate
|
|
15
15
|
|
|
16
16
|
if (template) {
|
|
@@ -13,29 +13,30 @@ const {log} = require('log-md')
|
|
|
13
13
|
|
|
14
14
|
const templatesDir = path.resolve(__dirname, '../templates')
|
|
15
15
|
|
|
16
|
-
module.exports = async function (
|
|
16
|
+
module.exports = async function importExternalTemplate(
|
|
17
|
+
workingDir,
|
|
18
|
+
projectName,
|
|
19
|
+
template
|
|
20
|
+
) {
|
|
17
21
|
const projectPath = path.resolve(workingDir, projectName)
|
|
18
22
|
const templateName = template
|
|
19
23
|
|
|
20
24
|
try {
|
|
21
|
-
const tempTemplatePath = path
|
|
22
|
-
.join(templatesDir, `__temp__${templateName}`)
|
|
25
|
+
const tempTemplatePath = path.join(templatesDir, `__temp__${templateName}`)
|
|
23
26
|
|
|
24
27
|
log(`⚙️ - Importing template \`${template}\` as requested...`)
|
|
25
28
|
const {name, version} = await pacote.manifest(templateName)
|
|
26
29
|
|
|
27
|
-
await pacote
|
|
28
|
-
.extract(`${name}@${version}`, tempTemplatePath)
|
|
30
|
+
await pacote.extract(`${name}@${version}`, tempTemplatePath)
|
|
29
31
|
|
|
30
|
-
log(
|
|
32
|
+
log(`🧰 - Installing **${projectName}** from template \`${templateName}\``)
|
|
31
33
|
const templateDirPath = path.join(tempTemplatePath, 'template')
|
|
32
34
|
|
|
33
35
|
await fs.copy(templateDirPath, projectPath)
|
|
34
36
|
} catch (error) {
|
|
35
|
-
log(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
)
|
|
37
|
+
log(`😕❓ Can't find template __${templateName}__. ${error}`, {
|
|
38
|
+
gutter: true
|
|
39
|
+
})
|
|
39
40
|
process.exit(1)
|
|
40
41
|
}
|
|
41
42
|
}
|
|
@@ -13,10 +13,9 @@ const {log} = require('log-md')
|
|
|
13
13
|
const templatesDir = path.resolve(__dirname, '../templates')
|
|
14
14
|
const defaultTemplate = 'standard'
|
|
15
15
|
|
|
16
|
-
module.exports = async function (workingDir, projectName) {
|
|
16
|
+
module.exports = async function importLocalTemplate(workingDir, projectName) {
|
|
17
17
|
const projectPath = path.resolve(workingDir, projectName)
|
|
18
|
-
const templateDirPath = path
|
|
19
|
-
.join(templatesDir, defaultTemplate, 'template')
|
|
18
|
+
const templateDirPath = path.join(templatesDir, defaultTemplate, 'template')
|
|
20
19
|
|
|
21
20
|
const templateName = path.basename(templateDirPath)
|
|
22
21
|
|
|
@@ -24,10 +23,9 @@ module.exports = async function (workingDir, projectName) {
|
|
|
24
23
|
log(`🧰 - Installing **${projectName}** from standard template...`)
|
|
25
24
|
await fs.copy(templateDirPath, projectPath)
|
|
26
25
|
} catch (error) {
|
|
27
|
-
log(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
)
|
|
26
|
+
log(`😕❓ Can't copy template __${templateName}__: ${error}`, {
|
|
27
|
+
gutter: true
|
|
28
|
+
})
|
|
31
29
|
process.exit(1)
|
|
32
30
|
}
|
|
33
31
|
}
|
|
@@ -13,7 +13,7 @@ const {log} = require('log-md')
|
|
|
13
13
|
|
|
14
14
|
const abortProjectAndClean = require('./abortProjectAndClean')
|
|
15
15
|
|
|
16
|
-
module.exports = async function (workingDir, projectName) {
|
|
16
|
+
module.exports = async function installDependencies(workingDir, projectName) {
|
|
17
17
|
const projectPath = path.resolve(workingDir, projectName)
|
|
18
18
|
const projectPackageJson = path.join(projectPath, 'package.json')
|
|
19
19
|
const packageMetadata = require(projectPackageJson)
|
|
@@ -21,10 +21,7 @@ module.exports = async function (workingDir, projectName) {
|
|
|
21
21
|
const dependencies = packageMetadata.dependencies || []
|
|
22
22
|
const devDependencies = packageMetadata.devDependencies || []
|
|
23
23
|
|
|
24
|
-
if (
|
|
25
|
-
dependencies.length === 0 &&
|
|
26
|
-
devDependencies.length === 0
|
|
27
|
-
) {
|
|
24
|
+
if (dependencies.length === 0 && devDependencies.length === 0) {
|
|
28
25
|
log('⏭ - No dependencies. Skipping install step...')
|
|
29
26
|
|
|
30
27
|
return
|
|
@@ -20,16 +20,16 @@ const packageJsonScripts = {
|
|
|
20
20
|
start: 'extension-create start'
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
module.exports = async function (
|
|
23
|
+
module.exports = async function writePackageJson(
|
|
24
|
+
workingDir,
|
|
25
|
+
projectName,
|
|
26
|
+
template
|
|
27
|
+
) {
|
|
24
28
|
const projectPath = path.resolve(workingDir, projectName)
|
|
25
29
|
|
|
26
|
-
const templatePath = path.resolve(
|
|
27
|
-
templatesDir,
|
|
28
|
-
getTemplatePath(template)
|
|
29
|
-
)
|
|
30
|
+
const templatePath = path.resolve(templatesDir, getTemplatePath(template))
|
|
30
31
|
|
|
31
|
-
const templateJsonPath = path
|
|
32
|
-
.resolve(templatePath, 'template.json')
|
|
32
|
+
const templateJsonPath = path.resolve(templatePath, 'template.json')
|
|
33
33
|
|
|
34
34
|
const templateJson = require(templateJsonPath)
|
|
35
35
|
|
|
@@ -3,29 +3,25 @@
|
|
|
3
3
|
"version": "1.0",
|
|
4
4
|
"name": "Welcome Extension",
|
|
5
5
|
"description": "An extension to welcome you!",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
"chrome_url_overrides": {
|
|
29
|
-
"newtab": "newtab/newtab.html"
|
|
30
|
-
}
|
|
6
|
+
"icons": {
|
|
7
|
+
"16": "public/icon/test_16.png",
|
|
8
|
+
"32": "public/icon/test_32.png",
|
|
9
|
+
"48": "public/icon/test_48.png",
|
|
10
|
+
"64": "public/icon/test_64.png"
|
|
11
|
+
},
|
|
12
|
+
"permissions": ["tabs"],
|
|
13
|
+
"web_accessible_resources": ["public/*"],
|
|
14
|
+
"browser_action": {
|
|
15
|
+
"default_icon": {
|
|
16
|
+
"16": "public/icon/test_16.png",
|
|
17
|
+
"32": "public/icon/test_32.png",
|
|
18
|
+
"48": "public/icon/test_48.png",
|
|
19
|
+
"64": "public/icon/test_64.png"
|
|
20
|
+
},
|
|
21
|
+
"default_popup": "popup/popup.html",
|
|
22
|
+
"default_title": "Welcome Extension"
|
|
23
|
+
},
|
|
24
|
+
"chrome_url_overrides": {
|
|
25
|
+
"newtab": "newtab/newtab.html"
|
|
26
|
+
}
|
|
31
27
|
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
|
-
<meta charset="UTF-8"
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
5
|
<title>New tab page</title>
|
|
6
|
-
<link rel="preconnect" href="https://fonts.gstatic.com"
|
|
7
|
-
<link
|
|
8
|
-
|
|
6
|
+
<link rel="preconnect" href="https://fonts.gstatic.com" />
|
|
7
|
+
<link
|
|
8
|
+
href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@1,900&display=swap"
|
|
9
|
+
rel="stylesheet"
|
|
10
|
+
/>
|
|
11
|
+
<link rel="stylesheet" href="./styles.css" />
|
|
9
12
|
</head>
|
|
10
13
|
<body>
|
|
11
14
|
<div class="hello-box">
|
|
12
15
|
<header>
|
|
13
|
-
<img src="../public/puzzle.png" alt="A puzzle icon"
|
|
16
|
+
<img src="../public/puzzle.png" alt="A puzzle icon" />
|
|
14
17
|
<h1>Welcome to your extension</h1>
|
|
15
18
|
<p class="description loading">Browser extensions are 🙌🙌🙌</p>
|
|
16
19
|
</header>
|
|
@@ -16,7 +16,8 @@ body {
|
|
|
16
16
|
max-width: 600px;
|
|
17
17
|
padding: 40px;
|
|
18
18
|
margin: auto;
|
|
19
|
-
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
|
19
|
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
|
20
|
+
0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
img {
|
|
@@ -31,7 +32,6 @@ h1 {
|
|
|
31
32
|
color: #00214d;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
|
|
35
35
|
p {
|
|
36
36
|
font-family: 'Courier New';
|
|
37
37
|
font-size: 1.25rem;
|
package/develop/README.md
CHANGED
|
@@ -31,20 +31,18 @@ const startExtensionCLI = require('@extension-create/start')
|
|
|
31
31
|
|
|
32
32
|
const yourCreateProgram = program
|
|
33
33
|
|
|
34
|
-
yourCreateProgram
|
|
35
|
-
.version(packageJson.version)
|
|
34
|
+
yourCreateProgram.version(packageJson.version)
|
|
36
35
|
|
|
37
36
|
startExtensionCLI(yourCreateProgram)
|
|
38
37
|
|
|
39
|
-
yourCreateProgram
|
|
40
|
-
.parse(process.argv)
|
|
38
|
+
yourCreateProgram.parse(process.argv)
|
|
41
39
|
```
|
|
42
40
|
|
|
43
41
|
## Program options table
|
|
44
42
|
|
|
45
|
-
| Flag
|
|
46
|
-
|
|
47
|
-
| -m, --manifest
|
|
43
|
+
| Flag | Argument | What it does |
|
|
44
|
+
| -------------- | --------- | --------------------------------------------------------- |
|
|
45
|
+
| -m, --manifest | file path | Specify a custom path for your extensions's manifest file |
|
|
48
46
|
|
|
49
47
|
## Contributing
|
|
50
48
|
|
package/develop/module.js
CHANGED