Skip to content

Commit

Permalink
fix: removes installation with npm and upgrades dependencies
Browse files Browse the repository at this point in the history
* fix: removes installation with npm and upgrades dependencies

* docs: updated readme

* docs: improved contributing information and scripts
  • Loading branch information
arianacosta authored Nov 26, 2019
1 parent 8caa239 commit b410ffa
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 1,721 deletions.
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing to Poetic

Thank you for your interest in this project!

## Core Concepts of Poetic

- As automatic as possible: Poetic is not meant to solve all the needs out there, it's is meant to solve the most popular ones in a very simple way. When possible, prefer automatic and opinionated installations over complex options.
- Customizable: For those with special needs, every configuration should be customizable. Ideally, with the same type of configuration files. Poetic should not have yet another configuration file. That's what we are trying to avoid.
- Self-Contained Single Dependency: Poetic should provide all the functionality as a single dependency. Users should not have to install or maintain extra dependencies or configurations.

## Developing Locally

To test out Poetic you will need a test project of your choosing (or use the simple [Poetic Sandbox](https://github.com/arianacosta/poetic-sandbox)).

```
directory/
├── poetic/
└── package.json
└── your_test_project/
└── package.json
└── src/
└── [your test files]
```

1. Clone the Poetic repository next to your test project
2. Go to poetic `cd poetic`
3. Run `yarn develop` to configure the boilerplate to local development
4. Go to the test project `cd ../your_test_project`
5. Install the local Poetic `npx ../poetic`

### Streamline Installation/Uninstallation

In your test project you may add the following scripts to simplify the iterative process of installing/uninstalling:

```
"scripts": {
"poetic:add": "npx ../poetic",
"poetic:reset": "git reset --hard && git clean -fd",
},
```
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ npx poetic
- Easy to maintain with a **single dependency**
- Configures **Visual Studio Code**

## Requirements

- Yarn (There are some [limitations with NPM](https://github.com/arianacosta/poetic/issues/28) that make it incompatible with ESLint as a subdependency)

### Motivation

Keeping the code clean and organized is important to prevent bugs and to collaborate with others. Linters help identify possible errors and bad practices and formatters allow us to concentrate on the features without having to worry about the code format. Unfortunately, configuring and maintaining these tools is cumbersome and more often than not, the project ends up with incorrect configurations (if any at all).
Expand Down
49 changes: 10 additions & 39 deletions bin/install-boilerplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ const installConfigurationFiles = () => {
}
}

const updatePackageJsonDevDependencies = () => {
const updatePackageJson = () => {
try {
console.log('🥝 Updating package.json devDependencies ...');
console.log('🥝 Updating package.json ...');

const packageJson = path.join(currentDir, "package.json");

Expand All @@ -47,6 +47,11 @@ const updatePackageJsonDevDependencies = () => {
const package = fse.readJsonSync(packageJson);
const packageScripts = fse.readJsonSync(path.join(sourceRootDir, 'bin/package.boilerplate.json'));

package.scripts = {
...package.scripts,
...packageScripts.scripts,
};

package.devDependencies = {
...package.devDependencies,
...packageScripts.devDependencies,
Expand All @@ -61,45 +66,12 @@ const updatePackageJsonDevDependencies = () => {
const installPackages = () => {
try {
console.log('🍉 Installing packages ...');
try {
cp.execSync('yarn install');
return 'yarn'
} catch (e) {
process.stdout.moveCursor(0, -1)
process.stdout.clearLine(0)
cp.execSync('npm install');
return 'npm'
}
cp.execSync('yarn install');
} catch (e) {
throw Error(`Could not install packages.`);
}
}

const updatePackageJsonScripts = (manager) => {
try {
console.log('🥝 Updating package.json scripts ...');

const packageJson = path.join(currentDir, "package.json");

if (!fse.existsSync(packageJson)) {
throw Error ('package.json not found in the current directory.')
}

const package = fse.readJsonSync(packageJson);
const packageScriptsRaw = fse.readFileSync(path.join(sourceRootDir, 'bin/package.boilerplate.json'), { encoding: 'utf8' })
const packageScripts = JSON.parse(packageScriptsRaw.replace(/\$\{manager\}/g, manager));

package.scripts = {
...package.scripts,
...packageScripts.scripts,
};

fse.writeJsonSync(packageJson, package, {spaces: 2});
} catch (e) {
throw Error(`Could not update package.json: ${e}`);
}
}

const displaySuccessMessage = () => {
console.log('');
console.log('💫 Poetic was installed successfully!');
Expand All @@ -122,9 +94,8 @@ const displayErrorMessage = (error) => {
try {
setCheckpoint();
installConfigurationFiles();
updatePackageJsonDevDependencies();
const manager = installPackages();
updatePackageJsonScripts(manager);
updatePackageJson();
installPackages();
displaySuccessMessage();
} catch (e) {
displayErrorMessage(e);
Expand Down
2 changes: 1 addition & 1 deletion bin/package.boilerplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"poetic": "^1.1.0"
},
"scripts": {
"code:clean": "${manager} code:lint && ${manager} code:format",
"code:clean": "yarn code:lint && yarn code:format",
"code:lint": "eslint --ext .js,.jsx,.ts,.tsx \"src/\" --fix",
"code:format": "prettier './src/**/**.{js,jsx,ts,tsx}' --write",
"code:check:rules": "eslint --print-config .eslintrc.js | eslint-config-prettier-check"
Expand Down
Loading

0 comments on commit b410ffa

Please sign in to comment.