-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The project manager and init script are responsible for creating a boilerplate project for the user. It should pull the exmaple project from GitHub and merge any exisitng project setup with that of the boilerplate.
- Loading branch information
1 parent
12627e4
commit 8bdf0e9
Showing
2 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ProjectManager } from './../project/projectManager'; | ||
import { ConfigManager } from './../configManager'; | ||
import * as colors from 'colors'; | ||
|
||
/** | ||
* Executes a contract build procedure | ||
* @note Keep alive setup is incomplete | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
*/ | ||
const run = async () => { | ||
|
||
await ProjectManager.initWithDefaults(); | ||
|
||
await ConfigManager.createConfigWhenMissing(); | ||
|
||
console.log(colors.white(` | ||
. . | ||
/ ___ , _ , _ \` , __ ___. _/_ __. , __ | ||
| / \` |' \`|' \`. | |' \`. .' \` | .' \ |' \`. | ||
| | | | | | | | | | | | | | | | | ||
/---/ \`.__/| / ' / / / | \`---| \\__/ \`._.' / | | ||
\___/ | ||
`)) | ||
}; | ||
|
||
run().catch(error => { | ||
throw error; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import axios from 'axios'; | ||
import * as path from 'path'; | ||
import * as mkdirpCallback from 'mkdirp'; | ||
import { | ||
readFile as readFileCallback, | ||
writeFile as writeFileCallback, | ||
exists as existsCallback, | ||
readdir as readdirCallback, | ||
} from 'fs'; | ||
import { promisify } from 'util'; | ||
import { ConfigManager, LamingtonConfig } from "./../configManager"; | ||
import * as spinner from './../cli/logIndicator'; | ||
import { sleep } from '../utils'; | ||
|
||
const exists = promisify(existsCallback); | ||
const mkdirp = promisify(mkdirpCallback); | ||
const writeFile = promisify(writeFileCallback); | ||
const readFile = promisify(readFileCallback); | ||
const readdir = promisify(readdirCallback); | ||
|
||
/** Default encoding */ | ||
const ENCODING = 'utf8'; | ||
|
||
/** | ||
* Fetches and stores the latest EOS configuration images | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
*/ | ||
export class ProjectManager { | ||
|
||
/** @hidden Reference to the local `package.json` file */ | ||
private static pkg:{ | ||
scripts?: { [key:string]:string }, | ||
devDependencies?: { [key:string]:string } | ||
}; | ||
|
||
/** | ||
* Downloads the example project and integrates aspects where required. | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
*/ | ||
public static async initWithDefaults() { | ||
|
||
ProjectManager.pkg = JSON.parse(await readFile(path.join(process.cwd(), 'package.json'), ENCODING)); | ||
|
||
await ProjectManager.configureScripts(); | ||
|
||
await ProjectManager.configureDependencies(); | ||
// Load Configuration | ||
await ConfigManager.initWithDefaults(); | ||
|
||
await ProjectManager.createProjectStructure(); | ||
|
||
await ProjectManager.pullExampleProject(); | ||
|
||
await writeFile(path.join(process.cwd(),'package.json'), JSON.stringify(ProjectManager.pkg, null, 4), ENCODING); | ||
} | ||
|
||
/** | ||
* Configures the projects `package.json` scripts for a standard Lamington environment | ||
* @note Should merge the scripts provided in the example project with existing | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
* @hidden | ||
*/ | ||
private static async configureScripts() { | ||
spinner.create('Adding scripts'); | ||
const { scripts } = ProjectManager.pkg; | ||
const defaultScripts = { | ||
'build':'lamington build', | ||
'test':'lamington test' | ||
} | ||
ProjectManager.pkg.scripts = { ...defaultScripts, ...scripts }; | ||
spinner.end('Added scripts'); | ||
} | ||
|
||
private static async configureDependencies() { | ||
spinner.create('Adding dependencies'); | ||
const { devDependencies } = ProjectManager.pkg; | ||
const defaultDependencies = { | ||
'lamington':'latest' | ||
} | ||
ProjectManager.pkg.devDependencies = { ...defaultDependencies, ...devDependencies }; | ||
spinner.end('Added recommended dependencies'); | ||
} | ||
|
||
/** | ||
* Downloads the latest example Lamington project from GitHub | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
* @hidden | ||
*/ | ||
private static async pullExampleProject() { | ||
const files = await readdir(path.join(process.cwd(), 'contracts')); | ||
spinner.create('Pulling example project'); | ||
|
||
await sleep(1000); | ||
if (files.length <= 0) { | ||
spinner.end('Included example project'); | ||
} else { | ||
spinner.end('Project contained contracts'); | ||
} | ||
} | ||
|
||
/** | ||
* Creates the standard directories and files for a Lamington project | ||
* @author Mitch Pierias <github.com/MitchPierias> | ||
* @hidden | ||
*/ | ||
private static async createProjectStructure() { | ||
|
||
spinner.create('Creating directory structure'); | ||
|
||
await ProjectManager.createDirectoryIfMissing('contracts'); | ||
|
||
await ProjectManager.createDirectoryIfMissing('.lamington'); | ||
|
||
spinner.end('Created directory structure'); | ||
} | ||
|
||
private static async createDirectoryIfMissing(dirName:string) { | ||
if (!await exists(path.join(process.cwd(), dirName))) { | ||
await mkdirp(path.join(process.cwd(), dirName)); | ||
} | ||
} | ||
} |