Ejemplo n.º 1
0
 return xpi(manifest).then(function(filePath) {
   xpiPath = filePath;
   expect(fs.existsSync(path.join(updateRDFPath, "@simple-addon-1.0.0.update.rdf"))).to.equal(true);
   expect(fs.existsSync(path.join(updateRDFPath, "simple-addon.xpi"))).to.equal(true);
   //Removing the update.RDF file to make utils.compareDirs works
   fs.unlink(path.join(updateRDFPath, "@simple-addon-1.0.0.update.rdf"));
   return utils.unzipTo(xpiPath, tmpOutputDir).then(function() {
     utils.compareDirs(updateRDFPath, tmpOutputDir);
   });
 })
Ejemplo n.º 2
0
/**
* ## Prepares folder structure
* prepares the temporary folder structure
*
* @param {String} that - the ebook object
*
* @return {Boolean} success - returns whether the creation was successful or not
*/
function _prepareFolder(that) {
  debug(`folder structure will be prepared in temp folder`);
  // ## create temp folder
  // ## using existsSync and mkdirSync on purpose; might consider using async in the future
  fs.existsSync(that.tempPath) || fs.mkdirSync(that.tempPath);
  fs.existsSync(that.tempBookPath) || fs.mkdirSync(that.tempBookPath);
  // ## create temp book folder with subfolders
  fs.existsSync(`${that.tempBookPath}/META-INF`) || fs.mkdirSync(`${that.tempBookPath}/META-INF`);
  fs.existsSync(`${that.tempBookPath}/OEBPS`) || fs.mkdirSync(`${that.tempBookPath}/OEBPS`);
  fs.existsSync(`${that.tempBookPath}/OEBPS/images`) || fs.mkdirSync(`${that.tempBookPath}/OEBPS/images`);
  return true;
}
Ejemplo n.º 3
0
function loadCachedSizes () {
  if (fs.existsSync(cachedSizesFilename)) {
    return JSON.parse(fs.readFileSync(cachedSizesFilename, 'utf-8'))
  } else {
    return {}
  }
}
Ejemplo n.º 4
0
function filterOutOldImages(flags) {
	console.log(util.format('Task 5 of 6: Filtering out existing images', flags.length));
	
	return !fs.existsSync(imgPath)
		? flags
		: fs.readdir(imgPath)
				.then(files => flags.filter(f => files.indexOf(f.img) == -1));
}
Ejemplo n.º 5
0
function filterOutOldFlags(flags) {
	console.log('Task 3 of 5: Filtering out existing flags');
	
	return !fs.existsSync(metaPath)
		? flags
		: fs.readdir(metaPath)
				.then(files => flags.filter(f => files.indexOf(f.meta) == -1));
}
Ejemplo n.º 6
0
 return __awaiter(this, void 0, void 0, function* () {
     const dir = installDir(version);
     if (!(yield fsp.existsSync(dir))) {
         console.log(`Installing to ${dir}...`);
         yield fsp.mkdirp(dir);
         yield fsp.writeJson(path.join(dir, "package.json"), packageJson(version));
         yield execAndThrowErrors("npm install", dir);
         // Copy rules so they use the local typescript/tslint
         yield fsp.copy(path.join(__dirname, "rules"), path.join(dir, "rules"));
         console.log("Installed!");
     }
 });
Ejemplo n.º 7
0
};

const PACKAGE_JSON_PATH = function() {
  return path.resolve(
    process.cwd(),
    'node_modules',
    'react-native-update',
    'package.json'
  );
};

checkForVersionCommand();

let cli;
const cliPath = CLI_MODULE_PATH();
if (fs.existsSync(cliPath)) {
  cli = require(cliPath);
}

if (cli) {
  cli.run();
} else {
  console.error('Are you at home directory of a react-native project?');
  console.error('`pushy install` is under development, please run `npm install react-native-update` to install pushy manually.');
  process.exit(1);
}

function checkForVersionCommand() {
  if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') {
    console.log('react-native-update-cli: ' + require('../package.json').version);
    try {
Ejemplo n.º 8
0
 function(err) {
   expect(fs.existsSync(path.join(updateRDFFailPath, "@simple-addon-1.0.0.update.rdf"))).to.equal(false);
   expect(fs.existsSync(path.join(updateRDFFailPath, "simple-addon.xpi"))).to.equal(true);
   return;
 }
Ejemplo n.º 9
0
module.exports = coroutine(function*(req, res, flags, current, ignoredFiles) {
  const headers = {};

  if (flags.cors) {
    headers['Access-Control-Allow-Origin'] = '*';
    headers[
      'Access-Control-Allow-Headers'
    ] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
  }

  for (const header in headers) {
    if (!{}.hasOwnProperty.call(headers, header)) {
      continue;
    }

    res.setHeader(header, headers[header]);
  }

  if (flags.auth) {
    const credentials = auth(req);

    if (!process.env.SERVE_USER || !process.env.SERVE_PASSWORD) {
      console.error(
        red(
          'You are running serve with basic auth but did not set the SERVE_USER and SERVE_PASSWORD environment variables.'
        )
      );

      // eslint-disable-next-line unicorn/no-process-exit
      process.exit(1);
    }

    if (
      !credentials ||
      credentials.name !== process.env.SERVE_USER ||
      credentials.pass !== process.env.SERVE_PASSWORD
    ) {
      res.statusCode = 401;
      res.setHeader('WWW-Authenticate', 'Basic realm="User Visible Realm"');
      return micro.send(res, 401, 'Access Denied');
    }
  }

  const { pathname } = parse(req.url);
  const assetDir = path.normalize(process.env.ASSET_DIR);

  let related = path.parse(path.join(current, pathname));

  if (related.dir.indexOf(assetDir) > -1) {
    const relative = path.relative(assetDir, pathname);
    related = path.parse(path.join(__dirname, '/../assets', relative));
  }

  related = decodeURIComponent(path.format(related));

  const relatedExists = fs.existsSync(related);
  let notFoundResponse = 'Not Found';

  try {
    const custom404Path = path.join(current, '/404.html');
    notFoundResponse = yield fs.readFile(custom404Path, 'utf-8');
  } catch (err) {}

  if (!relatedExists && flags.single === undefined) {
    return micro.send(res, 404, notFoundResponse);
  }

  const streamOptions = {};

  if (flags.cache) {
    streamOptions.maxAge = flags.cache;
  }

  // Check if directory
  if (relatedExists && pathType.dirSync(related)) {
    // Normalize path to trailing slash
    // Otherwise problems like #70 will occur
    const url = parse(req.url);

    if (url.pathname.substr(-1) !== '/') {
      url.pathname += '/';
      const newPath = format(url);

      res.writeHead(302, {
        Location: newPath
      });

      res.end();
      return;
    }

    let indexPath = path.join(related, '/index.html');
    res.setHeader('Content-Type', mime.contentType(path.extname(indexPath)));

    if (!fs.existsSync(indexPath)) {
      // Try to render the current directory's content
      const port = flags.port || req.socket.localPort;
      const renderedDir = yield renderDirectory(
        port,
        current,
        related,
        ignoredFiles
      );

      // If it works, send the directory listing to the user
      if (renderedDir) {
        return micro.send(res, 200, renderedDir);
      }

      // And if it doesn't, see if it's a single page application
      // If that's not true either, send an error
      if (!flags.single) {
        return micro.send(res, 404, notFoundResponse);
      }

      // But IF IT IS true, load the SPA's root index file
      indexPath = path.join(current, '/index.html');
    }

    return stream(req, indexPath, streamOptions).pipe(res);
  }

  if (!fs.existsSync(related) && flags.single) {
    const indexPath = path.join(current, '/index.html');
    return stream(req, indexPath, streamOptions).pipe(res);
  }

  // Serve files without a mime type as text
  // eslint-disable-next-line camelcase
  stream.mime.default_type = 'text/plain';

  return stream(
    req,
    related,
    Object.assign(
      {
        dotfiles: 'allow'
      },
      streamOptions
    )
  ).pipe(res);
});