Skip to content

Commit f1891fe

Browse files
lukeeddevelopit
authored andcommitted
Remote Templates (#329)
* install `gittar` * remove flags: css,sass,less,dest,type * purge *css flag-related stuffs * extract yarn-vs-npm logic before printing * replace ansi-codes with `chalk.green` * extract `pkgFile` path * use `argv.name` within pkg & manifest (Closes #326) - declare `log-symbols` as a dependency - it is already a direct dependency of `ora` * extract an `error` helper - with nice symbol & formatting * uninstall `recursive-copy` * extract `isDir` helper - uses *sync versions, but oh well * replace `copy` with `gittar.extract` - with filter * move `target` + `exists` + `force` logic first; - will need to verify a destination before extracting/downloading - will prompt (TODO) if incomplete - will abort if unsafe * use `argv.dest` for final instructions * fix typo * export `setup` functions directly * remove debug-type stdout from `initGit` * move common helpers to `util` file; - use more partial import statements * move `commandExists` —> `util.hasCommand`; - uses which.sync 🙊 - update function calls - remove `async` from `pkgScripts` * check if `yarn` bin exists on flag parsing; - instead of checking 5x per `setup` function - return `async` function directly from `initialize` * consolidate `setup.pkgScripts` function * do not write a `gitignore` file - template concern * minor cleanup, warn if no `git` binary found * oops, fix regex tester * don’t assume exit within `util.error` * use `warn` within watch command * use `util.isDir` within serve command * remove `init` command publicly * Merge `master` into `templates` * alias “official” preact-cli templates by name - only `default` & `full` for now * simplify `install` — install template deps * move `trimLeft` —> `util.trim` * remove `initialize` from setup; - assumed template ships own `package.json` already * simplify package-related `create` - change `pkg.name` & `mani.name` if set - set default `pkg.scripts` if none provided - will dynamically install `if-env` for `start` script * only extract `/template/` filepaths - strip:2 to remove “template” from dest name * add extra TODO note * define `done` handler before export * update `test/subjects` names - fixes test? /shrug * [MAJOR] tests refactor - supports new `create` command - refactor utility methods - change snapshot handling — comparison & taking - rename `WITH_INSTALL` —> `SKIP_INSTALL` - remove `setup` step; not needed * move `serve.snapshot` —>`images/serve` * add `deprecated` notice on `build.snapshot` file * remove unused `exists` helper * Fix tests/image/create.js test error * Revert "Fix tests/image/create.js test error" This reverts commit ca3b235. * [Travis] only build `master` branch - PRs are still built * remove `commands/init` file - somehow `recursive-copy` was picked up? * add console statement for debug - WTF HAPPENING * remove `dependency-install-loader` - no need anymore! - templates responsible own dependecies - and style-* flags removed * update scripts path - OCD strikes again * exit early if run `build` w/o installing deps; - tell user to run `npm install` first * always install deps for build subjects * remove `SKIP_INSTALL` global for Travis (temp) * assume any template without `/` is official lookup - print `info` message about the assumption * update tests, remove `full` alias
1 parent e1fc593 commit f1891fe

35 files changed

+467
-969
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ node_js:
1010
- 6
1111
- 8
1212

13+
branches:
14+
only:
15+
- master
16+
1317
cache:
1418
npm: true
1519
directories:
@@ -18,7 +22,8 @@ cache:
1822

1923
before_script:
2024
- export LIGHTHOUSE_CHROMIUM_PATH=`which google-chrome-stable`
21-
- if [ "$TRAVIS_BRANCH" = "master" ]; then export WITH_INSTALL=true; export WITH_LOG=true; fi
25+
# - if [ "$TRAVIS_BRANCH" = "master" ]; then export SKIP_INSTALL=true; export WITH_LOG=true; fi
26+
- if [ "$TRAVIS_BRANCH" = "master" ]; then export WITH_LOG=true; fi
2227

2328
script:
2429
- npm run lint

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ $ preact init
9595
$ preact create
9696

9797
--name Directory and package name for the new app.
98-
--dest Directory to create the app within. [default: <name>]
99-
--type A project template to start from.
100-
[Options: "full", "root", "simple", "empty"] [default: "full"]
101-
--less Pre-install LESS support. [boolean] [default: false]
102-
--sass Pre-install SASS/SCSS support. [boolean] [default: false]
103-
--stylus Pre-install STYLUS support. [boolean] [default: false]
10498
--git Initialize version control using git. [boolean] [default: false]
10599
--no-install Disables installing of dependencies. [boolean] [default: false]
106100
--yarn Installs dependencies with yarn. [boolean] [default: false]

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
"prepublish": "npm run -s build",
1414
"dev": "babel-node src",
1515
"lint": "eslint src tests",
16-
"pretest": "npm run -s build && rimraf ./tests/output",
16+
"pretest": "npm run -s build && rimraf tests/output",
1717
"test": "jest",
18-
"posttest": "rimraf ./tests/output",
18+
"posttest": "rimraf tests/output",
1919
"postinstall": "node -p 'require(\"./check.js\")()'",
2020
"test:build": "babel-node src build --cwd examples/root",
2121
"test:serve": "npm run -s test:build && babel-node src serve --port 3000 --cwd examples/root",
@@ -90,7 +90,6 @@
9090
"eslint-plugin-react": "^7.0.1",
9191
"html-looks-like": "^1.0.2",
9292
"jest": "^20.0.4",
93-
"lodash": "^4.17.4",
9493
"ncp": "^2.0.0",
9594
"uuid": "^3.0.1"
9695
},
@@ -121,6 +120,7 @@
121120
"file-loader": "^0.11.1",
122121
"fs.promised": "^3.0.0",
123122
"get-port": "^3.1.0",
123+
"gittar": "^0.1.0",
124124
"glob": "^7.1.2",
125125
"html-webpack-exclude-assets-plugin": "0.0.5",
126126
"html-webpack-plugin": "^2.28.0",
@@ -131,6 +131,7 @@
131131
"less": "^2.7.2",
132132
"less-loader": "^4.0.3",
133133
"loader-utils": "^1.1.0",
134+
"log-symbols": "^2.0.0",
134135
"minimatch": "^3.0.3",
135136
"mkdirp": "^0.5.1",
136137
"offline-plugin": "^4.6.2",
@@ -144,7 +145,6 @@
144145
"progress-bar-webpack-plugin": "^1.9.3",
145146
"promise-polyfill": "^6.0.2",
146147
"raw-loader": "^0.5.1",
147-
"recursive-copy": "^2.0.6",
148148
"require-relative": "^0.8.7",
149149
"rimraf": "^2.6.1",
150150
"script-ext-html-webpack-plugin": "^1.8.0",

src/commands/build.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { resolve } from 'path';
21
import rimraf from 'rimraf';
2+
import { resolve } from 'path';
3+
import { isDir, error } from '../util';
34
import asyncCommand from '../lib/async-command';
45
import runWebpack, { showStats, writeJsonStats } from '../lib/webpack/run-webpack';
56

@@ -48,8 +49,15 @@ export default asyncCommand({
4849
},
4950

5051
async handler(argv) {
52+
let cwd = argv.cwd ? resolve(argv.cwd) : process.cwd();
53+
let modules = resolve(cwd, 'node_modules');
54+
55+
if (!isDir(modules)) {
56+
return error('No `node_modules` found! Please run `npm install` before continuing.', 1);
57+
}
58+
5159
if (argv.clean) {
52-
let dest = resolve(argv.cwd || process.cwd(), argv.dest || 'build');
60+
let dest = resolve(cwd, argv.dest || 'build');
5361
await Promise.promisify(rimraf)(dest);
5462
}
5563

0 commit comments

Comments
 (0)