this.captureExecutionTime("Moving to results folder", 1, function () {
     fs.ensureDirSync(path.dirname(output_path));
     fs.renameSync(generated_path, output_path);
     fs.removeSync(FileHelpers.getTmpDirectory());
 });
Exemple #2
0
 readmes.forEach(readme => fse.renameSync(readme, path.join(path.dirname(readme), 'index.md')));
 static renameSync(from, to) {
   log.silly("renameSync", [from, to]);
   fs.renameSync(from, to);
 }
Exemple #4
0
 process.on('exit', () => {
   console.log('Restoring original compiler files');
   fs.renameSync(kmcompDestPath + '.bak', kmcompDestPath);
   fs.renameSync(kmcmpdllDestPath + '.bak', kmcmpdllDestPath);
 });
 }).on('end', function () {
   fs.renameSync('tmp/' + platform + extension + '.part', 'tmp/' + platform + extension);
   _this.log.ok('Node-webkit for ' + platform + ' downloaded');
   defer.resolve();
 }).on('error', function (error) {
Exemple #6
0
 .on('close', function () {
     fs.renameSync(localInstallerPath, installerPath);
     postMessageToBrackets(MessageIds.NOTIFY_DOWNLOAD_SUCCESS);
 });
Exemple #7
0
module.exports = function(appPath, appName, verbose, originalDirectory, template) {
  var ownPackageName = require(path.join(__dirname, '..', 'package.json')).name;
  var ownPath = path.join(appPath, 'node_modules', ownPackageName);
  var appPackage = require(path.join(appPath, 'package.json'));
  var useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));

  // Copy over some of the devDependencies
  appPackage.dependencies = appPackage.dependencies || {};
  appPackage.devDependencies = appPackage.devDependencies || {};

  // Setup the script rules
  appPackage.scripts = {
    'start': 'react-scripts start',
    'build': 'react-scripts build',
    'test': 'react-scripts test --env=jsdom',
    'eject': 'react-scripts eject'
  };

  fs.writeFileSync(
    path.join(appPath, 'package.json'),
    JSON.stringify(appPackage, null, 2)
  );

  var readmeExists = fs.existsSync(path.join(appPath, 'README.md'));
  if (readmeExists) {
    fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md'));
  }

  // Copy the files for the user
  var templatePath = template ? path.resolve(originalDirectory, template) : path.join(ownPath, 'template');
  if (fs.existsSync(templatePath)) {
    fs.copySync(templatePath, appPath);
  } else {
    console.error('Could not locate supplied template: ' + chalk.green(templatePath));
    return;
  }

  // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
  // See: https://github.com/npm/npm/issues/1862
  fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), [], function (err) {
    if (err) {
      // Append if there's already a `.gitignore` file there
      if (err.code === 'EEXIST') {
        var data = fs.readFileSync(path.join(appPath, 'gitignore'));
        fs.appendFileSync(path.join(appPath, '.gitignore'), data);
        fs.unlinkSync(path.join(appPath, 'gitignore'));
      } else {
        throw err;
      }
    }
  });

  // Run yarn or npm for react and react-dom
  // TODO: having to do two npm/yarn installs is bad, can we avoid it?
  var command;
  var args;

  if (useYarn) {
    command = 'yarnpkg';
    args = ['add'];
  } else {
    command = 'npm';
    args = [
      'install',
      '--save',
      verbose && '--verbose'
    ].filter(function(e) { return e; });
  }
  args.push('react', 'react-dom');

  // Install additional template dependencies, if present
  var templateDependenciesPath = path.join(appPath, '.template.dependencies.json');
  if (fs.existsSync(templateDependenciesPath)) {
    var templateDependencies = require(templateDependenciesPath).dependencies;
    args = args.concat(Object.keys(templateDependencies).map(function (key) {
      return key + '@' + templateDependencies[key];
    }));
    fs.unlinkSync(templateDependenciesPath);
  }

  console.log('Installing react and react-dom using ' + command + '...');
  console.log();

  var proc = spawn(command, args, {stdio: 'inherit'});
  proc.on('close', function (code) {
    if (code !== 0) {
      console.error('`' + command + ' ' + args.join(' ') + '` failed');
      return;
    }

    // Display the most elegant way to cd.
    // This needs to handle an undefined originalDirectory for
    // backward compatibility with old global-cli's.
    var cdpath;
    if (originalDirectory &&
        path.join(originalDirectory, appName) === appPath) {
      cdpath = appName;
    } else {
      cdpath = appPath;
    }

    console.log();
    console.log('Success! Created ' + appName + ' at ' + appPath);
    console.log('Inside that directory, you can run several commands:');
    console.log();
    console.log(chalk.cyan('  ' + command + ' start'));
    console.log('    Starts the development server.');
    console.log();
    console.log(chalk.cyan('  ' + command + ' run build'));
    console.log('    Bundles the app into static files for production.');
    console.log();
    console.log(chalk.cyan('  ' + command + ' test'));
    console.log('    Starts the test runner.');
    console.log();
    console.log(chalk.cyan('  ' + command + ' run eject'));
    console.log('    Removes this tool and copies build dependencies, configuration files');
    console.log('    and scripts into the app directory. If you do this, you can’t go back!');
    console.log();
    console.log('We suggest that you begin by typing:');
    console.log();
    console.log(chalk.cyan('  cd'), cdpath);
    console.log('  ' + chalk.cyan(command + ' start'));
    if (readmeExists) {
      console.log();
      console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`'));
    }
    console.log();
    console.log('Happy hacking!');
  });
};
Exemple #8
0
	router.post('/data/upload', function(req, res) {
		i18nm.setLocale(req.session.current_locale);
		var rep = {};
		// Check authorization
		if (!req.session.auth || req.session.auth.status < 2) {
			rep.status = 0;
			rep.error = i18nm.__("unauth");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!req.files || !req.files.file) {
			rep.status = 0;
			rep.error = i18nm.__("no_file_sent");
			res.send(JSON.stringify(rep));
			return;
		}
		var file = req.files.file;
		if (file.size > app.get('config').max_upload_file_mb * 1048576) {
			rep.status = 0;
			rep.error = i18nm.__("file_too_big");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!check_filename(file.originalname)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_filename_syntax");
			res.send(JSON.stringify(rep));
			return;
		}
		var dir = req.body.dir;
		if (dir && !check_directory(dir)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_dir");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!dir) {
			dir = '';
		} else {
			dir = '/' + dir;
		}
		dir = app.get('config').dir.storage + dir;
		if (!fs.existsSync(dir)) {
			rep.status = 0;
			rep.error = i18nm.__("dir_not_exists");
			res.send(JSON.stringify(rep));
			return;
		}
		var cr = fs.renameSync(app.get('config').dir.tmp + '/' + file.name, dir + '/' + file.originalname);
		if (cr) {
			rep.status = 0;
			rep.error = i18nm.__("upload_failed");
			res.send(JSON.stringify(rep));
			return;
		}
		// Create thumbnail if GM is available
		if (gm && (file.mimetype == 'image/png' || file.mimetype == 'image/jpeg')) {
			var md5 = crypto.createHash('md5');
			var fn = md5.update(file.originalname).digest('hex');
			var img = gm(dir + '/' + file.originalname);
			img.autoOrient();
			img.size(function(err, size) {
				if (!err) {
					if (size.width >= size.height) {
						img.resize(null, 70);
						img.crop(70, 70, 0, 0);
					} else {
						img.resize(70, null);
						img.crop(70, 70, 0, 0);
					}
					img.setFormat('jpeg');
					img.write(dir + '/___thumb_' + fn + '.jpg', function(err) {
						// OK, we don't care
					});
				}
			});
		}
		rep.status = 1;
		res.send(JSON.stringify(rep));
		return;
	});
Exemple #9
0
	router.post('/data/paste', function(req, res) {
		i18nm.setLocale(req.session.current_locale);
		var rep = {};
		// Check authorization
		if (!req.session.auth || req.session.auth.status < 2) {
			rep.status = 0;
			rep.error = i18nm.__("unauth");
			res.send(JSON.stringify(rep));
			return;
		}
		var clpbrd = req.body.clipboard;
		if (!clpbrd || !clpbrd.files || !clpbrd.files.length || !clpbrd.mode || (clpbrd.mode != 'copy' && clpbrd.mode != 'cut')) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_request");
			res.send(JSON.stringify(rep));
			return;
		}
		for (var i = 0; i < clpbrd.files.length; i++) {
			if (!check_filename(clpbrd.files[i])) {
				rep.status = 0;
				rep.error = i18nm.__("invalid_request");
				res.send(JSON.stringify(rep));
				return;
			}
		}
		var source_dir = clpbrd.dir;
		if (source_dir && !check_directory(source_dir)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_dir");
			res.send(JSON.stringify(rep));
			return;
		}
		var dest_dir = req.body.dest;
		if (dest_dir && !check_directory(dest_dir)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_dir");
			res.send(JSON.stringify(rep));
			return;
		}
		if (source_dir == dest_dir) {
			rep.status = 0;
			rep.error = i18nm.__("cannot_paste_to_source_dir");
			res.send(JSON.stringify(rep));
			return;
		}
		for (var j = 0; j < clpbrd.files.length; j++) {
			var _fn = clpbrd.dir + '/' + clpbrd.files[j];
			if (_fn.match(/^\//)) _fn = _fn.replace(/^\//, '');
			var rex1 = new RegExp('^' + _fn + '\/');
			var rex2 = new RegExp('^' + _fn + '$');
			if (dest_dir.match(rex1) || dest_dir.match(rex2)) {
				rep.status = 0;
				rep.error = i18nm.__("cannot_paste_to_itself");
				res.send(JSON.stringify(rep));
				return;
			}
		}
		if (!source_dir) {
			source_dir = '';
		} else {
			source_dir = '/' + source_dir;
		}
		source_dir = app.get('config').dir.storage + source_dir;
		if (!fs.existsSync(source_dir)) {
			rep.status = 0;
			rep.error = i18nm.__("dir_not_exists");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!dest_dir) {
			dest_dir = '';
		} else {
			dest_dir = '/' + dest_dir;
		}
		dest_dir = app.get('config').dir.storage + dest_dir;
		if (!fs.existsSync(dest_dir)) {
			rep.status = 0;
			rep.error = i18nm.__("dir_not_exists");
			res.send(JSON.stringify(rep));
			return;
		}
		var ure = false;
		source_dir = source_dir.replace(/\/\//g, '/');
		dest_dir = dest_dir.replace(/\/\//g, '/');
		for (var k = 0; k < clpbrd.files.length; k++) {
			var src = source_dir + '/' + clpbrd.files[k];
			if (!fs.existsSync(src)) {
				rep.status = 0;
				rep.error = i18nm.__("dir_or_file_not_exists");
				res.send(JSON.stringify(rep));
				return;
			}
			var dst = dest_dir + '/' + clpbrd.files[k];
			if (src == dst || src == dest_dir) {
				rep.status = 0;
				rep.error = i18nm.__("cannot_paste_to_itself");
				res.send(JSON.stringify(rep));
				return;
			}
			var stat = fs.statSync(src);
			var ur;
			if (stat.isFile() || stat.isDirectory()) {
				if (stat.isFile()) {
					var _ur;
					if (clpbrd.mode == 'cut') {
						_ur = fs.renameSync(src, dst);
					} else {
						_ur = fs.copySync(src, dst);
					}
					ur = _ur;
				} else {
					var _ur1 = fs.copySync(src, dst);
					ur = _ur1;
					if (clpbrd.mode == 'cut' && !_ur1) {
						fs.removeSync(src);
					}
				}
			}
			var fn = crypto.createHash('md5').update(clpbrd.files[k]).digest('hex');
			if (fs.existsSync(source_dir + '/___thumb_' + fn + '.jpg')) {
				if (clpbrd.mode == 'cut') {
					fs.renameSync(source_dir + '/___thumb_' + fn + '.jpg', dest_dir + '/___thumb_' + fn + '.jpg');
				} else {
					fs.copySync(source_dir + '/___thumb_' + fn + '.jpg', dest_dir + '/___thumb_' + fn + '.jpg');
				}
			}
			if (ur) ure = true;
		}
		rep.status = 1;
		res.send(JSON.stringify(rep));
		return;
	});
Exemple #10
0
	router.post('/data/rename', function(req, res) {
		i18nm.setLocale(req.session.current_locale);
		var rep = {};
		// Check authorization
		if (!req.session.auth || req.session.auth.status < 2) {
			rep.status = 0;
			rep.error = i18nm.__("unauth");
			res.send(JSON.stringify(rep));
			return;
		}
		var old_filename = req.body.old_filename;
		var new_filename = req.body.new_filename;
		var req_dir = req.body.dir;
		if (req_dir && !check_directory(req_dir)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_dir");
			res.send(JSON.stringify(rep));
			return;
		}
		if (req_dir) {
			req_dir = '/' + req_dir;
		} else {
			req_dir = '';
		}
		var dir = app.get('config').dir.storage + req_dir;
		if (!fs.existsSync(dir)) {
			rep.status = 0;
			rep.error = i18nm.__("dir_not_exists");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!check_filename(old_filename) || !check_filename(new_filename)) {
			rep.status = 0;
			rep.error = i18nm.__("invalid_filename_syntax");
			res.send(JSON.stringify(rep));
			return;
		}
		if (old_filename == new_filename) {
			rep.status = 0;
			rep.error = i18nm.__("cannot_rename_same");
			res.send(JSON.stringify(rep));
			return;
		}
		if (!fs.existsSync(dir + '/' + old_filename)) {
			rep.status = 0;
			rep.error = i18nm.__("file_not_exists");
			res.send(JSON.stringify(rep));
			return;
		}
		if (fs.existsSync(dir + '/' + new_filename)) {
			rep.status = 0;
			rep.error = i18nm.__("cannot_rename_same");
			res.send(JSON.stringify(rep));
			return;
		}
		var cr = fs.renameSync(dir + '/' + old_filename, dir + '/' + new_filename);
		var fn = crypto.createHash('md5').update(old_filename).digest('hex');
		if (fs.existsSync(dir + '/___thumb_' + fn + '.jpg')) {
			var nf = crypto.createHash('md5').update(new_filename).digest('hex');
			fs.renameSync(dir + '/___thumb_' + fn + '.jpg', dir + '/___thumb_' + nf + '.jpg');
		}
		if (cr) {
			rep.status = 0;
			rep.error = i18nm.__("rename_error");
			res.send(JSON.stringify(rep));
			return;
		}
		rep.status = 1;
		res.send(JSON.stringify(rep));
	});
Exemple #11
0
module.exports = function(
  appPath,
  appName,
  verbose,
  originalDirectory,
  template
) {
  const ownPackageName = require(path.join(__dirname, '..', 'package.json'))
    .name;
  const ownPath = path.join(appPath, 'node_modules', ownPackageName);
  const appPackage = require(path.join(appPath, 'package.json'));
  const useYarn = fs.existsSync(path.join(appPath, 'yarn.lock'));

  // Copy over some of the devDependencies
  appPackage.dependencies = appPackage.dependencies || {};

  // Setup the script rules
  appPackage.scripts = {
    start: 'react-scripts start',
    build: 'react-scripts build',
    test: 'react-scripts test --env=jsdom',
    eject: 'react-scripts eject'
  };

  fs.writeFileSync(
    path.join(appPath, 'package.json'),
    JSON.stringify(appPackage, null, 2)
  );

  const readmeExists = fs.existsSync(path.join(appPath, 'README.md'));
  if (readmeExists) {
    fs.renameSync(
      path.join(appPath, 'README.md'),
      path.join(appPath, 'README.old.md')
    );
  }

  // Copy the files for the user
  const templatePath = template
    ? path.resolve(originalDirectory, template)
    : path.join(ownPath, 'template');
  if (fs.existsSync(templatePath)) {
    fs.copySync(templatePath, appPath);
  } else {
    console.error(
      `Could not locate supplied template: ${chalk.green(templatePath)}`
    );
    return;
  }

  // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
  // See: https://github.com/npm/npm/issues/1862
  fs.move(
    path.join(appPath, 'gitignore'),
    path.join(appPath, '.gitignore'),
    [],
    err => {
      if (err) {
        // Append if there's already a `.gitignore` file there
        if (err.code === 'EEXIST') {
          const data = fs.readFileSync(path.join(appPath, 'gitignore'));
          fs.appendFileSync(path.join(appPath, '.gitignore'), data);
          fs.unlinkSync(path.join(appPath, 'gitignore'));
        } else {
          throw err;
        }
      }
    }
  );

  let command;
  let args;

  if (useYarn) {
    command = 'yarnpkg';
    args = ['add', '--dev'];
  } else {
    command = 'npm';
    args = ['install', '--save-dev', verbose && '--verbose'].filter(e => e);
  }

  // Install additional template dependencies, if present
  const templateDependenciesPath = path.join(
    appPath,
    '.template.dependencies.json'
  );
  if (fs.existsSync(templateDependenciesPath)) {
    const templateDependencies = require(templateDependenciesPath).dependencies;
    args = args.concat(
      Object.keys(templateDependencies).map(key => {
        return `${key}@${templateDependencies[key]}`;
      })
    );
    fs.unlinkSync(templateDependenciesPath);
  }

  // Install devDependencies needed by Reason
  const reasonDevDeps = [
    'bs-platform',
    'reason-react',
    'bs-jest'
  ];

  const extraDevDeps = [
    ...args,
    ...reasonDevDeps
  ];

  const installMessage = 'Installing ' +
    reasonDevDeps.slice(0, -1).map(dep => chalk.blue(dep)).join(', ') +
    ', and ' +
    chalk.blue(reasonDevDeps[reasonDevDeps.length - 1]) +
    ' using ' + command + '...'

  console.log(installMessage);
  console.log();
  const devDepsProc = spawn.sync(command, extraDevDeps, { stdio: 'inherit' });
  if (devDepsProc.status !== 0) {
    console.error(`\`${command} ${extraDevDeps.join(' ')}\` failed`);
    return;
  }

  // Display the most elegant way to cd.
  // This needs to handle an undefined originalDirectory for
  // backward compatibility with old global-cli's.
  let cdpath;
  if (originalDirectory && path.join(originalDirectory, appName) === appPath) {
    cdpath = appName;
  } else {
    cdpath = appPath;
  }

  // Change displayed command to yarn instead of yarnpkg
  const displayedCommand = useYarn ? 'yarn' : 'npm';

  console.log();
  console.log(`Success! Created ${appName} at ${appPath}`);
  console.log('Inside that directory, you can run several commands:');
  console.log();
  console.log(chalk.cyan(`  ${displayedCommand} start`));
  console.log('    Starts the development server.');
  console.log();
  console.log(
    chalk.cyan(`  ${displayedCommand} ${useYarn ? '' : 'run '}build`)
  );
  console.log('    Bundles the app into static files for production.');
  console.log();
  console.log(chalk.cyan(`  ${displayedCommand} test`));
  console.log('    Starts the test runner.');
  console.log();
  console.log(
    chalk.cyan(`  ${displayedCommand} ${useYarn ? '' : 'run '}eject`)
  );
  console.log(
    '    Removes this tool and copies build dependencies, configuration files'
  );
  console.log(
    '    and scripts into the app directory. If you do this, you can’t go back!'
  );
  console.log();
  console.log('We suggest that you begin by typing:');
  console.log();
  console.log(chalk.cyan('  cd'), cdpath);
  console.log(`  ${chalk.cyan(`${displayedCommand} start`)}`);
  if (readmeExists) {
    console.log();
    console.log(
      chalk.yellow(
        'You had a `README.md` file, we renamed it to `README.old.md`'
      )
    );
  }
  console.log();
  console.log('Happy hacking!');
};
Exemple #12
0
module.exports = function(appPath, appName, verbose, originalDirectory) {
  var ownPath = path.join(appPath, 'node_modules', 'preact-scripts');

  var appPackage = require(path.join(appPath, 'package.json'));
  var ownPackage = require(path.join(ownPath, 'package.json'));

  // Copy over some of the devDependencies
  appPackage.dependencies = appPackage.dependencies || {};
  appPackage.devDependencies = appPackage.devDependencies || {};
  ['preact'].forEach(function (key) {
    appPackage.dependencies[key] = ownPackage.devDependencies[key];
  });
  ['react-test-renderer'].forEach(function (key) {
    appPackage.devDependencies[key] = ownPackage.devDependencies[key];
  });

  // Setup the script rules
  appPackage.scripts = {};
  ['start', 'build', 'eject', 'test'].forEach(function(command) {
    appPackage.scripts[command] = 'preact-scripts ' + command;
  });

  // explicitly specify ESLint config path for editor plugins
  appPackage.eslintConfig = {
    extends: './node_modules/preact-scripts/config/eslint.js',
  };

  fs.writeFileSync(
    path.join(appPath, 'package.json'),
    JSON.stringify(appPackage, null, 2)
  );

  var readmeExists = pathExists.sync(path.join(appPath, 'README.md'));
  if (readmeExists) {
    fs.renameSync(path.join(appPath, 'README.md'), path.join(appPath, 'README.old.md'));
  }

  // Copy the files for the user
  fs.copySync(path.join(ownPath, 'template'), appPath);

  // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
  // See: https://github.com/npm/npm/issues/1862
  fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), [], function (err) {
    if (err) {
      // Append if there's already a `.gitignore` file there
      if (err.code === 'EEXIST') {
        var data = fs.readFileSync(path.join(appPath, 'gitignore'));
        fs.appendFileSync(path.join(appPath, '.gitignore'), data);
        fs.unlinkSync(path.join(appPath, 'gitignore'));
      } else {
        throw err;
      }
    }
  });

  // Run another npm install for preact
  console.log('Installing preact from npm...');
  console.log();
  // TODO: having to do two npm installs is bad, can we avoid it?
  var args = [
    'install',
    verbose && '--verbose'
  ].filter(function(e) { return e; });
  var proc = spawn('npm', args, {stdio: 'inherit'});
  proc.on('close', function (code) {
    if (code !== 0) {
      console.error('`npm ' + args.join(' ') + '` failed');
      return;
    }

    // Display the most elegant way to cd.
    // This needs to handle an undefined originalDirectory for
    // backward compatibility with old global-cli's.
    var cdpath;
    if (originalDirectory &&
        path.join(originalDirectory, appName) === appPath) {
      cdpath = appName;
    } else {
      cdpath = appPath;
    }

    console.log();
    console.log('Success! Created ' + appName + ' at ' + appPath + '.');
    console.log('Inside that directory, you can run several commands:');
    console.log();
    console.log('  * npm start: Starts the development server.');
    console.log('  * npm run build: Bundles the app into static files for production.');
    console.log('  * npm run eject: Removes this tool. If you do this, you can’t go back!');
    console.log();
    console.log('We suggest that you begin by typing:');
    console.log();
    console.log('  cd', cdpath);
    console.log('  npm start');
    if (readmeExists) {
      console.log();
      console.log(chalk.yellow('You had a `README.md` file, we renamed it to `README.old.md`'));
    }
    console.log();
    console.log('Happy hacking!');
  });
};