diff --git a/src/init/constants.json b/src/init/constants.json index 8d26a1c9..296017ff 100644 --- a/src/init/constants.json +++ b/src/init/constants.json @@ -2,6 +2,7 @@ "artifactsDest": "./", "artifactsDir": "/artifacts", "updateArtifactsDir": "/update-artifacts", + "recommendedGitIgnore":"/recommended-gitignore.txt", "dependencies": [ "@aeternity/aepp-sdk@12" ], diff --git a/src/init/init.js b/src/init/init.js index 56f0831c..cc1def50 100644 --- a/src/init/init.js +++ b/src/init/init.js @@ -38,6 +38,7 @@ const createAEprojectProjectStructure = async (folder) => { await setupArtifacts(folder); await installDependencies(folder); + await generateGitIgnore(folder); print('===== aeproject successfully initialized ====='); print('test/exampleTest.js and contract/ExampleContract.aes have been added as example how to use aeproject'); @@ -95,6 +96,16 @@ const updateArtifacts = async (folder) => { await copyFolderRecursiveSync(fileSource, folder); }; +/** + * generates a .gitignore file based on the content of + * recommended-gitignore.txt + * @param {string} folder - folder to add .gitignore + */ +const generateGitIgnore = async (folder) => { + const gitIgnorePath = path.join(folder, '.gitignore'); + await fs.promises.copyFile(`${__dirname}${constants.recommendedGitIgnore}`, gitIgnorePath); +}; + module.exports = { run, }; diff --git a/src/init/recommended-gitignore.txt b/src/init/recommended-gitignore.txt new file mode 100644 index 00000000..b7dab5e9 --- /dev/null +++ b/src/init/recommended-gitignore.txt @@ -0,0 +1,2 @@ +node_modules +build \ No newline at end of file diff --git a/tests/happy-path.js b/tests/happy-path.js index ebc305f1..928b0dc4 100644 --- a/tests/happy-path.js +++ b/tests/happy-path.js @@ -5,6 +5,7 @@ const chai = require('chai'); const chaiFiles = require('chai-files'); const { isEnvRunning } = require('../src/env/env'); const { version } = require('../package.json'); +const constants = require('../src/init/constants.json'); chai.use(chaiFiles); const { assert } = chai; @@ -40,6 +41,10 @@ describe('Happy Path', () => { const res = await exec(folder ? `aeproject init ${folder}` : 'aeproject init', { cwd }); assert.equal(res.code, 0); + const generatedGitIgnore = file(path.join(cwd, '.gitignore')).content; + const expectedGitIgnore = file(path.join(__dirname, `../src/init/${constants.recommendedGitIgnore}`)).content; + assert.equal(generatedGitIgnore, expectedGitIgnore); + // link to use local aeproject utils await exec('npm link @aeternity/aeproject', { cwd: folder ? path.join(cwd, folder) : cwd });