Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(amplify-app): initialize feature flag #5643

Merged
merged 3 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/amplify-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { engines } = require('../package.json');

const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
const amplify = /^win/.test(process.platform) ? 'amplify.cmd' : 'amplify';
const amplifyDev = /^win/.test(process.platform) ? 'amplify-dev.cmd' : 'amplify-dev';
const amplifyCliPackageName = '@aws-amplify/cli';

function run() {
Expand Down Expand Up @@ -105,7 +106,8 @@ async function createAmplifySkeletonProject() {
console.log(`${emoji.get('guitar')} Creating base Amplify project`);

return new Promise((resolve, reject) => {
const createSkeletonAmplifyProject = spawn(amplify, ['init', '--quickstart'], {
const cmd = path.basename(process.argv[1]) === 'amplify-app-dev' ? amplifyDev : amplify;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to amplifyCmd for clarity?

const createSkeletonAmplifyProject = spawn(cmd, ['init', '--quickstart'], {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
Expand Down
26 changes: 23 additions & 3 deletions packages/amplify-cli/src/init-steps/preInitSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import * as url from 'url';
import { execSync } from 'child_process';
import { pathManager, $TSContext, NonEmptyDirectoryError, exitOnNextTick } from 'amplify-cli-core';
import {
pathManager,
$TSContext,
NonEmptyDirectoryError,
exitOnNextTick,
CLIContextEnvironmentProvider,
FeatureFlags,
} from 'amplify-cli-core';
import { getPackageManager } from '../packageManagerHelpers';
import { normalizePackageManagerForOS } from '../packageManagerHelpers';
import { generateLocalEnvInfoFile } from './s9-onSuccess';
Expand All @@ -21,7 +28,7 @@ export async function preInitSetup(context: $TSContext) {
}

if (context.parameters.options.quickstart) {
await createAmplifySkeleton();
await createAmplifySkeleton(context);
context.usageData.emitSuccess();
exitOnNextTick(0);
}
Expand Down Expand Up @@ -110,11 +117,24 @@ async function setLocalEnvDefaults(context: $TSContext) {
/**
* Extract amplify project structure with backend-config and project-config
*/
async function createAmplifySkeleton() {
async function createAmplifySkeleton(context: $TSContext) {
insertAmplifyIgnore(pathManager.getGitIgnoreFilePath(process.cwd()));

const skeletonLocalDir = path.join(__dirname, '..', '..', 'templates', 'amplify-skeleton');
const skeletonProjectDir = path.join(pathManager.getAmplifyDirPath(process.cwd()));

await fs.copy(skeletonLocalDir, skeletonProjectDir);

// Initialize feature flags
const contextEnvironmentProvider = new CLIContextEnvironmentProvider({
getEnvInfo: () => {
return context.exeInfo.localEnvInfo;
},
});

if (!FeatureFlags.isInitialized()) {
await FeatureFlags.initialize(contextEnvironmentProvider, true);
}

await FeatureFlags.ensureDefaultFeatureFlags(true);
}
5 changes: 5 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/amplify-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
validateBackendConfig,
validateModelgen,
validateAmplifyPush,
validateFeatureFlags,
} from '../amplify-app-helpers/amplify-app-validation';

describe('amplify-app platform tests', () => {
Expand All @@ -37,6 +38,7 @@ describe('amplify-app platform tests', () => {
validateProjectConfig(projRoot, 'android');
validateApi(projRoot);
validateBackendConfig(projRoot);
validateFeatureFlags(projRoot);
});

it('should setup an iOS project', async () => {
Expand All @@ -45,6 +47,7 @@ describe('amplify-app platform tests', () => {
validateProjectConfig(projRoot, 'ios');
validateApi(projRoot);
validateBackendConfig(projRoot);
validateFeatureFlags(projRoot);
});

it('should set up a angular project', async () => {
Expand All @@ -53,6 +56,7 @@ describe('amplify-app platform tests', () => {
validateProjectConfig(projRoot, 'javascript', 'angular');
validateApi(projRoot);
validateBackendConfig(projRoot);
validateFeatureFlags(projRoot);
});

it('should set up a react project and run scripts', async () => {
Expand All @@ -61,6 +65,7 @@ describe('amplify-app platform tests', () => {
validateProjectConfig(projRoot, 'javascript', 'react');
validateApi(projRoot);
validateBackendConfig(projRoot);
validateFeatureFlags(projRoot);
await addIntegAccountInConfig(projRoot);
await amplifyModelgen(projRoot);
validateModelgen(projRoot);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs-extra';
import * as path from 'path';
import { pathManager } from 'amplify-cli-core';

function validateProject(projRoot: string, platform: string) {
expect(fs.existsSync(path.join(projRoot, 'amplify'))).toBeTruthy();
Expand Down Expand Up @@ -83,4 +84,17 @@ function validateAmplifyPush(projRoot: string) {
expect(fs.existsSync(path.join(projRoot, 'amplify', 'backend', 'amplify-meta.json'))).toBeTruthy();
}

export { validateProject, validateProjectConfig, validateApi, validateBackendConfig, validateModelgen, validateAmplifyPush };
function validateFeatureFlags(projRoot: string) {
const testCLIJSONPath = pathManager.getCLIJSONFilePath(projRoot);
expect(fs.existsSync(testCLIJSONPath)).toBeTruthy();
}

export {
validateProject,
validateProjectConfig,
validateApi,
validateBackendConfig,
validateModelgen,
validateAmplifyPush,
validateFeatureFlags,
};