Skip to content

Commit 6aa2ae1

Browse files
CobyPearambraueraddy-pathaniailliakovalenko
authored
Initializer for react-native sample (#879)
* WIP: nextjs generator * WIP: diy generator * WIP: nextjs generator - build templates * Start of dedicated package 'create-sitecore-jss' * remove package-lock * Stubbed out build-templates.ts, added .gitignore * added build templates * WIP: nextjs initializer- ejs file render * Handling template command line parameter / prompt * Allow token replacement on file names * remove remaining disconnected files * Added check for empty directory * Remove remaining styleguide code * test name change for lerna versioning * updated yarn.lock * lerna test * Revert "lerna test" This reverts commit 451c35d. * get rid of mkdirp helper in favor of fs-extra * Add support for 'add' positinal param * Initial watch script * Fix templates, add prefix flag * added logs, detect initializer, feed args from json * refined the config file and added switch case to initializers * Adding diffing to 'add' * Styleguide sub-initializer WIP: prompts for diffs working * Update yes flag to override with passed in args * WIP: Add dependencies/scripts to package.json during post-init * Basic "next steps" introduced, some linting errors fixed * WIP: Removing code duplication between files, start refactor package.json logic * WIP: package.json, lint * Add diff prompt to package.json, use diffJson method for .json files * Add jss cli to base nextjs template and remove message about yarn * Add diff to package.json, add some missing template files * Move styleguide Navigation component to proper place in src, fix tsconfig * Remove unused stuff in cli package * Diy generator yarn install (#861) * yarn install * added yarn.lock * added chalk, added initialized flag * Add yarn.lock Co-authored-by: Addy Pathania <[email protected]> * Update error handling for transformFiles * Start adding unit tests for shared functions * Add test(s) * Add error message when adding post-init to non-JSS app * Reorganize and refactor some base functionality * WIP: Unit tests for helpers * Add coverage script, add support for deep merge of package.json files * Cover helpers by UT * Cover diffFiles by UT * Minor fixes - Fix default appName for styleguide init - Remove stray console.log from a template - Move sinon to devDependencies * Fix isJssApp UT * merge with dev and refactor * Update diffFiles test, fix sinon wrap error * Add litFix command, add missing ejs logic to connected demo tsx * group tests * Cover transform by UT * Cover cmd by UT * Restructure folders, delay install - Folder structure is now leaner - Watch and main() now use the same function to loop through multiple inits -> initRunner() * Fixes before demo * NextjsAnswer cleanup (remove redundant props, move/rename file to follow base Answer naming) * apply sitemap-fetcher plugin for disconnected * apply next.config plugin changes * Remove unnecessary devDependencies (main packages include own type definitions) * Rename transformPostInit to writeFiles, fix some tests * remove monorepo dev dependencies if dev environment * Fix scaffold script * added tests for writePackageJson helper * Revert "Fix scaffold script" This reverts commit dc1d1d4. * scaffold-component updates for disconnected/styleguide * removed extra sitemapFetcher import * fix removeDevDependencies check, consolidation in [[...path]].tsx * added _app.tsx (with bootstrap, nprogress) for nextjs-styleguide * "yes" handling for subsequent initializers (don't prompt for diffs when init on an empty directory) * only pass along __true__ "yes" answers * Initializers internationalization (#868) * Update template * Merge changes * fix answer type * Fix configs * add changes * make appPrefix false as default * update * fix indent * add HostName to NextJSAnswer * Fix issues after review * [NextJS] Refactor scaffold script to make it pluggable (#870) * Make bootstrap silent and refactor * Remove scaffold-component script * update PR * revert changes * revert * Refactor * Refactor scaffold script * Fix indent * [Initializers] Refactor prompts and answers (#872) * Refactoring * remove line * Update default app name Co-authored-by: Coby Sher <[email protected]> Co-authored-by: Coby Sher <[email protected]> * Update some ejs closing tags to trim unwanted newline * Refactor post-initializer flow (#874) * #511113 Refactored post-initializer flow * Fixes after merge. Added templates to BaseArgs (needed in order to suppress post-initializer prompt) * Added "Initializing ..." console message. Expanded silent suppression. * Add react-native templates * Add ejs templating for appName and config * More template prep * Fixed watch mode * * #511292 fixed issue where transform wasn't occurring on package.json file when existing file * fixed issue where package.json config values weren't being used in styleguide if args.yes == true * isJssApp now returns boolean * added tests, fixed broken ones * only run lint --fix if a lint script exists * Add react-native initializer * [Initializers] Split `force`, `yes` flags (#877) * refactor yes/force flags * Fix unit tests * Use argv.destination by default * Add dynamic logic to init factory and base templates prompt choices * Add silent option to run * Update initializer and fix a template * Apply changes from comments * Update interfaces for ReactNative * Remove typo * Remove settings.json extra * Fixes * Remove yes from react-native init response * Move ReactNativeArgs * Update import * Change asset regex name and to include .jar file * Update node and npm versions in package.json template Co-authored-by: Adam Brauer <[email protected]> Co-authored-by: Addy Pathania <[email protected]> Co-authored-by: illiakovalenko <[email protected]> Co-authored-by: Illia Kovalenko <[email protected]>
1 parent e933fd8 commit 6aa2ae1

File tree

133 files changed

+5113
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+5113
-2
lines changed

packages/create-sitecore-jss/src/common/steps/transform.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { diffLines, diffJson, Change } from 'diff';
1515
import { BaseArgs } from '../args/base';
1616

17-
const ASSET_REGEX = /\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf)$/;
17+
const COPY_ONLY_REGEX = /\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf|jar)$/;
1818

1919
export type JsonPropertyType = number | string | (number | string)[] | JsonObjectType;
2020
export interface JsonObjectType {
@@ -186,7 +186,7 @@ export const transform = async (
186186
// if the directory doesn't exist, create it
187187
fs.mkdirsSync(path.dirname(transformFilename(pathToNewFile, answers)));
188188

189-
if (file.match(ASSET_REGEX)) {
189+
if (file.match(COPY_ONLY_REGEX)) {
190190
// pdfs may have <% encoded, which throws an error for ejs.
191191
// we simply want to copy file if it's a pdf, not render it with ejs.
192192
fs.copySync(pathToTemplate, pathToNewFile);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { BaseArgs } from '../../common/args/base';
2+
import { ClientAppAnswer } from '../../common/prompts/base';
3+
4+
export interface ReactNativeArgs extends BaseArgs, Partial<Omit<ClientAppAnswer, 'fetchWith'>> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'path';
2+
import { prompt } from 'inquirer';
3+
import { prompts, ReactNativeAnswer } from './prompts';
4+
import { Initializer } from '../../common/Initializer';
5+
import { transform } from '../../common/steps';
6+
import { ReactNativeArgs } from './args';
7+
8+
export default class ReactNativeInitializer implements Initializer {
9+
get isBase() {
10+
return true;
11+
}
12+
13+
async init(args: ReactNativeArgs) {
14+
const defaults = args.yes
15+
? {
16+
appName: 'sitecore-jss-react-native',
17+
hostName: 'https://cm.jss.localhost',
18+
language: '',
19+
}
20+
: {};
21+
22+
const answers = await prompt<ReactNativeAnswer>(prompts, { ...defaults, ...args });
23+
24+
const mergedArgs = {
25+
...args,
26+
...answers,
27+
};
28+
29+
const templatePath = path.resolve(__dirname, '../../templates/react-native');
30+
await transform(templatePath, mergedArgs, {
31+
filter: (filePath: string) =>
32+
!!mergedArgs.language || !filePath.endsWith('{{language}}.json'),
33+
});
34+
35+
const response = {
36+
appName: answers.appName,
37+
};
38+
39+
return response;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { DistinctQuestion, QuestionCollection } from 'inquirer';
2+
import { styleguidePrompts, StyleguideAnswer } from '../../common/prompts/styleguide';
3+
import { clientAppPrompts, ClientAppAnswer } from '../../common/prompts/base';
4+
5+
export interface ReactNativeAnswer extends Omit<ClientAppAnswer, 'fetchWith'>, StyleguideAnswer {}
6+
7+
export const prompts: QuestionCollection<ReactNativeAnswer> = [
8+
...clientAppPrompts.filter((p: DistinctQuestion) => p.name !== 'fetchWith'),
9+
...styleguidePrompts,
10+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
[android]
3+
target = Google Inc.:Google APIs:23
4+
5+
[maven_repositories]
6+
central = https://repo1.maven.org/maven2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"root": true,
3+
"parser": "babel-eslint",
4+
"parserOptions": {
5+
"ecmaFeatures": {
6+
"jsx": true
7+
}
8+
},
9+
"extends": [
10+
"airbnb-base",
11+
"plugin:react/recommended",
12+
"prettier",
13+
"prettier/react",
14+
"plugin:import/errors",
15+
"plugin:import/warnings"
16+
],
17+
"plugins": ["react", "react-native", "import", "prettier"],
18+
"settings": {
19+
"import/ignore": ["node_modules", ".png$", ".jpg$"],
20+
"import/resolver": {
21+
"babel-module": {}
22+
},
23+
"react": {
24+
"version": "detect"
25+
}
26+
},
27+
"env": {
28+
"jest": true
29+
},
30+
"rules": {
31+
"jsx-quotes": ["error", "prefer-double"],
32+
"react/prop-types": "off",
33+
"prettier/prettier": "error",
34+
"import/prefer-default-export": "off",
35+
"import/no-extraneous-dependencies": [
36+
"error",
37+
{
38+
"devDependencies": true,
39+
"optionalDependencies": true
40+
}
41+
],
42+
"linebreak-style": ["error", "windows"],
43+
"arrow-body-style": ["warn", "as-needed"],
44+
"arrow-parens": ["error", "always"],
45+
"no-unused-vars": [
46+
"error",
47+
{
48+
"args": "none"
49+
}
50+
],
51+
"func-names": "off",
52+
"no-console": "off",
53+
"radix": ["error", "as-needed"],
54+
"prefer-destructuring": "off",
55+
"no-useless-escape": "off",
56+
"spaced-comment": "error",
57+
"curly": ["error", "multi-line"],
58+
"eol-last": ["error", "always"],
59+
"guard-for-in": "error",
60+
"no-unused-labels": "error",
61+
"no-caller": "error",
62+
"no-bitwise": "error",
63+
"no-multiple-empty-lines": "error",
64+
"no-new-wrappers": "error",
65+
"no-eval": "error",
66+
"dot-notation": "error",
67+
"no-trailing-spaces": "error",
68+
"no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true }],
69+
"brace-style": "error",
70+
"quotes": ["error", "single"],
71+
"default-case": "error",
72+
"eqeqeq": "error"
73+
}
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# Xcode
6+
#
7+
ios/**/build/
8+
*.pbxuser
9+
!default.pbxuser
10+
*.mode1v3
11+
!default.mode1v3
12+
*.mode2v3
13+
!default.mode2v3
14+
*.perspectivev3
15+
!default.perspectivev3
16+
xcuserdata
17+
*.xccheckout
18+
*.moved-aside
19+
DerivedData
20+
*.hmap
21+
*.ipa
22+
*.xcuserstate
23+
project.xcworkspace
24+
25+
# Android/IntelliJ
26+
#
27+
android/**/build/
28+
.idea
29+
.gradle
30+
local.properties
31+
*.iml
32+
33+
# node.js
34+
#
35+
node_modules/
36+
*.log
37+
38+
# BUCK
39+
buck-out/
40+
\.buckd/
41+
*.keystore
42+
!debug.keystore
43+
44+
# fastlane
45+
#
46+
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
47+
# screenshots whenever they are needed.
48+
# For more information about the recommended setup visit:
49+
# https://docs.fastlane.tools/best-practices/source-control/
50+
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots
54+
55+
# CocoaPods
56+
/ios/Pods/
57+
58+
# sitecore
59+
60+
*.deploysecret.config
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"endOfLine": "crlf",
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"tabWidth": 2,
6+
"arrowParens": "always",
7+
"printWidth": 100
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Android",
9+
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
10+
"type": "reactnative",
11+
"request": "launch",
12+
"platform": "android",
13+
"sourceMaps": true,
14+
"outDir": "${workspaceRoot}/.vscode/.react"
15+
},
16+
{
17+
"name": "Debug iOS",
18+
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
19+
"type": "reactnative",
20+
"request": "launch",
21+
"platform": "ios",
22+
"sourceMaps": true,
23+
"outDir": "${workspaceRoot}/.vscode/.react"
24+
},
25+
{
26+
"name": "Attach to packager",
27+
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
28+
"type": "reactnative",
29+
"request": "attach",
30+
"sourceMaps": true,
31+
"outDir": "${workspaceRoot}/.vscode/.react"
32+
},
33+
{
34+
"name": "Debug in Exponent",
35+
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
36+
"type": "reactnative",
37+
"request": "launch",
38+
"platform": "exponent",
39+
"sourceMaps": true,
40+
"outDir": "${workspaceRoot}/.vscode/.react"
41+
}
42+
]
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)