Skip to content
This repository was archived by the owner on Apr 26, 2022. It is now read-only.

Commit a5a5839

Browse files
authored
Merge branch 'master' into greenkeeper/eslint-plugin-node-10.0.0
2 parents d44e9d9 + 209d6c5 commit a5a5839

File tree

9 files changed

+658
-742
lines changed

9 files changed

+658
-742
lines changed

package-lock.json

Lines changed: 552 additions & 678 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-plop",
3-
"version": "0.19.0",
3+
"version": "0.20.0",
44
"description": "programmatic plopping for fun and profit",
55
"main": "lib/index.js",
66
"types": "index.d.ts",
@@ -40,13 +40,13 @@
4040
"node": ">=8.9.4"
4141
},
4242
"devDependencies": {
43-
"@babel/cli": "^7.5.5",
44-
"@babel/core": "^7.5.5",
45-
"@babel/preset-env": "^7.5.5",
46-
"@babel/register": "^7.5.5",
47-
"ava": "^2.3.0",
48-
"eslint": "^6.0.0",
49-
"eslint-config-standard": "^14.0.1",
43+
"@babel/cli": "^7.6.4",
44+
"@babel/core": "^7.6.4",
45+
"@babel/preset-env": "^7.6.3",
46+
"@babel/register": "^7.6.2",
47+
"ava": "^2.4.0",
48+
"eslint": "^6.5.1",
49+
"eslint-config-standard": "^14.1.0",
5050
"eslint-plugin-import": "^2.18.2",
5151
"eslint-plugin-node": "^10.0.0",
5252
"eslint-plugin-promise": "^4.2.1",
@@ -61,10 +61,10 @@
6161
"@types/inquirer": "6.0.1",
6262
"change-case": "^3.1.0",
6363
"co": "^4.6.0",
64-
"core-js": "^3.2.1",
64+
"core-js": "^3.3.2",
6565
"del": "^5.1.0",
66-
"globby": "^10.0.0",
67-
"handlebars": "^4.1.2",
66+
"globby": "^10.0.1",
67+
"handlebars": "^4.4.3",
6868
"inquirer": "^7.0.0",
6969
"isbinaryfile": "^4.0.2",
7070
"lodash.get": "^4.4.2",

src/actions/_common-action-utils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ import path from 'path';
22
import * as fspp from '../fs-promise-proxy';
33

44
const getFullData = (data, cfg) => Object.assign({}, cfg.data, data);
5-
export const makeDestPath = (data, cfg, plop) =>
6-
path.resolve(
7-
plop.getDestBasePath(),
8-
plop.renderString(cfg.path || '', getFullData(data, cfg))
9-
);
5+
6+
export const normalizePath = path => {
7+
return !path.sep || path.sep === '\\' ? path.replace(/\\/g, '/') : path;
8+
};
9+
10+
export const makeDestPath = (data, cfg, plop) => {
11+
return path.resolve(plop.getDestBasePath(), plop.renderString(normalizePath(cfg.path) || '', getFullData(data, cfg)));
12+
};
1013

1114
export function getRenderedTemplatePath(data, cfg, plop) {
1215
if (cfg.templateFile) {
1316
const absTemplatePath = path.resolve(plop.getPlopfilePath(), cfg.templateFile);
14-
return plop.renderString(absTemplatePath, getFullData(data, cfg));
17+
return plop.renderString(normalizePath(absTemplatePath), getFullData(data, cfg));
1518
}
1619
return null;
1720
}
@@ -37,8 +40,7 @@ export function* getRenderedTemplate(data, cfg, plop) {
3740
return plop.renderString(template, getFullData(data, cfg));
3841
}
3942

40-
export const getRelativeToBasePath = (filePath, plop) =>
41-
filePath.replace(path.resolve(plop.getDestBasePath()), '');
43+
export const getRelativeToBasePath = (filePath, plop) => filePath.replace(path.resolve(plop.getDestBasePath()), '');
4244

4345
export const throwStringifiedError = err => {
4446
if (typeof err === 'string') {

src/actions/addMany.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs';
44
import globby from 'globby';
55
import actionInterfaceTest from './_common-action-interface-check';
66
import addFile from './_common-action-add-file';
7+
import { normalizePath } from './_common-action-utils';
78

89
const defaultConfig = {
910
verbose: true,
@@ -66,11 +67,7 @@ function isUnder(basePath = '') {
6667
}
6768

6869
function resolvePath(destination, file, rootPath) {
69-
return toUnix(path.join(destination, dropFileRootPath(file, rootPath)));
70-
}
71-
72-
function toUnix(path) {
73-
return !path.sep || path.sep === '\\' ? path.replace(/\\/g, '/') : path;
70+
return normalizePath(path.join(destination, dropFileRootPath(file, rootPath)));
7471
}
7572

7673
function dropFileRootPath(file, rootPath) {

tests/_base-ava-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import del from 'del';
44
import co from 'co';
55
import * as fspp from '../lib/fs-promise-proxy.js';
66
import nodePlop from '../lib/index.js';
7+
import { normalizePath } from '../src/actions/_common-action-utils';
78

89
class AvaTest {
9-
1010
constructor(testFile) {
1111
this.testName = path.basename(testFile).split('.')[0];
12-
this.mockPath = path.resolve(__dirname, this.testName + '-mock');
12+
this.mockPath = normalizePath(path.resolve(__dirname, this.testName + '-mock'));
1313
this.testSrcPath = path.resolve(this.mockPath, 'src');
1414
this.test = ava;
1515
this.nodePlop = nodePlop;
@@ -22,7 +22,7 @@ class AvaTest {
2222
const ctx = this;
2323
return co(function*() {
2424
// remove the src folder
25-
yield del([ctx.testSrcPath], {force: true});
25+
yield del([normalizePath(ctx.testSrcPath)], {force: true});
2626

2727
try {
2828
const mockIsEmpty = (yield fspp.readdir(ctx.mockPath)).length === 0;

tests/action-data-cleanup.ava.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
import co from 'co';
22
import AvaTest from './_base-ava-test';
3-
const {test, testSrcPath, nodePlop} = (new AvaTest(__filename));
3+
const { test, testSrcPath, nodePlop } = new AvaTest(__filename);
4+
import { normalizePath } from '../src/actions/_common-action-utils';
45

56
const plop = nodePlop();
67

78
// Make sure that props added by the action's data attr are cleaned up
89
// after the action executes
910

10-
test('Action data cleanup', co.wrap(function* (t) {
11-
const actions = ['one', 'two', 'three'].map(fName => ({
12-
type: 'add',
13-
template: '',
14-
path: `${testSrcPath}/{{fName}}-{{unchanged}}.txt`,
15-
data: {fName, unchanged: `${fName}-unchanged`}
16-
}));
17-
const g = plop.setGenerator('', {actions});
18-
const {changes, failures} = yield g.runActions({unchanged: 'unchanged'});
19-
const addedFiles = changes.map(c => c.path.split('/').slice(-1)).join('|');
20-
t.is(addedFiles, 'one-unchanged.txt|two-unchanged.txt|three-unchanged.txt');
21-
t.is(changes.length, 3);
22-
t.is(failures.length, 0);
23-
}));
11+
test(
12+
'Action data cleanup',
13+
co.wrap(function*(t) {
14+
const actions = ['one', 'two', 'three'].map(fName => ({
15+
type: 'add',
16+
template: '',
17+
path: `${testSrcPath}/{{fName}}-{{unchanged}}.txt`,
18+
data: { fName, unchanged: `${fName}-unchanged` }
19+
}));
20+
const g = plop.setGenerator('', { actions });
21+
const { changes, failures } = yield g.runActions({ unchanged: 'unchanged' });
22+
const addedFiles = changes
23+
.map(c =>
24+
normalizePath(c.path)
25+
.split('/')
26+
.slice(-1)
27+
)
28+
.join('|');
29+
t.is(addedFiles, 'one-unchanged.txt|two-unchanged.txt|three-unchanged.txt');
30+
t.is(changes.length, 3);
31+
t.is(failures.length, 0);
32+
})
33+
);
Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
11
import fs from 'fs';
22
import co from 'co';
33
import AvaTest from './_base-ava-test';
4-
const {test, mockPath, testSrcPath, nodePlop} = (new AvaTest(__filename));
4+
const { test, mockPath, testSrcPath, nodePlop } = new AvaTest(__filename);
55

66
const plop = nodePlop();
77

8-
test('Add action keeps the executable flag', co.wrap(function* (t) {
9-
plop.setGenerator('addExecutable', {
10-
actions: [{
11-
type: 'add',
12-
path: `${testSrcPath}/added.sh`,
13-
templateFile: `${mockPath}/plop-templates/add.sh`
14-
}]
15-
});
8+
if (process.platform !== 'win32') {
9+
test(
10+
'Add action keeps the executable flag',
11+
co.wrap(function*(t) {
12+
plop.setGenerator('addExecutable', {
13+
actions: [
14+
{
15+
type: 'add',
16+
path: `${testSrcPath}/added.sh`,
17+
templateFile: `${mockPath}/plop-templates/add.sh`
18+
}
19+
]
20+
});
1621

17-
yield plop.getGenerator('addExecutable').runActions();
18-
const destStats = fs.statSync(`${testSrcPath}/added.sh`);
19-
t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
20-
}));
22+
yield plop.getGenerator('addExecutable').runActions();
23+
const destStats = fs.statSync(`${testSrcPath}/added.sh`);
24+
t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
25+
})
26+
);
27+
} else {
28+
test.skip(
29+
'[Windows] Add action keeps the executable flag',
30+
co.wrap(function*(t) {
31+
plop.setGenerator('addExecutable', {
32+
actions: [
33+
{
34+
type: 'add',
35+
path: `${testSrcPath}/added.sh`,
36+
templateFile: `${mockPath}/plop-templates/add.sh`
37+
}
38+
]
39+
});
40+
41+
yield plop.getGenerator('addExecutable').runActions();
42+
const destStats = fs.statSync(`${testSrcPath}/added.sh`);
43+
// t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
44+
})
45+
);
46+
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import fs from 'fs';
22
import AvaTest from './_base-ava-test';
3-
const {test, mockPath, testSrcPath, nodePlop} = (new AvaTest(__filename));
3+
const { test, mockPath, testSrcPath, nodePlop } = new AvaTest(__filename);
44

55
const plop = nodePlop(`${mockPath}/plopfile.js`);
66
const executableFlagAddMany = plop.getGenerator('executable-flag-add-many');
77
let res;
88

99
test.before(() => {
10-
res = executableFlagAddMany.runActions({ executableName: 'ls command' })
10+
res = executableFlagAddMany.runActions({ executableName: 'ls command' });
1111
return res;
1212
});
13-
14-
test('addMany action keeps the executable flag', t => {
15-
const destStats = fs.statSync(`${testSrcPath}/ls-command.sh`);
16-
t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
17-
});
13+
if (process.platform !== 'win32') {
14+
test('addMany action keeps the executable flag', t => {
15+
const destStats = fs.statSync(`${testSrcPath}/ls-command.sh`);
16+
t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
17+
});
18+
} else {
19+
test.skip('[windows] addMany action keeps the executable flag', t => {
20+
const destStats = fs.statSync(`${testSrcPath}/ls-command.sh`);
21+
// t.is(destStats.mode & fs.constants.S_IXUSR, fs.constants.S_IXUSR);
22+
});
23+
}

tests/imported-custom-action-mock/custom-action.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const co = require('co');
22
const del = require('del');
33
const fspp = require('../../src/fs-promise-proxy');
4+
import { normalizePath } from '../../src/actions/_common-action-utils';
45

5-
module.exports = co.wrap(function* (data, cfg/*, plop*/) {
6+
module.exports = co.wrap(function*(data, cfg /*, plop*/) {
67
const removeFilePath = cfg.path;
78
if (yield fspp.fileExists(removeFilePath)) {
8-
return yield del([removeFilePath]);
9+
return yield del([normalizePath(removeFilePath)]);
910
} else {
1011
throw `Path does not exist ${removeFilePath}`;
1112
}

0 commit comments

Comments
 (0)