mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
parent
8c37b54e7e
commit
c08f1447bb
60
bin/puppeteer.js
Executable file
60
bin/puppeteer.js
Executable 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
47
index.js
Executable file → Normal file
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
/**
|
/**
|
||||||
* Copyright 2017 Google Inc. All rights reserved.
|
* Copyright 2017 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -15,46 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var vm = require('vm');
|
module.exports = {
|
||||||
var fs = require('fs');
|
Browser: require('./lib/Browser')
|
||||||
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);
|
|
||||||
|
16
install.js
16
install.js
@ -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 Downloader = require('./lib/Downloader');
|
||||||
var revision = require('./package').puppeteer.chromium_revision;
|
var revision = require('./package').puppeteer.chromium_revision;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
"rimraf": "^2.6.1"
|
"rimraf": "^2.6.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"puppeteer": "index.js"
|
"puppeteer": "./bin/puppeteer.js"
|
||||||
},
|
},
|
||||||
"puppeteer": {
|
"puppeteer": {
|
||||||
"chromium_revision": "471584"
|
"chromium_revision": "471584"
|
||||||
|
Loading…
Reference in New Issue
Block a user