Skip to content

Commit

Permalink
Merge pull request #2 from juliancwirko/feature/separate-templates-repos
Browse files Browse the repository at this point in the history
templates in separate repos
  • Loading branch information
juliancwirko authored Jul 7, 2021
2 parents 8c7f254 + 0301b99 commit 7b78606
Show file tree
Hide file tree
Showing 53 changed files with 810 additions and 2,267 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### [0.5.0](https://github.com/juliancwirko/create-harold-app/releases/tag/v0.5.0) (2021-07-06)

- templates are now located in separate repositories
- nothing should change from the usage perspective
- you can still use `npm init harold-app my-app` or `npm init harold-app my-app -t bare`

### [0.4.1](https://github.com/juliancwirko/create-harold-app/releases/tag/v0.4.1) (2021-06-06)

- fix postsList date element class name
Expand Down
41 changes: 29 additions & 12 deletions bin/create-harold-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
const spawn = require('cross-spawn');
const { program } = require('commander');
const sanitizeName = require('sanitize-filename');
const path = require('path');
const fse = require('fs-extra');
const download = require('download');
const fs = require('fs');

const TEMPLATES = ['bare', 'default'];
const TEMPLATE_BARE_NAME = 'bare';
const TEMPLATE_DEFAULT_NAME = 'default';
const TEMPLATES = [TEMPLATE_BARE_NAME, TEMPLATE_DEFAULT_NAME];
const BARE_PACKAGE_PATH =
'https://github.com/juliancwirko/harold-template-bare/archive/refs/heads/main.zip';
const DEFAULT_PACKAGE_PATH =
'https://github.com/juliancwirko/harold-template-default/archive/refs/heads/main.zip';

const packageJson = require('../package.json');

Expand All @@ -31,19 +36,22 @@ if (projectName && projectName.indexOf('-') !== 0) {
// Create project directory
spawn.sync('mkdir', [sanitizeName(projectName)], { stdio: 'inherit' });

let templateName = 'default';
let templateArchiveFilePath = DEFAULT_PACKAGE_PATH;

// Choose template if user passes an option
if (options.template && TEMPLATES.includes(options.template)) {
templateName = options.template;
templateArchiveFilePath =
options.template === TEMPLATE_BARE_NAME
? BARE_PACKAGE_PATH
: DEFAULT_PACKAGE_PATH;
}

// Copy required files to proper directories
fse
.copy(
path.join(__dirname, '../templates/' + templateName),
process.cwd() + '/' + projectName + '/src'
)
// Extract required files to proper directories
download(
templateArchiveFilePath,
process.cwd() + '/' + projectName + '/src',
{ extract: true, strip: 1 }
)
.then(() => {
// Write proper package.json file for the project
fs.readFile(
Expand Down Expand Up @@ -73,7 +81,16 @@ if (projectName && projectName.indexOf('-') !== 0) {
);
})
.catch((err) => {
if (err) console.log(err);
if (err)
console.log(
"Can't download the " +
options.template +
' template: (' +
err.statusCode +
': ' +
err.statusMessage +
')'
);
});
} else {
console.log('Please provide project name (directory)');
Expand Down
2 changes: 1 addition & 1 deletion bin/packagejson.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "harold-scripts start"
},
"devDependencies": {
"harold-scripts": "^0.4.1"
"harold-scripts": "^0.5.0"
}
}
Loading

0 comments on commit 7b78606

Please sign in to comment.