Skip to content

Commit b8030f3

Browse files
committed
Make icons optional
In case the user wants to put their icons in a custom location or already wants to use their own method of copying them. For example, the user may put their icons in the public folder which already has a copying system in place.
1 parent 3ac1c1a commit b8030f3

File tree

8 files changed

+50
-35
lines changed

8 files changed

+50
-35
lines changed

generator/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ module.exports = (api, _options) => {
9696
api.render('./template/content-script', { ...options })
9797
}
9898

99+
if (options.components.icons) {
100+
api.render('./template/icons', { name, ...options })
101+
}
102+
99103
api.onCreateComplete(() => {
100104
const gitignore = fs.readFileSync(api.resolve('./.gitignore'), 'utf8')
101105
fs.writeFileSync(api.resolve('./.gitignore'), gitignore + gitignoreSnippet)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,47 @@ module.exports = (api, options) => {
6161
}
6262
}
6363

64-
webpackConfig.plugins.push(new CopyWebpackPlugin([
65-
{ from: './src/icons', to: 'icons/[name].[ext]', ignore: ['icon.xcf'] },
66-
{
67-
from: './src/manifest.json',
68-
to: 'manifest.json',
69-
transform: (content) => {
70-
return new Promise((resolve, reject) => {
71-
const jsonContent = JSON.parse(content)
72-
jsonContent.version = version
73-
74-
if (isProduction) {
75-
return resolve(JSON.stringify(jsonContent, null, 2))
76-
}
77-
78-
jsonContent.content_security_policy = "script-src 'self' 'unsafe-eval'; object-src 'self'"
79-
80-
try {
81-
fs.statSync(keyFile)
82-
83-
return exec(`openssl rsa -in ${keyFile} -pubout -outform DER | openssl base64 -A`, (error, stdout) => {
84-
if (error) {
85-
// node couldn't execute the command
86-
reject(error)
87-
}
88-
89-
jsonContent.key = stdout
90-
resolve(JSON.stringify(jsonContent, null, 2))
91-
})
92-
} catch (error) {
93-
logger.warn('No key.pem file found. This is fine for dev, however you may have problems publishing without one')
64+
const toCopy = []
65+
66+
if (options.components.icons) {
67+
toCopy.push({ from: './src/icons', to: 'icons/[name].[ext]', ignore: ['icon.xcf'] })
68+
}
69+
70+
toCopy.push({
71+
from: './src/manifest.json',
72+
to: 'manifest.json',
73+
transform: (content) => {
74+
return new Promise((resolve, reject) => {
75+
const jsonContent = JSON.parse(content)
76+
jsonContent.version = version
77+
78+
if (isProduction) {
79+
return resolve(JSON.stringify(jsonContent, null, 2))
80+
}
81+
82+
jsonContent.content_security_policy = "script-src 'self' 'unsafe-eval'; object-src 'self'"
83+
84+
try {
85+
fs.statSync(keyFile)
86+
87+
return exec(`openssl rsa -in ${keyFile} -pubout -outform DER | openssl base64 -A`, (error, stdout) => {
88+
if (error) {
89+
// node couldn't execute the command
90+
reject(error)
91+
}
92+
93+
jsonContent.key = stdout
9494
resolve(JSON.stringify(jsonContent, null, 2))
95-
}
96-
})
97-
}
95+
})
96+
} catch (error) {
97+
logger.warn('No key.pem file found. This is fine for dev, however you may have problems publishing without one')
98+
resolve(JSON.stringify(jsonContent, null, 2))
99+
}
100+
})
98101
}
99-
]))
102+
})
103+
104+
webpackConfig.plugins.push(new CopyWebpackPlugin(toCopy))
100105

101106
if (isProduction) {
102107
webpackConfig.plugins.push(new ZipPlugin({

prompts.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = [
22
{
33
name: 'components',
44
type: 'checkbox',
5-
defaults: ['popup', 'background'],
5+
defaults: ['popup', 'background', 'icons'],
66
message: 'Which browser extension components do you wish to generate?',
77
choices: [
88
{
@@ -36,6 +36,12 @@ module.exports = [
3636
// name: 'Dev Tools Tab',
3737
// value: 'devTools',
3838
// short: 'dev tools'
39+
},
40+
{
41+
name: 'Icons',
42+
value: 'icons',
43+
short: 'icons',
44+
checked: true
3945
}
4046
],
4147
filter: async (input) => {

0 commit comments

Comments
 (0)