Skip to content

Commit 4af1e29

Browse files
committed
Clean the template-full option and add a prettier config file
1 parent 36a03c6 commit 4af1e29

File tree

6 files changed

+36
-46
lines changed

6 files changed

+36
-46
lines changed

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"bracketSpacing": false,
3+
"singleQuote": true,
4+
"jsxBracketSameLine": true,
5+
"trailingComma": "es5",
6+
"printWidth": 80,
7+
"proseWrap": "always"
8+
}

packages/reactful-main/bin/reactful.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const config = {};
66

77
async function reactfulCreate() {
88
try {
9-
const { appName, appPath } = config;
9+
const {appName, appPath} = config;
1010
console.info(`\n***** Creating ${appName} app *****\n`);
1111

1212
require('../lib/copy')(config);
@@ -46,6 +46,7 @@ async function main() {
4646
const commandExists = require('../lib/commandExists');
4747
config.useYarn = await commandExists('yarn');
4848
config.useGit = await commandExists('git');
49+
config.appType = 'simple';
4950

5051
const [firstArg, secondArg] = process.argv.slice(2);
5152

@@ -54,25 +55,22 @@ async function main() {
5455
return;
5556
}
5657

57-
if (firstArg === 'init' || firstArg === 'init-full') {
58+
if (firstArg === 'init') {
5859
config.appPath = '.';
5960
config.appName = path.basename(path.resolve('.'));
60-
config.appType = firstArg === 'init' ? 'simple' : 'full';
61-
return reactfulCreate();
6261
}
6362

64-
if (firstArg === 'new' || firstArg === 'new-full') {
63+
if (firstArg === 'new') {
6564
config.appPath = config.appName = secondArg;
66-
config.appType = firstArg === 'new' ? 'simple' : 'full';
67-
return reactfulCreate();
6865
}
6966

70-
if (fs.existsSync(path.resolve('src', 'server', 'config.js'))) {
71-
return forwardCommand(firstArg, secondArg);
72-
}
67+
if (!['init', 'new'].includes(firstArg)) {
68+
if (fs.existsSync(path.resolve('src', 'server', 'config.js'))) {
69+
return forwardCommand(firstArg, secondArg);
70+
}
7371

74-
config.appPath = config.appName = firstArg;
75-
config.appType = 'simple';
72+
config.appPath = config.appName = firstArg;
73+
}
7674

7775
reactfulCreate();
7876
}

packages/reactful-main/lib/copy.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
const path = require('path');
2-
const { copy, inspect } = require('fs-jetpack');
2+
const {copy, inspect} = require('fs-jetpack');
33
const prompt = require('prompt-sync')();
44

5-
module.exports = function reactfulCopy({ appPath, appType }) {
6-
const templateDir = path.resolve(
7-
__dirname,
8-
'..',
9-
appType === 'simple' ? 'template' : 'template-full'
10-
);
5+
module.exports = function reactfulCopy({appPath}) {
6+
const templateDir = path.resolve(__dirname, '..', 'template');
117

128
copy(templateDir, appPath, {
139
overwrite: (src, dest) => {
1410
if (
15-
inspect(src.absolutePath, { checksum: 'md5' }).md5 !==
16-
inspect(dest.absolutePath, { checksum: 'md5' }).md5
11+
inspect(src.absolutePath, {checksum: 'md5'}).md5 !==
12+
inspect(dest.absolutePath, {checksum: 'md5'}).md5
1713
) {
1814
const answer = prompt(`Replace ${src.name}? [y|n] `);
1915
return answer.match(/(yes|yep|y|sure)/, 'i');
2016
}
2117
return true;
22-
},
18+
}
2319
});
2420
};

packages/reactful-main/lib/init.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const path = require('path');
22
const fs = require('fs');
3-
const { spawn } = require('child_process');
3+
const {spawn} = require('child_process');
44

55
module.exports = function reactfulInit(config) {
66
return new Promise((resolve, reject) => {
77
const pmCommand = config.useYarn ? 'yarn' : 'npm';
8-
const { appName, appPath } = config;
8+
const {appName, appPath} = config;
99
const packageJson = {
1010
name: appName,
1111
version: '0.1.0',
@@ -27,19 +27,15 @@ module.exports = function reactfulInit(config) {
2727
'prod-stop': `pm2 stop ${appName}Prod`,
2828
'prod-reload': `pm2 reload --update-env ${appName}Prod`,
2929
'prod-logs': `pm2 logs ${appName}Prod`,
30-
_reactful_commands: '_reactful_commands',
30+
_reactful_commands: '_reactful_commands'
3131
},
3232
babel: {
33-
presets: [
34-
'react',
35-
['env', { targets: { node: 'current' } }],
36-
'stage-2',
37-
],
33+
presets: ['react', ['env', {targets: {node: 'current'}}], 'stage-2']
3834
},
3935
jest: {
4036
modulePaths: ['./src'],
41-
testPathIgnorePatterns: ['/node_modules/'],
42-
},
37+
testPathIgnorePatterns: ['/node_modules/']
38+
}
4339
};
4440

4541
fs.writeFileSync(
@@ -55,23 +51,15 @@ module.exports = function reactfulInit(config) {
5551
const reactfulJson = {
5652
main: 'main.js',
5753
styles: 'styles.js',
58-
vendor: 'vendor.js',
54+
vendor: 'vendor.js'
5955
};
6056

6157
fs.writeFileSync(
6258
path.resolve(appPath, '.reactful.json'),
6359
JSON.stringify(reactfulJson, null, 2)
6460
);
6561

66-
const {
67-
main: mainDeps,
68-
dev: devDeps,
69-
full: fullDeps,
70-
} = require('./dependencies');
71-
72-
if (config.appType === 'full') {
73-
mainDeps.push(...fullDeps);
74-
}
62+
const {main: mainDeps, dev: devDeps} = require('./dependencies');
7563

7664
const installProdCmd = config.useYarn ? 'yarn add' : 'npm install --save';
7765
const installDevCmd = config.useYarn
@@ -87,7 +75,7 @@ module.exports = function reactfulInit(config) {
8775
{
8876
shell: true,
8977
stdio: 'inherit',
90-
cwd: path.resolve(appPath),
78+
cwd: path.resolve(appPath)
9179
}
9280
);
9381

packages/reactful-main/template/src/components/App.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import renderer from 'react-test-renderer';
66
describe('App', () => {
77
it('renders correctly', () => {
88
const tree = renderer
9-
.create(<App initialData={{ appName: 'TEST' }} />)
9+
.create(<App initialData={{appName: 'TEST'}} />)
1010
.toJSON();
1111

1212
expect(tree).toMatchSnapshot();

packages/reactful-main/template/src/server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ app.use(morgan('common'));
1414
app.use(express.static('public'));
1515

1616
app.set('view engine', 'ejs');
17-
app.use(bodyParser.urlencoded({ extended: false }));
17+
app.use(bodyParser.urlencoded({extended: false}));
1818
app.use(bodyParser.json());
1919

2020
app.locals.serialize = serialize;
@@ -42,7 +42,7 @@ app.listen(config.port, config.host, () => {
4242
fs.writeFileSync(
4343
path.resolve('.reactful.json'),
4444
JSON.stringify(
45-
{ ...app.locals.gVars, host: config.host, port: config.port },
45+
{...app.locals.gVars, host: config.host, port: config.port},
4646
null,
4747
2
4848
)

0 commit comments

Comments
 (0)