Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
# OS specific auto-generated folders and files
*.swp
.DS_Store
npm-debug.log
tmp

# Platform specific tools (use fetch-configlet)
bin/configlet
bin/configlet.exe
node_modules

# IDE folders and files
.idea

# Babel specific
babel-output

# Test generated content
tmp

# package.json generated content
node_modules

# Ignore npm error/log
npm-debug.log

# Ignore yarn lockfile and error, in case someone accidentally runs yarn
yarn.lock
yarn-error.log
14 changes: 14 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
63 changes: 63 additions & 0 deletions bin/tools/copy-babel-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env node

/**
* This copies the current .babelrc to a specific exercise folder or to all
* of them if an exercise folder is not given.
*
* Usage:
*
* ./bin/tools/copy-babel-config <exercise>
*/

// @ts-check

const fs = require('fs');
const path = require('path');

const ROOT_PATH = path.join(__dirname, '..', '..');
const BABEL_CONFIG_PATH = path.join(ROOT_PATH, 'babel.config.js');
const EXERCISE = process.argv.slice(2).find(arg => !arg.startsWith('-'));

process.stdout.write(`=> copy babel config for ${EXERCISE || 'all exercises'}\n`);


function execute(exercise) {
const EXERCISE_DIR = path.join(ROOT_PATH, 'exercises', exercise);
const destination = path.join(EXERCISE_DIR, path.basename(BABEL_CONFIG_PATH));

fs.copyFile(BABEL_CONFIG_PATH, destination, (err) => {
if (err) {
process.stderr.write(`=> error for ${exercise}: ${err.message}\n`);
} else {
process.stdout.write(`=> copied babel config to ${exercise}\n`);
}
});

}

if (!EXERCISE) {
process.stdin.resume();
process.stdout.write('?> are you sure? [Y/n]\n');
process.stdin.once('data', (data) => {
process.stdin.pause();

const input = data.toString().trim();

if (!/^(?:\s?|y|yes)$/i.test(input)) {
process.stdout.write('=> ok bye\n');
process.exit(0);
return;
}

fs.readdir(path.join(ROOT_PATH, 'exercises'), (err, exercises) => {
if (err) {
process.stderr.write(err.message);
process.exit(-1);
}

exercises.forEach(execute);
});
});
} else {
execute(EXERCISE);
}
81 changes: 81 additions & 0 deletions bin/tools/copy-package-json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env node

/**
* This copies the current package.json to a specific exercise folder or to all
* of them if an exercise folder is not given. Merges the version field in case
* it's set.
*
* Usage:
*
* ./bin/tools/copy-package-json <exercise>
*/

// @ts-check

const fs = require('fs');
const path = require('path');

const ROOT_PATH = path.join(__dirname, '..', '..');
const EXERCISE = process.argv.slice(2).find(arg => !arg.startsWith('-'));

process.stdout.write(`=> copy package.json for ${EXERCISE || 'all exercises'}\n`);

function formatAsJson(data) {
return JSON.stringify(data, null, 2);
}

// @ts-ignore
const BASE_PACKAGE_JSON = require('../../package.json');

function execute(exercise) {
const EXERCISE_DIR = path.join(ROOT_PATH, 'exercises', exercise);
const EXERCISE_PACKAGE_JSON = path.join(EXERCISE_DIR, 'package.json');

fs.readFile(EXERCISE_PACKAGE_JSON, (err, data) => {
const current = JSON.parse(err ? JSON.stringify(BASE_PACKAGE_JSON) : data.toString());
const mergedPackage = formatAsJson(
{
...BASE_PACKAGE_JSON,
version: current.version,
},
);

fs.writeFile(EXERCISE_PACKAGE_JSON, mergedPackage, (innerErr) => {
if (innerErr) {
process.stderr.write(`=> error for ${exercise}: ${err.message}\n`);
} else {
process.stdout.write(`=> copied package.json to ${exercise}\n`);
}
});
});
}

if (!EXERCISE) {
process.stdin.resume();
process.stdout.write('?> are you sure? [Y/n]\n');
process.stdin.once('data', (data) => {
process.stdin.pause();

const input = data.toString().trim();

if (!/^(?:\s?|y|yes)$/i.test(input)) {
process.stdout.write('=> ok bye\n');
process.exit(0);
return;
}

fs.readdir(path.join(ROOT_PATH, 'exercises'), (err, exercises) => {
if (err) {
process.stderr.write(err.message);
process.exit(-1);
}

exercises.forEach(execute);
});
});
} else {
execute(EXERCISE);
}

// Sanity check matching whitespace
fs.writeFile(path.join(ROOT_PATH, 'package.json'), formatAsJson(BASE_PACKAGE_JSON), () => {});
14 changes: 14 additions & 0 deletions exercises/accumulate/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
38 changes: 6 additions & 32 deletions exercises/accumulate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,21 @@
"url": "https://github.com/exercism/javascript"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-preset-env": "^1.7.0",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"jest": "^23.6.0"
"jest": "^24.5.0"
},
"jest": {
"modulePathIgnorePatterns": [
"package.json"
]
},
"babel": {
"presets": [
[
"env",
{
"targets": [
{
"node": "current"
}
]
}
]
],
"plugins": [
[
"babel-plugin-transform-builtin-extend",
{
"globals": [
"Error"
]
}
],
[
"transform-regenerator"
]
]
},
"scripts": {
"test": "jest --no-cache ./*",
"watch": "jest --no-cache --watch ./*",
Expand Down Expand Up @@ -77,4 +51,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
14 changes: 14 additions & 0 deletions exercises/acronym/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
38 changes: 6 additions & 32 deletions exercises/acronym/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,21 @@
"url": "https://github.com/exercism/javascript"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"babel-jest": "^23.6.0",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-preset-env": "^1.7.0",
"babel-jest": "^24.5.0",
"eslint": "^5.12.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.15.0",
"jest": "^23.6.0"
"jest": "^24.5.0"
},
"jest": {
"modulePathIgnorePatterns": [
"package.json"
]
},
"babel": {
"presets": [
[
"env",
{
"targets": [
{
"node": "current"
}
]
}
]
],
"plugins": [
[
"babel-plugin-transform-builtin-extend",
{
"globals": [
"Error"
]
}
],
[
"transform-regenerator"
]
]
},
"scripts": {
"test": "jest --no-cache ./*",
"watch": "jest --no-cache --watch ./*",
Expand Down Expand Up @@ -77,4 +51,4 @@
},
"license": "MIT",
"dependencies": {}
}
}
14 changes: 14 additions & 0 deletions exercises/all-your-base/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
presets: [
[
'@babel/env',
{
targets: {
node: 'current',
},
useBuiltIns: false,
},

],
],
};
Loading