-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support gcloudignore * fixlint * use posix path
- Loading branch information
1 parent
c99cb30
commit bc4a13e
Showing
13 changed files
with
3,514 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
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 @@ | ||
data |
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,10 @@ | ||
/** | ||
* Responds to any HTTP request. | ||
* | ||
* @param {!express:Request} req HTTP request context. | ||
* @param {!express:Response} res HTTP response context. | ||
*/ | ||
exports.helloWorld = (req, res) => { | ||
let message = req.query.message || req.body.message || 'Hello World!!'; | ||
res.status(200).send(message); | ||
}; |
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 @@ | ||
baz |
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,4 @@ | ||
{ | ||
"name": "sample-http", | ||
"version": "0.0.1" | ||
} |
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 @@ | ||
*.txt |
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 @@ | ||
foo |
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,10 @@ | ||
/** | ||
* Responds to any HTTP request. | ||
* | ||
* @param {!express:Request} req HTTP request context. | ||
* @param {!express:Response} res HTTP response context. | ||
*/ | ||
exports.helloWorld = (req, res) => { | ||
let message = req.query.message || req.body.message || 'Hello World!!'; | ||
res.status(200).send(message); | ||
}; |
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,4 @@ | ||
{ | ||
"name": "sample-http", | ||
"version": "0.0.1" | ||
} |
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,94 @@ | ||
import { expect } from 'chai'; | ||
import os from 'os'; | ||
import * as fs from 'fs'; | ||
import 'mocha'; | ||
import * as path from 'path'; | ||
import { zipDir } from '../src/util'; | ||
import StreamZip from 'node-stream-zip'; | ||
|
||
const testDirNoIgnore = 'tests/test-node-func'; | ||
const testDirSimpleIgnore = 'tests/test-func-ignore'; | ||
const testDirNodeIgnore = 'tests/test-func-ignore-node'; | ||
const name = `zip-${Math.round(Math.random() * 100000)}`; | ||
describe('Zip', function () { | ||
it('creates a zipfile with correct files without gcloudignore', async function () { | ||
const zf = await zipDir( | ||
testDirNoIgnore, | ||
path.posix.join(os.tmpdir(), name), | ||
); | ||
const uzf = new StreamZip.async({ file: zf }); | ||
const filesInsideZip = await uzf.entries(); | ||
const expectedFiles = getNonIgnoredFiles(testDirNoIgnore, testDirNoIgnore); | ||
expect(await uzf.entriesCount).equal(expectedFiles.length); | ||
for (const entry of Object.values(filesInsideZip)) { | ||
expect(expectedFiles).to.be.include(entry.name); | ||
} | ||
}); | ||
|
||
it('creates a zipfile with correct files with simple gcloudignore', async function () { | ||
const zf = await zipDir( | ||
testDirSimpleIgnore, | ||
path.posix.join(os.tmpdir(), name), | ||
); | ||
const uzf = new StreamZip.async({ file: zf }); | ||
const filesInsideZip = await uzf.entries(); | ||
const expectedFiles = getNonIgnoredFiles( | ||
testDirSimpleIgnore, | ||
testDirSimpleIgnore, | ||
new Set(['ignore.txt', '.gcloudignore']), | ||
); | ||
expect(await uzf.entriesCount).equal(expectedFiles.length); | ||
for (const entry of Object.values(filesInsideZip)) { | ||
expect(expectedFiles).to.be.include(entry.name); | ||
} | ||
}); | ||
|
||
it('creates a zipfile with correct files with dir gcloudignore', async function () { | ||
const zf = await zipDir( | ||
testDirNodeIgnore, | ||
path.posix.join(os.tmpdir(), name), | ||
); | ||
const uzf = new StreamZip.async({ file: zf }); | ||
const filesInsideZip = await uzf.entries(); | ||
const expectedFiles = getNonIgnoredFiles( | ||
testDirNodeIgnore, | ||
testDirNodeIgnore, | ||
new Set([ | ||
'node_modules/foo/foo.txt', | ||
'node_modules/bar/bar.txt', | ||
'.gcloudignore', | ||
]), | ||
); | ||
expect(await uzf.entriesCount).equal(expectedFiles.length); | ||
for (const entry of Object.values(filesInsideZip)) { | ||
expect(expectedFiles).to.be.include(entry.name); | ||
} | ||
}); | ||
}); | ||
|
||
function getNonIgnoredFiles( | ||
parentDir: string, | ||
directory: string, | ||
ignore: Set<string> = new Set(), | ||
fileList: string[] = [], | ||
): string[] { | ||
const items = fs.readdirSync(directory); | ||
for (const item of items) { | ||
const stat = fs.statSync(path.posix.join(directory, item)); | ||
if (stat.isDirectory()) | ||
fileList = getNonIgnoredFiles( | ||
parentDir, | ||
path.posix.join(directory, item), | ||
ignore, | ||
fileList, | ||
); | ||
else { | ||
const fPath = path.posix.relative( | ||
parentDir, | ||
path.posix.join(directory, item), | ||
); | ||
if (!ignore.has(fPath)) fileList.push(fPath); | ||
} | ||
} | ||
return fileList; | ||
} |