Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit fd1fd62

Browse files
committed
fix(base): Change cwd folder for run console commands
1 parent 981d479 commit fd1fd62

3 files changed

Lines changed: 123 additions & 47 deletions

File tree

src/lib/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ export class Base {
5050
}
5151
async commandRunner(commandString: string) {
5252
this.log('commandRunner').debug('start');
53+
this.log('commandRunner').debug('rootFolder', this.rootFolder);
5354
this.log('commandRunner').debug(commandString);
5455
const commandBin = commandString.split(' ')[0];
5556
const commandArgs = commandString.split(' ').filter((arg: string, index: number) => index > 0);
5657
const child = npmRun.spawnSync(
5758
commandBin,
5859
commandArgs,
59-
{ cwd: path.resolve(__dirname, '..', '..') }
60+
{ cwd: process.cwd() }
6061
);
6162
if (child.status === 0 || child.status === '0') {
6263
this.log('commandRunner').debug('status', child.status);

test/cmd-apps-spec.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as chai from 'chai';
2+
import * as del from 'del';
3+
import { config } from 'dotenv';
4+
import * as fsExtra from 'fs-extra';
5+
import * as path from 'path';
6+
7+
import { Base } from '../src/lib/base';
8+
9+
const npmRun = require('npm-run');
10+
const assert = chai.assert;
11+
12+
describe('Apps:run from console', () => {
13+
config();
14+
const debug = process.env.TEST_DEBUG === 'true';
15+
describe('#prepare()', () => {
16+
const items: any[] = [];
17+
const dirRoot = path.resolve(__dirname + '/../');
18+
let _dir = path.resolve(`${__dirname}/fixture/apps/app1`);
19+
items.push({
20+
dir: _dir,
21+
translateTsFile: path.resolve(`${_dir}/src/i18n/ru.i18n.ts`),
22+
indexTsFile: path.resolve(`${_dir}/src/index.ts`)
23+
});
24+
_dir = path.resolve(`${__dirname}/fixture/apps/subFolder/app2`);
25+
items.push({
26+
dir: _dir,
27+
translateTsFile: path.resolve(`${_dir}/src/i18n/ru.i18n.ts`),
28+
indexTsFile: path.resolve(`${_dir}/src/index.ts`)
29+
});
30+
beforeEach(() => {
31+
items.forEach(({ dir: dir,
32+
dirRoot: dirRoot,
33+
translateTsFile: translateTsFile,
34+
indexTsFile: indexTsFile
35+
}) => {
36+
if (fsExtra.existsSync(translateTsFile)) {
37+
del.sync([translateTsFile]);
38+
}
39+
if (fsExtra.existsSync(indexTsFile)) {
40+
del.sync([indexTsFile]);
41+
}
42+
});
43+
});
44+
items.forEach(({
45+
dir: dir,
46+
translateTsFile: translateTsFile,
47+
indexTsFile: indexTsFile
48+
}) => {
49+
it(`not exists ${translateTsFile}`, () => {
50+
assert.equal(fsExtra.existsSync(translateTsFile), false);
51+
});
52+
it(`not exists ${indexTsFile}`, () => {
53+
assert.equal(fsExtra.existsSync(indexTsFile), false);
54+
});
55+
});
56+
it('tsc --pretty', (done: any) => {
57+
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
58+
const commandString = './node_modules/.bin/tsc --pretty';
59+
60+
const base = new Base('', dirRoot);
61+
base.debug = debug;
62+
base.commandRunner(commandString).then((data: boolean) => {
63+
assert.equal(fsExtra.existsSync(file), true);
64+
done();
65+
}).catch(function (e) {
66+
done(e);
67+
});
68+
});
69+
it('rucken prepare --app --root ./test/fixture', (done) => {
70+
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
71+
const commandString = 'node . prepare --app --root ./test/fixture' + (debug ? ' --verbose' : '');
72+
73+
assert.equal(fsExtra.existsSync(file), true);
74+
75+
const base = new Base('', dirRoot);
76+
base.debug = debug;
77+
base.commandRunner(commandString).then((data: boolean) => {
78+
items.forEach(({
79+
dir: dir,
80+
translateTsFile: translateTsFile,
81+
indexTsFile: indexTsFile
82+
}) => {
83+
assert.equal(fsExtra.existsSync(translateTsFile), true);
84+
assert.equal(fsExtra.existsSync(indexTsFile), true);
85+
});
86+
done();
87+
}).catch(function (e) {
88+
done(e);
89+
});
90+
});
91+
});
92+
});

test/cmd-libs-spec.ts

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as del from 'del';
33
import { config } from 'dotenv';
44
import * as fsExtra from 'fs-extra';
55
import * as path from 'path';
6+
import { Base } from '../src/lib/base';
67

78
const npmRun = require('npm-run');
89
const assert = chai.assert;
@@ -50,57 +51,39 @@ describe('Libs:run from console', () => {
5051
assert.equal(fsExtra.existsSync(indexTsFile), false);
5152
});
5253
});
53-
it('tsc --pretty', () => {
54+
it('tsc --pretty', (done: any) => {
5455
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
5556
const commandString = './node_modules/.bin/tsc --pretty';
56-
const commandBin = commandString.split(' ')[0];
57-
const commandArgs = commandString.split(' ').filter((arg: string, index: number) => index > 0);
58-
if (debug) {
59-
console.log('commandRunner#start');
60-
console.log('commandRunner#', commandString);
61-
console.log('commandRunner#', file);
62-
}
63-
const child = npmRun.spawnSync(
64-
commandBin,
65-
commandArgs,
66-
{ cwd: dirRoot }
67-
);
68-
if (debug) {
69-
console.log('commandRunner#status', child.status);
70-
console.log('commandRunner#stderr', child.stderr.toString());
71-
console.log('commandRunner#stdout', child.stdout.toString());
72-
console.log('commandRunner#end');
73-
}
74-
assert.equal(fsExtra.existsSync(file), true);
57+
58+
const base = new Base('', dirRoot);
59+
base.debug = debug;
60+
base.commandRunner(commandString).then((data: boolean) => {
61+
assert.equal(fsExtra.existsSync(file), true);
62+
done();
63+
}).catch(function (e) {
64+
done(e);
65+
});
7566
});
76-
it('rucken prepare --lib --root ./test/fixture', () => {
67+
it('rucken prepare --lib --root ./test/fixture', (done) => {
7768
const file = path.resolve(`${dirRoot}/dist/bin/app.js`);
78-
const commandString = 'node ' + file + ' prepare --lib --root ./test/fixture' + (debug ? ' --verbose' : '');
79-
const commandBin = commandString.split(' ')[0];
80-
const commandArgs = commandString.split(' ').filter((arg: string, index: number) => index > 0);
81-
if (debug) {
82-
console.log('commandRunner#start');
83-
console.log('commandRunner#', commandString);
84-
}
69+
const commandString = 'node . prepare --lib --root ./test/fixture' + (debug ? ' --verbose' : '');
70+
8571
assert.equal(fsExtra.existsSync(file), true);
86-
const child = npmRun.spawnSync(
87-
commandBin,
88-
commandArgs,
89-
{ cwd: dirRoot }
90-
);
91-
if (debug) {
92-
console.log('commandRunner#status', child.status);
93-
console.log('commandRunner#stderr', child.stderr.toString());
94-
console.log('commandRunner#stdout', child.stdout.toString());
95-
console.log('commandRunner#end');
96-
}
97-
items.forEach(({
98-
dir: dir,
99-
translateTsFile: translateTsFile,
100-
indexTsFile: indexTsFile
101-
}) => {
102-
assert.equal(fsExtra.existsSync(translateTsFile), true);
103-
assert.equal(fsExtra.existsSync(indexTsFile), true);
72+
73+
const base = new Base('', dirRoot);
74+
base.debug = debug;
75+
base.commandRunner(commandString).then((data: boolean) => {
76+
items.forEach(({
77+
dir: dir,
78+
translateTsFile: translateTsFile,
79+
indexTsFile: indexTsFile
80+
}) => {
81+
assert.equal(fsExtra.existsSync(translateTsFile), true);
82+
assert.equal(fsExtra.existsSync(indexTsFile), true);
83+
});
84+
done();
85+
}).catch(function (e) {
86+
done(e);
10487
});
10588
});
10689
});

0 commit comments

Comments
 (0)