Skip to content

Commit

Permalink
feat: adapt for typescript template
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Oct 10, 2022
1 parent 7e0c28d commit 7a78264
Show file tree
Hide file tree
Showing 19 changed files with 3,513 additions and 3,486 deletions.
12 changes: 4 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"extends": [
"airbnb-base",
"prettier"
],
"extends": ["airbnb-base", "prettier"],
"env": {
"node": true,
"mocha": true
},
"parser": "babel-eslint",
"rules": {
"no-console": 0,
"import/extensions": ["error", { "js": "always" }],
"no-underscore-dangle": [
"error",
{
"allow": [
"_id"
]
"allow": ["_id"]
}
],
"import/no-named-as-default": 0
Expand Down
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn install
1 change: 1 addition & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git status
1 change: 1 addition & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn install
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint && yarn test
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint && yarn test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ Move to a directory where you would like to clone a test project, e.g. `cd ~/my-

Run the CLI by using the full path from that directory to the `lib` folder inside this repository.

```
```bash
node ~/code/graasp/tools/graasp-cli/lib new
```
13 changes: 0 additions & 13 deletions babel.config.js

This file was deleted.

50 changes: 25 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
"version": "0.4.2",
"author": "Juan Carlos Farah",
"description": "A CLI to create apps and labs for the Graasp ecosystem.",
"main": "lib/index.js",
"exports": "./src/index.js",
"type": "module",
"files": [
"lib"
],
"scripts": {
"test": "echo \"warning: no test specified\" && exit 0",
"compile": "babel src --out-dir lib --ignore **/__tests__",
"compile": "babel src --out-dir lib ",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"hooks:install": "node node_modules/husky/husky.js install",
"prettier:check": "prettier --check 'src/**/*.js'",
"prettier:write": "prettier --write 'src/**/*.js'",
"lint": "eslint .",
"release": "standard-version",
"prepublishOnly": "run-s lint test",
"prepublishOnly": "yarn lint && yarn test",
"prepare": "npm run compile"
},
"repository": {
Expand All @@ -42,33 +43,32 @@
},
"homepage": "https://github.com/graasp/graasp-cli#readme",
"devDependencies": {
"@babel/cli": "7.8.4",
"@babel/core": "7.9.0",
"@babel/preset-env": "7.9.0",
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.3.4",
"@babel/cli": "7.19.3",
"@babel/core": "7.19.3",
"@babel/preset-env": "7.19.4",
"@commitlint/cli": "17.1.2",
"@commitlint/config-conventional": "17.1.0",
"babel-eslint": "10.1.0",
"eslint": "6.8.0",
"eslint-config-airbnb-base": "14.1.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.20.1",
"husky": "4.2.3",
"eslint": "8.25.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"husky": "8.0.1",
"npm-run-all": "4.1.5",
"prettier": "2.1.1",
"standard-version": "7.1.0"
"prettier": "2.7.1",
"standard-version": "9.5.0"
},
"dependencies": {
"@babel/polyfill": "7.8.7",
"archiver": "5.0.0",
"bson-objectid": "1.3.0",
"del": "4.1.1",
"execa": "1.0.0",
"archiver": "5.3.1",
"del": "7.0.0",
"execa": "6.1.0",
"fs-exists-cached": "1.0.0",
"fs-extra": "7.0.1",
"hosted-git-info": "2.7.1",
"inquirer": "6.2.2",
"lodash": "4.17.19",
"yargs": "12.0.5"
"fs-extra": "10.1.0",
"hosted-git-info": "5.1.0",
"inquirer": "9.1.3",
"lodash": "4.17.21",
"uuid": "9.0.0",
"yargs": "17.6.0"
},
"packageManager": "yarn@3.2.4"
}
10 changes: 3 additions & 7 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const DEFAULT_STARTER = 'graasp/graasp-app-starter-react';
// todo: change to the graasp repo
export const DEFAULT_STARTER = 'graasp/graasp-app-starter-ts#1/initRepo';
export const DEFAULT_FRAMEWORK = 'react';
export const DEFAULT_PATH = './';
export const BUILD_DIRECTORY = 'build';
Expand All @@ -8,12 +9,7 @@ export const BUILD_PACKAGE_NAME = 'package.zip';
// environments
export const TEST = 'test';
export const LOCAL = 'local';
export const DEV = 'dev';
export const PROD = 'prod';

// keys
export const AWS_ACCESS_KEY_ID_LENGTH = 20;
export const AWS_SECRET_ACCESS_KEY_LENGTH = 40;
export const DEV = 'development';

// file names
export const GRAASP_IGNORE_FILE = '.graaspignore';
6 changes: 3 additions & 3 deletions src/createCli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import yargs from 'yargs';
import prompt from './prompt';
import { DEFAULT_STARTER } from './config';
import createPackageFile from './createPackageFile';
import prompt from './prompt.js';
import { DEFAULT_STARTER } from './config.js';
import createPackageFile from './createPackageFile.js';

const promisify = (fn) => (...args) => {
Promise.resolve(fn(...args)).then(
Expand Down
2 changes: 1 addition & 1 deletion src/createPackageFile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import archiver from 'archiver';
import path from 'path';
import fs from 'fs';
import { DEFAULT_PATH, BUILD_DIRECTORY, BUILD_PACKAGE_NAME } from './config';
import { DEFAULT_PATH, BUILD_DIRECTORY, BUILD_PACKAGE_NAME } from './config.js';

const removeFileIfExists = (filepath) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node

import createCli from './createCli';
import createCli from './createCli.js';

createCli(process.argv);
50 changes: 33 additions & 17 deletions src/initStarter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { execSync } from 'child_process';
import fs from 'fs-extra';
import util from 'util';
import HostedGitInfo from 'hosted-git-info';
import del from 'del';
import { sync as existsSync } from 'fs-exists-cached';
import { DEFAULT_PATH, DEFAULT_STARTER, GRAASP_IGNORE_FILE } from './config';
import writeEnvFiles from './writeEnvFiles';
import { spawn } from './utils';
import { deleteSync } from 'del';
import fsExistsCached from 'fs-exists-cached';
import { DEFAULT_PATH, DEFAULT_STARTER, GRAASP_IGNORE_FILE } from './config.js';
import writeEnvFiles from './writeEnvFiles.js';
import { spawn } from './utils.js';

const { sync: existsSync } = fsExistsCached;
const readFile = util.promisify(fs.readFile);

/**
Expand All @@ -35,8 +36,13 @@ const install = async (rootPath) => {
process.chdir(rootPath);

try {
const cmd = shouldUseYarn() ? spawn('yarnpkg') : spawn('npm install');
await cmd;
if (shouldUseYarn()) {
console.log('switching to yarn v2...');
await spawn('yarn set version berry');
await spawn('yarn');
} else {
await spawn('npm install');
}
} finally {
process.chdir(prevDir);
}
Expand All @@ -57,15 +63,15 @@ const removeIgnoredFiles = async (rootPath) => {
const files = lines.filter((line) => line !== '');

// delete matching files, including hidden ones
del.sync(files, { dot: true });
deleteSync(files, { dot: true });
} catch (e) {
console.error(e);
} finally {
process.chdir(prevDir);
}
};

// creates an new git repository
// creates a new git repository
const initGit = async (rootPath) => {
const prevDir = process.cwd();

Expand All @@ -83,12 +89,12 @@ const initGit = async (rootPath) => {
const commit = async (rootPath) => {
const prevDir = process.cwd();

console.log('performing initial commit...');
await console.log('performing initial commit (running lint and tests)...');
process.chdir(rootPath);

try {
await spawn('git add -A', { stdio: 'ignore' });

await console.log('this may take some time');
// cannot spawn this because of the way we are splitting the command
execSync('git commit -m "chore: initial commit from graasp cli"', {
stdio: 'ignore',
Expand Down Expand Up @@ -146,6 +152,16 @@ const writeReadme = async (rootPath, name, type) => {
}
};

const checkDeploymentMethod = async (rootPath, useGithubActions) => {
if (!useGithubActions) {
try {
await fs.remove(path.join(rootPath, '.github'));
} catch (e) {
console.error(e);
}
}
};

const writeChangeLog = async (rootPath) => {
const string = '# Change Log';
try {
Expand All @@ -160,10 +176,9 @@ const initStarter = async (options = {}) => {
starter = DEFAULT_STARTER,
name,
type,
graaspDeveloperId,
githubActions,
graaspAppId,
awsAccessKeyId,
awsSecretAccessKey,
mockApi,
p = DEFAULT_PATH,
} = options;

Expand Down Expand Up @@ -206,12 +221,13 @@ const initStarter = async (options = {}) => {

// write environment files
await writeEnvFiles(projectDirectory, {
graaspDeveloperId,
graaspAppId,
awsAccessKeyId,
awsSecretAccessKey,
mockApi,
});

// deployment method (removes .github directory when not using GitHub Actions)
await checkDeploymentMethod(projectDirectory, githubActions);

// write readme
await writeReadme(projectDirectory, name, type);

Expand Down
Loading

0 comments on commit 7a78264

Please sign in to comment.