This code provides a function to format code within a project directory using WebStorm and potentially import project settings from a .idea
directory.
npm run import -- "delint using webstorm"
// TODO: display a tree of require dependencies and make sure it all still compiles properly
var path = require('path');
var {ncp} = require('ncp');
var importer = require('../Core');
var execCmd = importer.import("spawn child process");
ncp.limit = 16;
var webstormWin = 'C:\\Program Files\\JetBrains\\WebStorm 2017.1.1\\bin\\format.bat';
var webstormMac = '/Applications/WebStorm.app/Contents/bin/format.sh';
var webstorm = process.platform === 'win32' ? webstormWin : webstormMac;
var idea = path.resolve(path.join(__dirname, '../.idea'));
function delint(project) {
// output .idea to set the framework preferences?
// I think I overwrote the default, some way to env variables for this?
return util.promisify(ncp)(idea, project + '/.idea')
.then(() => execCmd(`"${webstorm}" "${project}"`, {cwd: project}))
}
module.exports = delint;
// @description: Deletes lint in a project directory.
// @param {string} project - Path to the project directory.
// @return {Promise} - Resolves when the lint deletion is complete.
const path = require('path');
const { promisify } = require('util'); // Use util.promisify to avoid multiple imports
const ncp = require('ncp').promisify(); // Use promisify to avoid callback hell
const importer = require('../Core');
const { spawnChildProcess } = importer.import(); // Use destructuring to improve readability
// Define constants for WebStorm executable paths
const webstormExe = {
win32: 'C:\\Program Files\\JetBrains\\WebStorm 2017.1.1\\bin\\format.bat',
darwin: '/Applications/WebStorm.app/Contents/bin/format.sh', // Use darwin for macOS
};
// Define constants for IDEA directory path
const ideaDir = path.resolve(path.join(__dirname, '../.idea'));
/**
* Deletes lint in a project directory using WebStorm's format tool.
* @param {string} project - Path to the project directory.
* @returns {Promise} - Resolves when the lint deletion is complete.
*/
function delint(project) {
// Limit ncp to 16 concurrent operations
ncp.limit = 16;
// Use process.platform to determine the correct executable path
const webstorm = webstormExe[process.platform];
// Copy IDEA directory to project directory
return ncp(ideaDir, path.join(project, '.idea'))
.then(() => {
// Execute WebStorm's format tool in the project directory
return spawnChildProcess(`${webstorm} ${project}`, { cwd: project });
});
}
module.exports = delint;
This code sets up a function delint
that performs code formatting and potentially imports project settings from a .idea
directory.
Here's a breakdown:
Dependencies:
path
for file path manipulation.ncp
for copying directories.importer
(likely a custom module) for accessing other functions.execCmd
(likely from importer
) for executing shell commands.WebStorm Path:
.idea
Directory:
.idea
directory, which likely contains project-specific settings.delint
Function:
project
path as input..idea
directory to the specified project directory.Export:
delint
function as the module's main export.In essence, this code aims to format code within a project directory using WebStorm and potentially import project-specific settings from a .idea
directory.