Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit 178945c

Browse files
committed
Adding new template proposal. Resolves #71
1 parent 5f6f13a commit 178945c

35 files changed

+23914
-14288
lines changed

.circleci/config.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,4 @@ jobs:
3232

3333
- run:
3434
name: Run Unit Tests
35-
command: export NODE_ENV=production && npm run test
36-
37-
- run:
38-
name: Execute The Build
39-
command: npm run build
40-
41-
- run:
42-
name: CEA Install Self Test
43-
command: node ./tasks/cea-install my-app
44-
45-
# Sanity test yarn install and tasks
46-
- run:
47-
name: Yarn install test
48-
command: rm -rf ./node_modules && yarn install
49-
50-
- run:
51-
name: Yarn tasks test
52-
command: export NODE_ENV=production && yarn lint && yarn build && yarn test
35+
command: export NODE_ENV=production && npm run test-template && npm test

package-lock.json

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

package.json

Lines changed: 10 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,72 +17,18 @@
1717
"bin": {
1818
"create-evergreen-app": "./tasks/cea-install.js"
1919
},
20-
"files": [
21-
".browserslistrc",
22-
".editorconfig",
23-
".eslintrc",
24-
".gitattributes",
25-
"yarn.lock",
26-
"package-lock.json",
27-
"babel.config.js",
28-
"karma-test-shim.js",
29-
"karma.conf.js",
30-
"lws.config.js",
31-
"postcss.config.js",
32-
"README.md",
33-
"webpack.config.common.js",
34-
"webpack.config.develop.js",
35-
"webpack.config.prod.js",
36-
"src/",
37-
"tasks/"
38-
],
3920
"scripts": {
40-
"build": "rimraf ./public && webpack --config ./webpack.config.prod.js --progress",
41-
"develop": "webpack-dev-server --config ./webpack.config.develop.js --open",
42-
"gh-pages": "rimraf ./docs && npm run build && cp -rv ./public/ ./docs",
43-
"lint": "eslint \"*.js\" \"./src/**/*.js\"",
44-
"serve": "npm run build && ws",
45-
"start": "npm run develop",
46-
"test": "rimraf ./reports && karma start"
21+
"lint": "eslint \"./tasks/**/*.js\"",
22+
"test-template": "npm i --prefix template && npm test --prefix template",
23+
"test": "mocha --timeout 2000"
4724
},
4825
"dependencies": {
49-
"@polymer/lit-element": "^0.6.1"
50-
},
51-
"devDependencies": {
52-
"@babel/core": "^7.1.0",
53-
"@babel/preset-env": "^7.1.0",
54-
"@webcomponents/webcomponentsjs": "^2.1.3",
55-
"babel-loader": "^8.0.2",
56-
"babel-plugin-transform-builtin-classes": "^0.6.1",
57-
"css-loader": "^1.0.0",
58-
"css-to-string-loader": "^0.1.3",
59-
"cssnano": "^4.1.0",
60-
"eslint": "^5.6.0",
61-
"eslint-loader": "^2.1.1",
62-
"favicons-webpack-plugin": "0.0.9",
63-
"file-loader": "^2.0.0",
64-
"html-webpack-plugin": "^3.2.0",
65-
"istanbul-instrumenter-loader": "^3.0.1",
66-
"jasmine": "^3.2.0",
67-
"jasmine-core": "^3.2.1",
68-
"karma": "^3.0.0",
69-
"karma-chrome-launcher": "^2.2.0",
70-
"karma-coverage-istanbul-reporter": "^2.0.4",
71-
"karma-firefox-launcher": "^1.1.0",
72-
"karma-jasmine": "^1.1.2",
73-
"karma-junit-reporter": "^1.2.0",
74-
"karma-sourcemap-loader": "^0.3.7",
75-
"karma-webpack": "^3.0.5",
76-
"local-web-server": "^2.6.0",
77-
"postcss-cssnext": "^3.1.0",
78-
"postcss-loader": "^3.0.0",
79-
"puppeteer": "^0.11.0",
80-
"rimraf": "^2.6.2",
81-
"webpack": "^4.22.0",
82-
"webpack-bundle-analyzer": "^3.0.2",
83-
"webpack-cli": "^3.1.0",
84-
"webpack-dev-server": "^3.1.9",
85-
"webpack-manifest-plugin": "^2.0.4",
86-
"webpack-merge": "^4.1.4"
26+
"chai": "^4.2.0",
27+
"chai-as-promised": "^7.1.1",
28+
"chalk": "^2.4.2",
29+
"commander": "^2.19.0",
30+
"eslint": "^5.13.0",
31+
"fs-extra": "^7.0.1",
32+
"mocha": "^5.2.0"
8733
}
8834
}

tasks/cea-install.js

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,61 @@
11
#!/usr/bin/env node
22
/* eslint no-console: 0 */
33

4-
// THIS SCRIPT SHOULD ONLY USE NATIVE NODE.JS APIs, NO PACKAGES FROM NPM ALLOWED
54
const copyFolder = require('./copy-folder');
65
const fs = require('fs');
76
const os = require('os');
87
const path = require('path');
98
const { spawn } = require('child_process');
9+
const chalk = require('chalk');
10+
const commander = require('commander');
11+
const templatePkg = require(path.join(__dirname, '..', '/template/package.json'));
1012

1113
let TARGET_DIR;
1214

13-
console.log('-------------------------------------------------------');
14-
console.log('Welcome to Create Evergreen App ♻️');
15-
console.log('-------------------------------------------------------');
15+
console.log(`${chalk.rgb(175, 207, 71)('-------------------------------------------------------')}`);
16+
console.log(`${chalk.rgb(175, 207, 71)('Welcome to Create Evergreen App ♻️')}`);
17+
console.log(`${chalk.rgb(175, 207, 71)('-------------------------------------------------------')}`);
18+
19+
const program = new commander.Command(templatePkg.name)
20+
.version(templatePkg.version)
21+
.arguments('<application-directory>')
22+
.usage(`${chalk.green('<application-directory>')} [options]`)
23+
.action(name => {
24+
TARGET_DIR = name;
25+
})
26+
.option('--yarn', 'Use yarn package manager instead of npm default')
27+
.parse(process.argv);
28+
29+
if (program.yarn) {
30+
console.log('Yarn Enabled');
31+
}
1632

1733
// Check target application directory/name is included in args
1834
// warn if directory is present, else create new target directory
19-
const checkTargetDir = async appDir => {
20-
if (!appDir) {
35+
const checkTargetDir = async () => {
36+
if (typeof TARGET_DIR === 'undefined') {
2137
console.error(
22-
'Missing Project Directory! Please specifiy the application name e.g. create-evergreen-app my-app'
38+
`Missing Project Directory! Please specifiy the application name e.g. ${chalk.green('create-evergreen-app my-app')}`
2339
);
40+
console.log();
41+
console.log(`Run ${chalk.green('create-evergreen-app --help')} for available options`);
2442
process.exit(1); // eslint-disable-line no-process-exit
2543
}
2644

27-
const targetExists = await fs.existsSync(appDir);
45+
const targetExists = await fs.existsSync(TARGET_DIR);
2846

2947
if (targetExists) {
3048
console.error(
31-
`${appDir} already exists, existing project detected? Delete ${appDir} to try again or run from a different directory.`
49+
`${TARGET_DIR} already exists, existing project detected? Delete ${TARGET_DIR} to try again or run from a different directory.`
3250
);
3351
process.exit(1); // eslint-disable-line no-process-exit
3452
}
3553

36-
await fs.mkdirSync(appDir);
37-
38-
return appDir;
54+
return await fs.mkdirSync(TARGET_DIR);
3955
};
4056

4157
// Create new package.json
4258
const npmInit = async () => {
43-
const templatePkg = require(path.join(__dirname, '..', 'package.json'));
4459
const appPkg = {
4560
name: TARGET_DIR,
4661
version: '0.1.0',
@@ -59,19 +74,19 @@ const npmInit = async () => {
5974

6075
// Copy root and src files to target directory
6176
const srcInit = async () => {
62-
const copyBlacklist = ['tasks/'];
63-
const packageFiles = require(path.join(__dirname, '..', 'package.json')).files;
64-
const files = packageFiles.filter((file) => {
65-
if (copyBlacklist.indexOf(file) < 0) {
66-
return file;
67-
}
68-
});
77+
// const copyBlacklist = [''];
78+
const packageFiles = require(path.join(__dirname, '..', '/template/package.json')).files;
79+
// const files = packageFiles.filter((file) => {
80+
// if (copyBlacklist.indexOf(file) < 0) {
81+
// return file;
82+
// }
83+
// });
6984

7085
await createGitIgnore();
7186

7287
return await Promise.all(
73-
files.map(async file => {
74-
const resolvedPath = path.join(__dirname, '..', file);
88+
packageFiles.map(async file => {
89+
const resolvedPath = path.join(__dirname, '..', '/template/', file);
7590

7691
if (fs.lstatSync(resolvedPath).isDirectory()) {
7792
return await copyFolder(resolvedPath, TARGET_DIR);
@@ -111,7 +126,8 @@ const createGitIgnore = () => {
111126
// Install npm dependencies
112127
const install = () => {
113128
return new Promise((resolve, reject) => {
114-
const command = os.platform() === 'win32' ? 'npm.cmd' : 'npm';
129+
const pkgMng = program.yarn ? 'yarn' : 'npm'; // default to npm
130+
const command = os.platform() === 'win32' ? `${pkgMng}.cmd` : pkgMng;
115131
const args = ['install', '--save', '--save-exact', '--loglevel', 'error'];
116132
const process = spawn(command, args, { stdio: 'inherit' });
117133

@@ -130,7 +146,7 @@ const install = () => {
130146
const run = async () => {
131147
try {
132148
console.log('Preparing project directory...');
133-
TARGET_DIR = await checkTargetDir(process.argv[2]);
149+
await checkTargetDir();
134150

135151
console.log('Initializing npm dependencies...');
136152
npmInit();
File renamed without changes.

template/.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = false

0 commit comments

Comments
 (0)