-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
npm scripts to pack an extension (#35)
* add script to automatically generate zip file * fix wrong path * add missing file extension * rename JS script. separate npm script * fix using wrong path for manifest * Use base instead of name of parsed path * Pack a file into release directory * Print success message * Substitute string literals with variables * Update README * Update README.md * Create release folder if not exist * Remove chalk dependency * Show error message when failed to generate zip file --------- Co-authored-by: Seokseong Jeon <seokseong@jeon.engineer>
- Loading branch information
Showing
4 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ | |
.DS_Store | ||
|
||
npm-debug.log* | ||
|
||
# packed files | ||
/release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const { readFileSync, existsSync, mkdirSync } = require('fs'); | ||
const { parse, resolve } = require('path'); | ||
const AdmZip = require('adm-zip'); | ||
|
||
try { | ||
const { base } = parse(__dirname); | ||
const { version } = JSON.parse( | ||
readFileSync(resolve(__dirname, 'build', 'manifest.json'), 'utf8') | ||
); | ||
|
||
const outdir = 'release'; | ||
const filename = `${base}-v${version}.zip`; | ||
const zip = new AdmZip(); | ||
zip.addLocalFolder('build'); | ||
if (!existsSync(outdir)) { | ||
mkdirSync(outdir); | ||
} | ||
zip.writeZip(`${outdir}/${filename}`); | ||
|
||
console.log( | ||
`Success! Created a ${filename} file under ${outdir} directory. You can upload this file to web store.` | ||
); | ||
} catch (e) { | ||
console.error('Error! Failed to generate a zip file.'); | ||
} |