Slight code restructuring

This patch:
- moves phantom shim shell into a bin/ folder
- introduces a new root index.js which exposes Browser to the
  dependent modules
- adds forgotten LICENSE header to the install.js
This commit is contained in:
Andrey Lushnikov 2017-05-14 23:26:37 -07:00
parent 8c37b54e7e
commit c08f1447bb
4 changed files with 80 additions and 45 deletions

60
bin/puppeteer.js Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env node
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var vm = require('vm');
var fs = require('fs');
var path = require('path');
var Puppeteer = require('..').Browser;
var argv = require('minimist')(process.argv.slice(2), {
alias: { v: 'version' },
boolean: ['headless'],
default: {'headless': true },
});
if (argv.version) {
console.log('Puppeteer v' + require('./package.json').version);
return;
}
if (argv['ssl-certificates-path']) {
console.error('Flag --ssl-certificates-path is not supported.');
process.exit(1);
return;
}
var scriptArguments = argv._;
if (!scriptArguments.length) {
console.log('puppeteer [scriptfile]');
return;
}
var scriptPath = path.resolve(process.cwd(), scriptArguments[0]);
if (!fs.existsSync(scriptPath)) {
console.error(`script not found: ${scriptPath}`);
process.exit(1);
return;
}
var browser = new Browser({
remoteDebuggingPort: 9229,
headless: argv.headless,
});
var PhatomJs = require('./phantomjs');
var context = PhatomJs.createContext(browser, scriptPath, argv);
var scriptContent = fs.readFileSync(scriptPath, 'utf8');
vm.runInContext(scriptContent, context);

47
index.js Executable file → Normal file
View File

@ -1,4 +1,3 @@
#!/usr/bin/env node
/**
* Copyright 2017 Google Inc. All rights reserved.
*
@ -15,46 +14,6 @@
* limitations under the License.
*/
var vm = require('vm');
var fs = require('fs');
var path = require('path');
var Browser = require('./lib/Browser');
var argv = require('minimist')(process.argv.slice(2), {
alias: { v: 'version' },
boolean: ['headless'],
default: {'headless': true },
});
if (argv.version) {
console.log('Puppeteer v' + require('./package.json').version);
return;
}
if (argv['ssl-certificates-path']) {
console.error('Flag --ssl-certificates-path is not currently supported.\nMore information at https://github.com/aslushnikov/puppeteer/issues/1');
process.exit(1);
return;
}
var scriptArguments = argv._;
if (!scriptArguments.length) {
console.log('puppeteer [scriptfile]');
return;
}
var scriptPath = path.resolve(process.cwd(), scriptArguments[0]);
if (!fs.existsSync(scriptPath)) {
console.error(`script not found: ${scriptPath}`);
process.exit(1);
return;
}
var browser = new Browser({
remoteDebuggingPort: 9229,
headless: argv.headless,
});
var PhatomJs = require('./phantomjs');
var context = PhatomJs.createContext(browser, scriptPath, argv);
var scriptContent = fs.readFileSync(scriptPath, 'utf8');
vm.runInContext(scriptContent, context);
module.exports = {
Browser: require('./lib/Browser')
};

View File

@ -1,3 +1,19 @@
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Downloader = require('./lib/Downloader');
var revision = require('./package').puppeteer.chromium_revision;
var fs = require('fs');

View File

@ -22,7 +22,7 @@
"rimraf": "^2.6.1"
},
"bin": {
"puppeteer": "index.js"
"puppeteer": "./bin/puppeteer.js"
},
"puppeteer": {
"chromium_revision": "471584"