Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to choose which files to ignore #133

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: Node.js Unit Tests

on:
push:
branches:
- master
pull_request:

jobs:
build-front:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.allow-failure || false }}

strategy:
matrix:
Expand All @@ -30,6 +31,7 @@ jobs:

- name: Install and run tests
run: npm install-ci-test
continue-on-error: ${{ matrix.allow-failure || false }}

- name: Run CLI commands
run: |
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,23 @@ crx.load( path.resolve(__dirname, './myExtension') )
```

### ChromeExtension = require("crx")
### crx = new ChromeExtension(attrs)
### crx = new ChromeExtension(attrs?)

This module exports the `ChromeExtension` constructor directly, which can take an optional attribute object, which is used to extend the instance.

`attrs` is an optional object with advanced configuration elements:

```js
crx = new ChromeExtension({
// By default, we exclude bundling crx extensions within extensions
// You can change that, and ignore other files as well
ignore: ['*.crx']
// By default, it produces extensions compatible with CRX version 3 (since Chromium 64)
// CRX version 2 is for Chromium versions prior to 64
version: 3
})
```

### crx.load(path|files)

Prepares the temporary workspace for the Chrome Extension located at `path` — which is expected to directly contain `manifest.json`.
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const DEFAULTS = {
codebase: null,
path: null,
src: "**",
ignore: ["*.crx"],
version: 3,
};

Expand Down Expand Up @@ -157,7 +158,7 @@ class ChromeExtension {
.glob(selfie.src, {
cwd: selfie.path,
matchBase: true,
ignore: ["*.pem", ".git", "*.crx"]
ignore: ["*.pem", ".git"].concat(selfie.ignore)
})
.finalize();
});
Expand Down
24 changes: 23 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,28 @@ TESTS.writeFile = function(t, opts){
t.throws(() => crx.writeFile('/tmp/crx'));
};

TESTS.ignoreFiles = function(t, opts){
t.plan(1);

var crx = newCrx(Object.assign({
ignore: ['*.png']
}, opts));

crx.load().then(function(){
return crx.loadContents();
})
.then(function(packageData){
var entries = new Zip(packageData)
.getEntries()
.map(function(entry){
return entry.entryName;
})

t.deepEqual(entries, ['manifest.json']);
})
.catch(t.error.bind(t));
};

TESTS.loadContents = function(t, opts){
t.plan(3);

Expand Down Expand Up @@ -127,7 +149,7 @@ TESTS.generateUpdateXML = function(t, opts){
t.throws(() => new ChromeExtension({}).generateUpdateXML(), 'No URL provided for update.xml');

var crx = newCrx(opts);
var expected = crx.version === 2 ? updateXml2 : updateXml3;
var expected = crx.version === 2 ? updateXml2 : updateXml3;

crx.pack().then(function(){
var xmlBuffer = crx.generateUpdateXML();
Expand Down