This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- tosin clone repo and replace values - create integration test for replacement value method
- Loading branch information
Showing
10 changed files
with
344 additions
and
17 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
__tests__/fixtures/filesReplacement/test.md | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
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,15 @@ | ||
# This file contains every values to be replace by the cli | ||
|
||
- Project Name = {% project name %} | ||
- Human Project Name = {% human project name %} | ||
- Developer Name = {% developer name %} | ||
- Email = {% email %} | ||
- Repository = {% repository %} | ||
- Lowercase Repository = {% lowercase repository %} | ||
|
||
- Project Name = {% project name %} | ||
- Human Project Name = {% human project name %} | ||
- Developer Name = {% developer name %} | ||
- Email = {% email %} | ||
- Repository = {% repository %} | ||
- Lowercase Repository = {% lowercase repository %} |
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,15 @@ | ||
# This file contains every values to be replace by the cli | ||
|
||
- Project Name = tosin-cli | ||
- Human Project Name = Awesome Tosin | ||
- Developer Name = Floriel Fedry | ||
- Email = truc@gmail.com | ||
- Repository = FullHuman/tosin | ||
- Lowercase Repository = fullhuman/tosin | ||
|
||
- Project Name = tosin-cli | ||
- Human Project Name = Awesome Tosin | ||
- Developer Name = Floriel Fedry | ||
- Email = truc@gmail.com | ||
- Repository = FullHuman/tosin | ||
- Lowercase Repository = fullhuman/tosin |
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 |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import { sum } from './../src/index' | ||
import fs from 'fs' | ||
import { promisify } from 'util' | ||
import { replaceInFile } from './../src/index' | ||
|
||
const readFile = promisify(fs.readFile) | ||
const writeFile = promisify(fs.writeFile) | ||
|
||
describe('test the library', () => { | ||
it('returns the expected result', () => { | ||
const actual = sum(1, 2) | ||
const expected = 3 | ||
expect(actual).toBe(expected) | ||
|
||
const replaceSets = [ | ||
['{% project name %}', 'tosin-cli'], | ||
['{% human project name %}', 'Awesome Tosin'], | ||
['{% developer name %}', 'Floriel Fedry'], | ||
['{% email %}', 'truc@gmail.com'], | ||
['{% repository %}', 'FullHuman/tosin'], | ||
['{% lowercase repository %}', 'fullhuman/tosin'] | ||
] | ||
|
||
it('replace the text with the values', async () => { | ||
const testFilePath = '__tests__/fixtures/filesReplacement/test.md' | ||
|
||
const fileReadme = await readFile('__tests__/fixtures/filesReplacement/README.md', 'utf-8') | ||
await writeFile(testFilePath, fileReadme, 'utf-8') | ||
|
||
const fileReadmeExpected = await readFile('__tests__/fixtures/filesReplacement/README_EXPECTED.md', 'utf-8') | ||
await replaceInFile(testFilePath, replaceSets) | ||
const actualFile = await readFile(testFilePath, 'utf-8') | ||
|
||
expect(actualFile).toBe(fileReadmeExpected) | ||
}) | ||
}) |
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,17 @@ | ||
#!/usr/bin/env node | ||
|
||
const { init } = require("../lib/tosin.cjs"); | ||
|
||
const program = require('commander'); | ||
|
||
program | ||
.version('1.0.0') | ||
.command('init') | ||
.action(() => { | ||
init() | ||
.then(() => process.exit(0)) | ||
.catch(() => process.exit(1)) | ||
}) | ||
|
||
program.parse(process.argv); | ||
|
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,90 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
|
||
var fs = _interopDefault(require('fs')); | ||
var util = require('util'); | ||
var enquirer = _interopDefault(require('enquirer')); | ||
var degit = _interopDefault(require('degit')); | ||
|
||
const readFile = util.promisify(fs.readFile); | ||
const writeFile = util.promisify(fs.writeFile); | ||
|
||
const init = async () => { | ||
const response = await enquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'humanProjectName', | ||
message: 'What is the name of your project? (e.g. Svelte)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'projectName', | ||
mesasge: 'What is the npm project name? (e.g. svelte-js)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'repository', | ||
message: 'What is your repository (<username>/<repo>)? (e.g. FullHuman/tosin)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'developerName', | ||
message: 'What is your name (used for the licence)?' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'email', | ||
message: 'What is the email to be use for the code of conduct?' | ||
} | ||
]); | ||
// clone the template library | ||
const emmitter = degit('FullHuman/tosin-template-library', { | ||
cache: true, | ||
force: true, | ||
verbose: true | ||
}); | ||
|
||
emitter.on('info', info => { | ||
console.log(info.message); | ||
}); | ||
|
||
await emmitter.clone('.'); | ||
|
||
const replaceSets = [ | ||
['{% project name %}', response.projectName], | ||
['{% human project name %}', response.humanProjectName], | ||
['{% developer name %}', response.developerName], | ||
['{% email %}', response.email], | ||
['{% repository %}', response.repository], | ||
['{% lowercase repository %}', response.repository.toLowerCase()] | ||
] | ||
|
||
;[ | ||
'.github/ISSUE_TEMPLATE/BUG_REPORT.md', | ||
'.github/CODE_OF_CONDUCT.md', | ||
'.github/PULL_REQUEST_TEMPLATE.md', | ||
'scripts/deploy_docs.sh', | ||
'CONTRIBUTING.md', | ||
'LICENSE', | ||
'package.json', | ||
'README.md', | ||
'rollup.config.js' | ||
].forEach(file => { | ||
replaceInFile(file, replaceSets); | ||
}); | ||
}; | ||
|
||
const replaceInFile = async (filePath, replaceSets) => { | ||
const fileContent = await readFile(filePath, 'utf-8'); | ||
let result = fileContent; | ||
replaceSets.forEach(([toReplace, value]) => { | ||
result = result.replace(new RegExp(toReplace, 'g'), value); | ||
}); | ||
await writeFile(filePath, result, 'utf8'); | ||
}; | ||
|
||
exports.init = init; | ||
exports.replaceInFile = replaceInFile; |
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,83 @@ | ||
import fs from 'fs'; | ||
import { promisify } from 'util'; | ||
import enquirer from 'enquirer'; | ||
import degit from 'degit'; | ||
|
||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
const init = async () => { | ||
const response = await enquirer.prompt([ | ||
{ | ||
type: 'input', | ||
name: 'humanProjectName', | ||
message: 'What is the name of your project? (e.g. Svelte)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'projectName', | ||
mesasge: 'What is the npm project name? (e.g. svelte-js)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'repository', | ||
message: 'What is your repository (<username>/<repo>)? (e.g. FullHuman/tosin)' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'developerName', | ||
message: 'What is your name (used for the licence)?' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'email', | ||
message: 'What is the email to be use for the code of conduct?' | ||
} | ||
]); | ||
// clone the template library | ||
const emmitter = degit('FullHuman/tosin-template-library', { | ||
cache: true, | ||
force: true, | ||
verbose: true | ||
}); | ||
|
||
emitter.on('info', info => { | ||
console.log(info.message); | ||
}); | ||
|
||
await emmitter.clone('.'); | ||
|
||
const replaceSets = [ | ||
['{% project name %}', response.projectName], | ||
['{% human project name %}', response.humanProjectName], | ||
['{% developer name %}', response.developerName], | ||
['{% email %}', response.email], | ||
['{% repository %}', response.repository], | ||
['{% lowercase repository %}', response.repository.toLowerCase()] | ||
] | ||
|
||
;[ | ||
'.github/ISSUE_TEMPLATE/BUG_REPORT.md', | ||
'.github/CODE_OF_CONDUCT.md', | ||
'.github/PULL_REQUEST_TEMPLATE.md', | ||
'scripts/deploy_docs.sh', | ||
'CONTRIBUTING.md', | ||
'LICENSE', | ||
'package.json', | ||
'README.md', | ||
'rollup.config.js' | ||
].forEach(file => { | ||
replaceInFile(file, replaceSets); | ||
}); | ||
}; | ||
|
||
const replaceInFile = async (filePath, replaceSets) => { | ||
const fileContent = await readFile(filePath, 'utf-8'); | ||
let result = fileContent; | ||
replaceSets.forEach(([toReplace, value]) => { | ||
result = result.replace(new RegExp(toReplace, 'g'), value); | ||
}); | ||
await writeFile(filePath, result, 'utf8'); | ||
}; | ||
|
||
export { init, replaceInFile }; |
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
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
Oops, something went wrong.